From bfd4c421004ce35a9eac307c3ac4976caa1820ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 5 Jan 2020 18:00:56 +0100 Subject: UDUP with no serialization working --- src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java | 4 ++++ src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java create mode 100644 src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java (limited to 'src/test/java') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java new file mode 100644 index 0000000..c56f00a --- /dev/null +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java @@ -0,0 +1,4 @@ +package pl.edu.mimuw.cloudatlas.agent; + +public class GossipTest { +} diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java new file mode 100644 index 0000000..975c918 --- /dev/null +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -0,0 +1,4 @@ +package pl.edu.mimuw.cloudatlas.agent; + +public class UDUPTest { +} -- cgit v1.2.3 From 55fecc86b43cc46fd949ab9b6c6910d2194e6cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 5 Jan 2020 18:01:45 +0100 Subject: Add UDUP basic test --- .../pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 182 +++++++++++++++++++++ 1 file changed, 182 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java index 975c918..545ad56 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -1,4 +1,186 @@ package pl.edu.mimuw.cloudatlas.agent; +import org.junit.*; +import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UDUPMessage; +import pl.edu.mimuw.cloudatlas.agent.modules.Module; +import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; +import pl.edu.mimuw.cloudatlas.agent.modules.UDUP; +import pl.edu.mimuw.cloudatlas.model.PathName; +import pl.edu.mimuw.cloudatlas.model.ValueContact; + +import java.net.InetAddress; +import java.net.UnknownHostException; + public class UDUPTest { + + @Test + public void messageBetweenUDUPs() { + UDUP udp1 = null; + UDUP udp2 = null; + UDUPMessage msg1 = null; + boolean testSuccess = true; + + try { + System.out.println("Starting udp1"); + + udp1 = new UDUP( + ModuleType.UDP, + InetAddress.getByName("127.0.0.2"), + 5999, + 1000, + 5000, + 20000); + + System.out.println("Starting udp2"); + + udp2 = new UDUP( + ModuleType.UDP, + InetAddress.getByName("127.0.0.3"), + 5999, + 1000, + 5000, + 20000); + + msg1 = new UDUPMessage( + "1", + new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), + null, //new GetStateMessage("getstate1", 0, ModuleType.UDP, 1), + 0, + "conv1"); + + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + Thread udpThread1 = new Thread(udp1); + udpThread1.start(); + Thread udpThread2 = new Thread(udp2); + udpThread2.start(); + + try { + Thread.sleep(5000); + System.out.println("Sending message"); + if (udp1 == null | udp2 == null) { + Assert.fail("UDPs not initialized"); + } else { + udp1.handle(msg1); + Thread.sleep(10000); + UDUPMessage conv = udp2.fetchConversation("conv1"); + if (!conv.getConversationId().equals("conv1")) { + testSuccess = false; + } + } + } catch (InterruptedException | Module.InvalidMessageType e) { + e.printStackTrace(); + testSuccess = false; + } catch (UDUP.InvalidConversation invalidConversation) { + System.out.println("Invalid conversation"); + testSuccess = false; + } + + udpThread1.interrupt(); + udpThread2.interrupt(); + + if (testSuccess) { + Assert.assertTrue(true); + } else { + Assert.fail(); + } + } +/* + @Test + public void bigMessageBetweenUDUPs() { + UDUP udp1 = new UDUP( + ModuleType.UDP, + 5999, + 1000, + 5000, + 256); + + UDUP udp2 = new UDUP( + ModuleType.UDP, + 5998, + 1000, + 5000, + 256); + + AttributesMap bigAttrib = new AttributesMap(); + for (Long i = 1L; i < 20; i++) { + bigAttrib.add(i.toString(), new ValueInt(i)); + } + + UDUPMessage msg1 = new UDUPMessage( + "udp1", + ModuleType.UDP, + "localhost", + 5998, + new UpdateAttributesMessage("updateattrib1", 0,"/", bigAttrib), + 0, + "conv1"); + + try { + udp1.handle(msg1); + Thread.sleep(1000); + UDUPMessage conv = udp2.fetchConversation("conv1"); + Assert.assertEquals(conv.getConversationId(), "conv1"); + } catch (InterruptedException | Module.InvalidMessageType e) { + e.printStackTrace(); + } catch (UDUP.InvalidConversation noConversationError) { + Assert.fail(); + } + } + + + @Test + public void sendMultipleMessages() { + @Test + public void messageBetweenUDUPs() { + UDUP udp1 = new UDUP( + ModuleType.UDP, + 5999, + 1000, + 5000, + 3, + 256); + + UDUP udp2 = new UDUP( + ModuleType.UDP, + 5998, + 1000, + 5000, + 3, + 256); + + UDUPMessage msg1 = new UDUPMessage( + "1", + ModuleType.UDP, + "localhost", + 5998, + null, + 0, + "conv1"); + + + + + try { + udp1.handle(msg1); + udp1.handle(msg2); + udp1.handle(msg3); + Thread.sleep(1000); + UDUPMessage conv1 = udp2.fetchConversation("conv1"); + Assert.assertEquals(conv1.getConversationId(), "conv1"); + UDUPMessage conv2 = udp2.fetchConversation("conv2"); + Assert.assertEquals(conv2.getConversationId(), "conv2"); + UDUPMessage conv3 = udp2.fetchConversation("conv3"); + Assert.assertEquals(conv3.getConversationId(), "conv3"); + } catch (InterruptedException | Module.InvalidMessageType e) { + e.printStackTrace(); + } catch (UDUP.InvalidConversation invalidConversation) { + Assert.fail(); + } + } + } +*/ } -- cgit v1.2.3 From ab9a470aa67ef414581145ad671e119d9edb86d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 6 Jan 2020 16:14:44 +0100 Subject: Refactor UDUP module --- src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java (limited to 'src/test/java') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java deleted file mode 100644 index c56f00a..0000000 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/GossipTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package pl.edu.mimuw.cloudatlas.agent; - -public class GossipTest { -} -- cgit v1.2.3 From db22fe6c09a33c2cf5a7936442ccb7b8307ae84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 6 Jan 2020 16:35:16 +0100 Subject: Improve existing test --- .../pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 26 +++++++--------------- 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java index 545ad56..e4f601a 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -1,7 +1,6 @@ package pl.edu.mimuw.cloudatlas.agent; import org.junit.*; -import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UDUPMessage; import pl.edu.mimuw.cloudatlas.agent.modules.Module; import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; @@ -25,29 +24,27 @@ public class UDUPTest { System.out.println("Starting udp1"); udp1 = new UDUP( - ModuleType.UDP, InetAddress.getByName("127.0.0.2"), 5999, - 1000, 5000, - 20000); + 1000); System.out.println("Starting udp2"); udp2 = new UDUP( - ModuleType.UDP, InetAddress.getByName("127.0.0.3"), 5999, - 1000, 5000, - 20000); + 1000); + + UDUPMessage testContent = new UDUPMessage(); + testContent.setDestinationModule(ModuleType.TEST); msg1 = new UDUPMessage( - "1", + "udup1", new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), - null, //new GetStateMessage("getstate1", 0, ModuleType.UDP, 1), - 0, - "conv1"); + testContent + ); } catch (UnknownHostException e) { e.printStackTrace(); @@ -66,17 +63,10 @@ public class UDUPTest { } else { udp1.handle(msg1); Thread.sleep(10000); - UDUPMessage conv = udp2.fetchConversation("conv1"); - if (!conv.getConversationId().equals("conv1")) { - testSuccess = false; - } } } catch (InterruptedException | Module.InvalidMessageType e) { e.printStackTrace(); testSuccess = false; - } catch (UDUP.InvalidConversation invalidConversation) { - System.out.println("Invalid conversation"); - testSuccess = false; } udpThread1.interrupt(); -- cgit v1.2.3