Skip to content
Snippets Groups Projects
Commit 10165c6f authored by Herwin van Welbergen's avatar Herwin van Welbergen
Browse files

added testcases, added converters to java versions

parent ac733056
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ java/dist ...@@ -6,6 +6,7 @@ java/dist
java/privateprops java/privateprops
java/.project java/.project
java/.classpath java/.classpath
*.pyc
.project .project
.classpath .classpath
**/.*.swp **/.*.swp
...@@ -27,14 +27,15 @@ public final class Initializer { ...@@ -27,14 +27,15 @@ public final class Initializer {
DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter()); DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter());
DefaultConverterRepository.getDefaultConverterRepository() DefaultConverterRepository.getDefaultConverterRepository()
.addConverter(new ProtocolBufferConverter<IUCommission>(IUCommission.getDefaultInstance())); .addConverter(new ProtocolBufferConverter<IUCommission>(IUCommission.getDefaultInstance()));
DefaultConverterRepository.getDefaultConverterRepository()
.addConverter(new ProtocolBufferConverter<IUPayloadUpdate>(IUPayloadUpdate.getDefaultInstance()));
DefaultConverterRepository.getDefaultConverterRepository()
.addConverter(new ProtocolBufferConverter<IULinkUpdate>(IULinkUpdate.getDefaultInstance()));
DefaultConverterRepository.getDefaultConverterRepository().addConverter( DefaultConverterRepository.getDefaultConverterRepository().addConverter(
new IUConverter(new ConverterSignature("ipaaca-iu", RemotePushIU.class))); new IUConverter(new ConverterSignature("ipaaca-iu", RemotePushIU.class)));
DefaultConverterRepository.getDefaultConverterRepository().addConverter( DefaultConverterRepository.getDefaultConverterRepository().addConverter(
new IUConverter(new ConverterSignature("ipaaca-localiu", LocalIU.class))); new IUConverter(new ConverterSignature("ipaaca-localiu", LocalIU.class)));
DefaultConverterRepository.getDefaultConverterRepository().addConverter(
new PayloadConverter());
DefaultConverterRepository.getDefaultConverterRepository().addConverter(
new LinkUpdateConverter());
} }
} }
package ipaaca;
import ipaaca.Ipaaca.IULinkUpdate;
import java.nio.ByteBuffer;
import rsb.converter.ConversionException;
import rsb.converter.Converter;
import rsb.converter.ConverterSignature;
import rsb.converter.UserData;
import rsb.converter.WireContents;
import com.google.protobuf.InvalidProtocolBufferException;
public class LinkUpdateConverter implements Converter<ByteBuffer>
{
private static final String LINKUPDATE_WIRESCHEMA = "ipaaca-iu-link-update";
@Override
public UserData<?> deserialize(String wireSchema, ByteBuffer buffer) throws ConversionException
{
IULinkUpdate pl;
try
{
pl = IULinkUpdate.newBuilder().mergeFrom(buffer.array()).build();
}
catch (InvalidProtocolBufferException e)
{
throw new RuntimeException(e);
}
return new UserData<IULinkUpdate>(pl, IULinkUpdate.class);
}
@Override
public ConverterSignature getSignature()
{
return new ConverterSignature(LINKUPDATE_WIRESCHEMA,IULinkUpdate.class);
}
@Override
public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException
{
IULinkUpdate pl = (IULinkUpdate)obj;
return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),LINKUPDATE_WIRESCHEMA);
}
}
...@@ -74,7 +74,10 @@ public class LocalIU extends AbstractIU ...@@ -74,7 +74,10 @@ public class LocalIU extends AbstractIU
{ {
increaseRevisionNumber(); increaseRevisionNumber();
committed = true; committed = true;
outputBuffer.sendIUCommission(this, writerName); if(outputBuffer!=null)
{
outputBuffer.sendIUCommission(this, writerName);
}
} }
} }
} }
......
package ipaaca;
import ipaaca.Ipaaca.IUPayloadUpdate;
import java.nio.ByteBuffer;
import rsb.converter.ConversionException;
import rsb.converter.Converter;
import rsb.converter.ConverterSignature;
import rsb.converter.UserData;
import rsb.converter.WireContents;
import com.google.protobuf.InvalidProtocolBufferException;
public class PayloadConverter implements Converter<ByteBuffer>
{
private static final String PAYLOAD_WIRESCHEMA = "ipaaca-iu-payload-update";
@Override
public UserData<?> deserialize(String wireSchema, ByteBuffer buffer) throws ConversionException
{
IUPayloadUpdate pl;
try
{
pl = IUPayloadUpdate.newBuilder().mergeFrom(buffer.array()).build();
}
catch (InvalidProtocolBufferException e)
{
throw new RuntimeException(e);
}
return new UserData<IUPayloadUpdate>(pl, IUPayloadUpdate.class);
}
@Override
public ConverterSignature getSignature()
{
return new ConverterSignature(PAYLOAD_WIRESCHEMA,IUPayloadUpdate.class);
}
@Override
public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException
{
IUPayloadUpdate pl = (IUPayloadUpdate)obj;
return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),PAYLOAD_WIRESCHEMA);
}
}
...@@ -109,8 +109,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -109,8 +109,7 @@ public class ComponentCommunicationIntegrationTest
localIU = new LocalIU(); localIU = new LocalIU();
localIU.setCategory(CATEGORY); localIU.setCategory(CATEGORY);
localIU.getPayload().put("key1", "item1"); localIU.getPayload().put("key1", "item1");
localIU.addLinks("INIT", ImmutableSet.of("init1","init2")); localIU.addLinks("INIT", ImmutableSet.of("init1","init2"));
outBuffer.add(localIU);
} }
@After @After
...@@ -123,6 +122,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -123,6 +122,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testAddedIU() throws InterruptedException public void testAddedIU() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
assertNotNull(iuIn); assertNotNull(iuIn);
...@@ -130,11 +130,12 @@ public class ComponentCommunicationIntegrationTest ...@@ -130,11 +130,12 @@ public class ComponentCommunicationIntegrationTest
assertThat(localIU.getLinks("INIT"),containsInAnyOrder("init1","init2")); assertThat(localIU.getLinks("INIT"),containsInAnyOrder("init1","init2"));
assertEquals(1,component2EventHandler.getNumberOfAddEvents(iuIn.getUid())); assertEquals(1,component2EventHandler.getNumberOfAddEvents(iuIn.getUid()));
assertEquals(0,component1EventHandler.getNumberOfAddEvents(localIU.getUid())); assertEquals(0,component1EventHandler.getNumberOfAddEvents(localIU.getUid()));
} }
@Test @Test
public void testIUCommit() throws InterruptedException public void testIUCommit() throws InterruptedException
{ {
outBuffer.add(localIU);
localIU.commit(); localIU.commit();
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
...@@ -143,9 +144,22 @@ public class ComponentCommunicationIntegrationTest ...@@ -143,9 +144,22 @@ public class ComponentCommunicationIntegrationTest
assertEquals(1,component2EventHandler.getNumberOfCommitEvents(iuIn.getUid())); assertEquals(1,component2EventHandler.getNumberOfCommitEvents(iuIn.getUid()));
} }
@Test
public void testIUCommitBeforePublish() throws InterruptedException
{
localIU.commit();
outBuffer.add(localIU);
Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
assertTrue(iuIn.isCommitted());
assertEquals(0,component1EventHandler.getNumberOfCommitEvents(localIU.getUid()));
assertEquals(0,component2EventHandler.getNumberOfCommitEvents(iuIn.getUid()));
}
@Test @Test
public void testIUCommitFromInputBuffer() throws InterruptedException public void testIUCommitFromInputBuffer() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
...@@ -160,6 +174,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -160,6 +174,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testIUUpdate() throws InterruptedException public void testIUUpdate() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
assertNull(iuIn.getPayload().get("key2")); assertNull(iuIn.getPayload().get("key2"));
...@@ -174,6 +189,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -174,6 +189,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testSetPayload() throws InterruptedException public void testSetPayload() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
...@@ -191,6 +207,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -191,6 +207,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testSetPayloadRemote() throws InterruptedException public void testSetPayloadRemote() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
...@@ -208,6 +225,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -208,6 +225,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testIUUpdateFromInputBuffer() throws InterruptedException public void testIUUpdateFromInputBuffer() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
...@@ -222,6 +240,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -222,6 +240,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testIUpdateRemove() throws InterruptedException public void testIUpdateRemove() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
assertEquals("item1",iuIn.getPayload().get("key1")); assertEquals("item1",iuIn.getPayload().get("key1"));
...@@ -236,6 +255,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -236,6 +255,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testIUpdateRemoveFromInputBuffer() throws InterruptedException public void testIUpdateRemoveFromInputBuffer() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
assertEquals("item1",iuIn.getPayload().get("key1")); assertEquals("item1",iuIn.getPayload().get("key1"));
...@@ -250,6 +270,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -250,6 +270,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testSetLinksLocal() throws InterruptedException public void testSetLinksLocal() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6")); localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));
...@@ -261,6 +282,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -261,6 +282,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testSetLinksRemote() throws InterruptedException public void testSetLinksRemote() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6")); iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));
...@@ -272,6 +294,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -272,6 +294,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testSetLinksRemoteOverwrite() throws InterruptedException public void testSetLinksRemoteOverwrite() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6")); localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));
...@@ -288,6 +311,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -288,6 +311,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testAddLinksLocal() throws InterruptedException public void testAddLinksLocal() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu4")); localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu4"));
...@@ -300,6 +324,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -300,6 +324,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testAddLinksRemote() throws InterruptedException public void testAddLinksRemote() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
iuIn.addLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6")); iuIn.addLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));
...@@ -311,6 +336,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -311,6 +336,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testRemoveLinksLocal() throws InterruptedException public void testRemoveLinksLocal() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7")); localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7"));
...@@ -323,6 +349,7 @@ public class ComponentCommunicationIntegrationTest ...@@ -323,6 +349,7 @@ public class ComponentCommunicationIntegrationTest
@Test @Test
public void testRemoveLinksRemote() throws InterruptedException public void testRemoveLinksRemote() throws InterruptedException
{ {
outBuffer.add(localIU);
Thread.sleep(200); Thread.sleep(200);
AbstractIU iuIn = inBuffer.getIU(localIU.getUid()); AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7")); iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7"));
...@@ -331,4 +358,6 @@ public class ComponentCommunicationIntegrationTest ...@@ -331,4 +358,6 @@ public class ComponentCommunicationIntegrationTest
assertThat(localIU.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7")); assertThat(localIU.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7"));
assertThat(iuIn.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7")); assertThat(iuIn.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7"));
} }
} }
package ipaaca; package ipaaca;
import static org.junit.Assert.assertEquals; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.*;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -14,24 +15,31 @@ import org.junit.Test; ...@@ -14,24 +15,31 @@ import org.junit.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
public class JavaPythonTest { public class JavaPythonTest
{
static {
static
{
Initializer.initializeIpaacaRsb(); Initializer.initializeIpaacaRsb();
} }
private InputBuffer inBuffer; private InputBuffer inBuffer;
@Before private static final String PYTHON_PREAMBLE = "import sys\n"
+ "sys.path.insert(0, '../python/build/')\n"
+ "sys.path.insert(0, '../python/lib/')\n"
+ "import ipaaca, time\n";
@Before
public void setup() public void setup()
{ {
Set<String> categories = new ImmutableSet.Builder<String>().add("JavaPythonTest").build(); Set<String> categories = new ImmutableSet.Builder<String>().add("JavaPythonTest").build();
inBuffer = new InputBuffer("javaside", categories); inBuffer = new InputBuffer("javaside", categories);
} }
private void printRuntimeErrors(Process p) throws IOException private void printRuntimeErrors(Process p) throws IOException
{ {
InputStream in = p.getInputStream(); InputStream in = p.getInputStream();
BufferedInputStream buf = new BufferedInputStream(in); BufferedInputStream buf = new BufferedInputStream(in);
InputStreamReader inread = new InputStreamReader(buf); InputStreamReader inread = new InputStreamReader(buf);
...@@ -64,29 +72,116 @@ public class JavaPythonTest { ...@@ -64,29 +72,116 @@ public class JavaPythonTest {
{ {
System.out.println(line); System.out.println(line);
} }
} }
@Test private boolean runPythonProgram(String pypr) throws IOException
public void test() throws IOException, InterruptedException { {
Process p = Runtime.getRuntime().exec(new String[] { "python", "-c", pypr });
String pypr = printRuntimeErrors(p);
"import sys\n" + return p.exitValue()==0;
"sys.path.insert(0, '../python/build/')\n" + }
"sys.path.insert(0, '../python/lib/')\n" +
"import ipaaca, time\n" + @Test
"ob = ipaaca.OutputBuffer('pythonside')\n" + public void testSetPayloadInPythonOutputBuffer() throws IOException, InterruptedException
"iu = ipaaca.IU('JavaPythonTest')\n" + {
"iu.payload = {'data':'Hello from Python!'}\n" +
"time.sleep(0.1)\n" + String pypr = PYTHON_PREAMBLE
"ob.add(iu)"; + "ob = ipaaca.OutputBuffer('pythonside')\n"
Process p = Runtime.getRuntime().exec(new String[]{"python","-c", pypr}); + "iu = ipaaca.IU('JavaPythonTest')\n"
printRuntimeErrors(p); + "iu.payload = {'data':'Hello from Python!'}\n"
+ "time.sleep(0.1)\n"
Thread.sleep(200); + "ob.add(iu)\n";
assertEquals(1, inBuffer.getIUs().size()); assertTrue(runPythonProgram(pypr));
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertEquals("Hello from Python!",iu.getPayload().get("data")); Thread.sleep(200);
} assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertEquals("Hello from Python!", iu.getPayload().get("data"));
}
@Test
public void testSetPayloadInPythonOutputBufferAfterPublishing() throws IOException, InterruptedException
{
String pypr = PYTHON_PREAMBLE
+ "ob = ipaaca.OutputBuffer('pythonside')\n"
+ "iu = ipaaca.IU('JavaPythonTest')\n"
+ "ob.add(iu)\n"
+ "time.sleep(0.1)\n"
+ "iu.payload = {'data':'Hello from Python!'}\n";
assertTrue(runPythonProgram(pypr));
Thread.sleep(200);
assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertEquals("Hello from Python!", iu.getPayload().get("data"));
}
@Test
public void testAddLinkThenPublishInPython() throws IOException, InterruptedException
{
String pypr = PYTHON_PREAMBLE
+"ob = ipaaca.OutputBuffer('pythonside')\n"
+"iu = ipaaca.IU('JavaPythonTest')\n"
+"iu.add_links('testtype',['dummy1','dummy2'])\n"
+ "time.sleep(0.1)\n"
+ "ob.add(iu)\n";
assertTrue(runPythonProgram(pypr));
Thread.sleep(200);
assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertThat(iu.getLinks("testtype"),containsInAnyOrder("dummy1","dummy2"));
}
@Test
public void testPublishThenAddLinkInPython() throws IOException, InterruptedException
{
String pypr = PYTHON_PREAMBLE
+"ob = ipaaca.OutputBuffer('pythonside')\n"
+"iu = ipaaca.IU('JavaPythonTest')\n"
+ "ob.add(iu)\n"
+ "time.sleep(0.1)\n"
+"iu.add_links('testtype',['dummy1','dummy2'])\n";
assertTrue(runPythonProgram(pypr));
Thread.sleep(200);
assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertThat(iu.getLinks("testtype"),containsInAnyOrder("dummy1","dummy2"));
}
@Test
public void testCommitPublishedIUFromPython()throws IOException, InterruptedException
{
String pypr = PYTHON_PREAMBLE
+"ob = ipaaca.OutputBuffer('pythonside')\n"
+"iu = ipaaca.IU('JavaPythonTest')\n"
+ "ob.add(iu)\n"
+ "time.sleep(0.1)\n"
+ "iu.commit()\n";
assertTrue(runPythonProgram(pypr));
Thread.sleep(200);
assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertTrue(iu.isCommitted());
}
@Test
public void testCommitThenPublishIUFromPython()throws IOException, InterruptedException
{
String pypr = PYTHON_PREAMBLE
+"ob = ipaaca.OutputBuffer('pythonside')\n"
+"iu = ipaaca.IU('JavaPythonTest')\n"
+"iu.commit()\n"
+"time.sleep(0.1)\n"
+"ob.add(iu)\n";
assertTrue(runPythonProgram(pypr));
Thread.sleep(200);
assertEquals(1, inBuffer.getIUs().size());
AbstractIU iu = inBuffer.getIUs().iterator().next();
assertTrue(iu.isCommitted());
}
} }
...@@ -342,7 +342,8 @@ class IU(IUInterface):#{{{ ...@@ -342,7 +342,8 @@ class IU(IUInterface):#{{{
if not self._committed: if not self._committed:
self._increase_revision_number() self._increase_revision_number()
self._committed = True self._committed = True
self.buffer._send_iu_commission(self, writer_name=writer_name) if self.buffer is not None:
self.buffer._send_iu_commission(self, writer_name=writer_name)
def commit(self): def commit(self):
"""Commit to this IU.""" """Commit to this IU."""
......
<ivy-module version="2.0"> <ivy-module version="2.0">
<info organisation="ipaaca" module="IpaacaPythonTest"/> <info organisation="ipaaca" module="IpaacaPythonTest"/>
<dependencies > <dependencies>
<dependency org="hamcrest" name="hamcrest" rev="latest.release"/>
</dependencies> </dependencies>
</ivy-module> </ivy-module>
#!/usr/bin/env python #!/usr/bin/env python
import sys
import time import time
import unittest
import hamcrest as hc
import ipaaca import ipaaca
import sys
import unittest
def handle_iu_event(iu, event_type, local): def handle_iu_event(iu, event_type, local):
print('(IU event '+event_type+' '+str(iu.uid)+')') print('(IU event '+event_type+' '+str(iu.uid)+')')
...@@ -22,10 +23,10 @@ class IpaacaIUStoreTestCase(unittest.TestCase): ...@@ -22,10 +23,10 @@ class IpaacaIUStoreTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
def testInputBufferContents(self): def testInputBufferContents(self):
self.assertIn(self.sensor_iu.uid, self.ib.iu_store) hc.assert_that(self.ib.iu_store, hc.has_key(self.sensor_iu.uid))
self.assertEqual(len(self.ib.iu_store), 1) self.assertEqual(len(self.ib.iu_store), 1)
def testOutputBufferContents(self): def testOutputBufferContents(self):
self.assertIn(self.sensor_iu.uid, self.ob.iu_store) hc.assert_that(self.ib.iu_store, hc.has_key(self.sensor_iu.uid))
self.assertEqual(len(self.ob.iu_store), 1) self.assertEqual(len(self.ob.iu_store), 1)
class IpaacaPayloadTestCase(unittest.TestCase): class IpaacaPayloadTestCase(unittest.TestCase):
...@@ -41,6 +42,29 @@ class IpaacaPayloadTestCase(unittest.TestCase): ...@@ -41,6 +42,29 @@ class IpaacaPayloadTestCase(unittest.TestCase):
iu_received = self.ib.iu_store.get(self.sensor_iu.uid) iu_received = self.ib.iu_store.get(self.sensor_iu.uid)
self.assertEqual(iu_received.payload["data"], 'sensordata') self.assertEqual(iu_received.payload["data"], 'sensordata')
class IpaacaCommitTestCases(unittest.TestCase):
def setUp(self):
self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory'])
self.ob = ipaaca.OutputBuffer('TestOut')
self.iu = ipaaca.IU('sensorcategory')
def testCommitBeforePublish(self):
self.iu.commit()
self.ob.add(self.iu)
time.sleep(0.1)
received_iu = self.ib.iu_store[self.iu.uid]
self.assertTrue(received_iu.committed)
def testCommitAfterPublish(self):
self.ob.add(self.iu)
self.iu.commit()
time.sleep(0.1)
received_iu = self.ib.iu_store[self.iu.uid]
self.assertTrue(received_iu.committed)
class IpaacaLinksTestCase(unittest.TestCase): class IpaacaLinksTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory', 'decisioncategory']) self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory', 'decisioncategory'])
...@@ -58,10 +82,10 @@ class IpaacaLinksTestCase(unittest.TestCase): ...@@ -58,10 +82,10 @@ class IpaacaLinksTestCase(unittest.TestCase):
self.ob.add(self.decision_iu) self.ob.add(self.decision_iu)
time.sleep(0.1) time.sleep(0.1)
# test received version # test received version
self.assertIn(self.decision_iu.uid, self.ib.iu_store) hc.assert_that(self.ib.iu_store, hc.has_key(self.decision_iu.uid))
received_iu = self.ib.iu_store[self.decision_iu.uid] received_iu = self.ib.iu_store[self.decision_iu.uid]
grinlinks = received_iu.get_links('grin') grinlinks = received_iu.get_links('grin')
self.assertIn(self.sensor_iu.uid, grinlinks) hc.assert_that(grinlinks, hc.has_item(self.sensor_iu.uid))
self.assertEqual(len(grinlinks), 1) self.assertEqual(len(grinlinks), 1)
def testSetAndRemoveSingleLink(self): def testSetAndRemoveSingleLink(self):
time.sleep(0.1) time.sleep(0.1)
...@@ -73,7 +97,7 @@ class IpaacaLinksTestCase(unittest.TestCase): ...@@ -73,7 +97,7 @@ class IpaacaLinksTestCase(unittest.TestCase):
self.decision_iu.remove_links('grin', [self.sensor_iu.uid]) self.decision_iu.remove_links('grin', [self.sensor_iu.uid])
time.sleep(0.1) time.sleep(0.1)
# test received version # test received version
self.assertIn(self.decision_iu.uid, self.ib.iu_store) hc.assert_that(self.ib.iu_store, hc.has_key(self.decision_iu.uid))
received_iu = self.ib.iu_store[self.decision_iu.uid] received_iu = self.ib.iu_store[self.decision_iu.uid]
grinlinks = received_iu.get_links('grin') grinlinks = received_iu.get_links('grin')
self.assertEqual(len(grinlinks), 0) self.assertEqual(len(grinlinks), 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment