From 7656d4c679e59b7054b0ec312c29d8f0e2ae4ef4 Mon Sep 17 00:00:00 2001 From: hvanwelbergen <hvanwelbergen@techfak.uni-bielefeld.de> Date: Mon, 14 Jan 2013 22:18:58 +0100 Subject: [PATCH] fixed memory overflow, dependency update. --- ipaacalib/java/src/ipaaca/OutputBuffer.java | 5 +- ...ntMessageCommunicationIntegrationTest.java | 106 +++++++++++------- ipaacalib/python/ivy.xml | 4 +- ipaacalib/python/test/ivy.xml | 4 +- 4 files changed, 72 insertions(+), 47 deletions(-) diff --git a/ipaacalib/java/src/ipaaca/OutputBuffer.java b/ipaacalib/java/src/ipaaca/OutputBuffer.java index 02cbd55..de5e646 100644 --- a/ipaacalib/java/src/ipaaca/OutputBuffer.java +++ b/ipaacalib/java/src/ipaaca/OutputBuffer.java @@ -315,7 +315,10 @@ public class OutputBuffer extends Buffer { throw new IUPublishedException(iu); } - iuStore.put(iu.getUid(), iu); + if(!(iu instanceof LocalMessageIU)) + { + iuStore.put(iu.getUid(), iu); + } iu.setBuffer(this); publishIU(iu); } diff --git a/ipaacalib/java/test/src/ipaaca/ComponentMessageCommunicationIntegrationTest.java b/ipaacalib/java/test/src/ipaaca/ComponentMessageCommunicationIntegrationTest.java index 40d23e8..f678a12 100644 --- a/ipaacalib/java/test/src/ipaaca/ComponentMessageCommunicationIntegrationTest.java +++ b/ipaacalib/java/test/src/ipaaca/ComponentMessageCommunicationIntegrationTest.java @@ -20,7 +20,7 @@ import com.google.common.collect.ImmutableSet; /** * Test communication of the 'MESSAGE' type between IUs * @author hvanwelbergen - * + * */ public class ComponentMessageCommunicationIntegrationTest { @@ -29,118 +29,140 @@ public class ComponentMessageCommunicationIntegrationTest { Initializer.initializeIpaacaRsb(); } - + private OutputBuffer outBuffer; private InputBuffer inBuffer; private LocalMessageIU localIU; - private CountingEventHandler component1EventHandler; + private CountingEventHandler component1EventHandler; private CountingEventHandler component2EventHandler; private StoringEventHandler component1StoreHandler = new StoringEventHandler(); private StoringEventHandler component2StoreHandler = new StoringEventHandler(); private static final String CATEGORY = "category1"; - + @Before public void setup() { outBuffer = new OutputBuffer("component1"); - - Set<String> categories = new ImmutableSet.Builder<String>().add(CATEGORY).build(); + + Set<String> categories = new ImmutableSet.Builder<String>().add(CATEGORY).build(); inBuffer = new InputBuffer("component2", categories); - EnumSet<IUEventType> types = EnumSet.of(IUEventType.ADDED,IUEventType.COMMITTED,IUEventType.UPDATED); + EnumSet<IUEventType> types = EnumSet.of(IUEventType.ADDED, IUEventType.COMMITTED, IUEventType.UPDATED); component2EventHandler = new CountingEventHandler(); component1EventHandler = new CountingEventHandler(); - inBuffer.registerHandler(new IUEventHandler(component2EventHandler,types,categories)); - outBuffer.registerHandler(new IUEventHandler(component1EventHandler,types,categories)); - inBuffer.registerHandler(new IUEventHandler(component2StoreHandler,types,categories)); - outBuffer.registerHandler(new IUEventHandler(component1StoreHandler,types,categories)); - + inBuffer.registerHandler(new IUEventHandler(component2EventHandler, types, categories)); + outBuffer.registerHandler(new IUEventHandler(component1EventHandler, types, categories)); + inBuffer.registerHandler(new IUEventHandler(component2StoreHandler, types, categories)); + outBuffer.registerHandler(new IUEventHandler(component1StoreHandler, types, categories)); + localIU = new LocalMessageIU(); localIU.setCategory(CATEGORY); localIU.getPayload().put("key1", "item1"); - localIU.addLinks("INIT", ImmutableSet.of("init1","init2")); + localIU.addLinks("INIT", ImmutableSet.of("init1", "init2")); } - + @After public void tearDown() { inBuffer.close(); outBuffer.close(); } - + @Test public void testAddedIU() throws InterruptedException { outBuffer.add(localIU); - Thread.sleep(200); + Thread.sleep(200); AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); assertNull(iuIn); - assertThat(localIU.getLinks("INIT"),containsInAnyOrder("init1","init2")); - assertEquals(1,component2EventHandler.getNumberOfAddEvents(localIU.getUid())); - assertEquals(0,component1EventHandler.getNumberOfAddEvents(localIU.getUid())); - assertEquals(1,component2EventHandler.getNumberOfAddEvents(localIU.getUid())); - assertEquals(0,component1EventHandler.getNumberOfAddEvents(localIU.getUid())); + assertThat(localIU.getLinks("INIT"), containsInAnyOrder("init1", "init2")); + assertEquals(1, component2EventHandler.getNumberOfAddEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfAddEvents(localIU.getUid())); + assertEquals(1, component2EventHandler.getNumberOfAddEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfAddEvents(localIU.getUid())); assertEquals(localIU.getUid(), component2StoreHandler.getAddedIUs().get(0).getUid()); - } - + } + @Test public void testIUCommit() throws InterruptedException { outBuffer.add(localIU); localIU.commit(); Thread.sleep(200); - assertEquals(0,component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); - assertEquals(0,component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); assertFalse(component2StoreHandler.getAddedIUs().get(0).isCommitted()); } - + @Test public void testIUCommitBeforePublish() throws InterruptedException { localIU.commit(); - outBuffer.add(localIU); + outBuffer.add(localIU); Thread.sleep(200); - assertEquals(0,component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); - assertEquals(0,component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); assertTrue(component2StoreHandler.getAddedIUs().get(0).isCommitted()); } - + @Test public void testIUCommitFromInputBuffer() throws InterruptedException { outBuffer.add(localIU); Thread.sleep(200); AbstractIU iuIn = component2StoreHandler.getAddedIUs().get(0); - + iuIn.commit(); Thread.sleep(200); assertFalse(localIU.isCommitted()); - assertEquals(0,component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); - assertEquals(0,component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfCommitEvents(localIU.getUid())); + assertEquals(0, component2EventHandler.getNumberOfCommitEvents(localIU.getUid())); } - + @Test public void testIUUpdate() throws InterruptedException { outBuffer.add(localIU); - Thread.sleep(200); + Thread.sleep(200); AbstractIU iuIn = component2StoreHandler.getAddedIUs().get(0); assertNull(iuIn.getPayload().get("key2")); - + localIU.getPayload().put("key2", "value2"); Thread.sleep(200); assertEquals(null, iuIn.getPayload().get("key2")); - assertEquals(0,component2EventHandler.getNumberOfUpdateEvents(localIU.getUid())); - assertEquals(0,component1EventHandler.getNumberOfUpdateEvents(localIU.getUid())); + assertEquals(0, component2EventHandler.getNumberOfUpdateEvents(localIU.getUid())); + assertEquals(0, component1EventHandler.getNumberOfUpdateEvents(localIU.getUid())); } - + @Test public void testIUUpdateBeforePublish() throws InterruptedException { localIU.getPayload().put("key2", "value2"); outBuffer.add(localIU); - - Thread.sleep(200); + + Thread.sleep(200); AbstractIU iuIn = component2StoreHandler.getAddedIUs().get(0); - assertEquals("value2", iuIn.getPayload().get("key2")); + assertEquals("value2", iuIn.getPayload().get("key2")); + } + + private void fillBuffer(int val) + { + LocalMessageIU iu = new LocalMessageIU(); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < 1000000; i++) + { + buffer.append(val); + } + iu.setCategory(""); + iu.getPayload().put("x", buffer.toString()); + outBuffer.add(iu); + } + + @Test + public void testManyMessages() + { + for (int i = 0; i < 1000; i++) + { + fillBuffer(i); + } } } diff --git a/ipaacalib/python/ivy.xml b/ipaacalib/python/ivy.xml index e037daf..6746fd8 100644 --- a/ipaacalib/python/ivy.xml +++ b/ipaacalib/python/ivy.xml @@ -4,8 +4,8 @@ <artifact type="py.zip" ext="py.zip"/> </publications> <dependencies> - <dependency org="google" name="protobuf" rev="latest.release"/> - <dependency org="rsb" name="rsb" rev="latest.release"/> + <dependency org="google" name="protobuf-python" rev="latest.release"/> + <dependency org="rsb" name="rsb-python" rev="latest.release"/> </dependencies> </ivy-module> diff --git a/ipaacalib/python/test/ivy.xml b/ipaacalib/python/test/ivy.xml index bdf74d7..1e4d577 100644 --- a/ipaacalib/python/test/ivy.xml +++ b/ipaacalib/python/test/ivy.xml @@ -1,7 +1,7 @@ <ivy-module version="2.0"> <info organisation="ipaaca" module="IpaacaPythonTest"/> <dependencies> - <dependency org="hamcrest" name="hamcrest" rev="latest.release"/> - <dependency org="mockito" name="mockito" rev="latest.release" /> + <dependency org="hamcrest" name="hamcrest-python" rev="latest.release"/> + <dependency org="mockito" name="mockito-python" rev="latest.release" /> </dependencies> </ivy-module> -- GitLab