From 5f02fa0e59dc84e12fae1fde61bdfa8edb5446b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 6 Jan 2020 18:58:25 +0100 Subject: Fix handling of multipart udp messages --- .../pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 179 +++++++++++++-------- 1 file changed, 108 insertions(+), 71 deletions(-) (limited to 'src/test/java/pl/edu') 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 e4f601a..c4bb8e7 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -2,11 +2,14 @@ package pl.edu.mimuw.cloudatlas.agent; import org.junit.*; import pl.edu.mimuw.cloudatlas.agent.messages.UDUPMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; 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.AttributesMap; import pl.edu.mimuw.cloudatlas.model.PathName; import pl.edu.mimuw.cloudatlas.model.ValueContact; +import pl.edu.mimuw.cloudatlas.model.ValueInt; import java.net.InetAddress; import java.net.UnknownHostException; @@ -78,45 +81,64 @@ public class UDUPTest { 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)); + UDUP udp1 = null; + UDUP udp2 = null; + UDUPMessage msg1 = null; + boolean testSuccess = true; + int timeout = 5000; + + try { + System.out.println("Starting udp1"); + + udp1 = new UDUP( + InetAddress.getByName("127.0.0.2"), + 5998, + timeout, + 20); + + System.out.println("Starting udp2"); + + udp2 = new UDUP( + InetAddress.getByName("127.0.0.3"), + 5998, + timeout, + 20); + + UDUPMessage testContent = new UDUPMessage(); + testContent.setDestinationModule(ModuleType.TEST); + + msg1 = new UDUPMessage( + "udup1", + new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), + testContent + ); + + } catch (UnknownHostException e) { + e.printStackTrace(); } - UDUPMessage msg1 = new UDUPMessage( - "udp1", - ModuleType.UDP, - "localhost", - 5998, - new UpdateAttributesMessage("updateattrib1", 0,"/", bigAttrib), - 0, - "conv1"); + Thread udpThread1 = new Thread(udp1); + udpThread1.start(); + Thread udpThread2 = new Thread(udp2); + udpThread2.start(); try { udp1.handle(msg1); - Thread.sleep(1000); - UDUPMessage conv = udp2.fetchConversation("conv1"); - Assert.assertEquals(conv.getConversationId(), "conv1"); + Thread.sleep(timeout + 1000); } catch (InterruptedException | Module.InvalidMessageType e) { e.printStackTrace(); - } catch (UDUP.InvalidConversation noConversationError) { + testSuccess = false; + } + + udpThread1.interrupt(); + udpThread2.interrupt(); + + if (testSuccess) { + Assert.assertTrue(true); + } else { Assert.fail(); } } @@ -124,53 +146,68 @@ public class UDUPTest { @Test public void sendMultipleMessages() { - @Test - public void messageBetweenUDUPs() { - UDUP udp1 = new UDUP( - ModuleType.UDP, - 5999, - 1000, - 5000, - 3, - 256); + UDUP udp1 = null; + UDUP udp2 = null; + UDUPMessage msg1 = null; + UDUPMessage msg2 = null; + UDUPMessage msg3 = null; + boolean testSuccess = true; + int timeout = 5000; - UDUP udp2 = new UDUP( - ModuleType.UDP, - 5998, - 1000, - 5000, - 3, - 256); + try { + System.out.println("Starting udp1"); - UDUPMessage msg1 = new UDUPMessage( - "1", - ModuleType.UDP, - "localhost", - 5998, - null, - 0, - "conv1"); + udp1 = new UDUP( + InetAddress.getByName("127.0.0.2"), + 5997, + timeout, + 1000); + System.out.println("Starting udp2"); + udp2 = new UDUP( + InetAddress.getByName("127.0.0.3"), + 5997, + timeout, + 1000); + UDUPMessage testContent = new UDUPMessage(); + testContent.setDestinationModule(ModuleType.TEST); - 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(); - } + msg1 = new UDUPMessage( + "udup1", + new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), + testContent + ); + + msg2 = new UDUPMessage( + "udup2", + new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), + testContent + ); + + msg3 = new UDUPMessage( + "udup3", + new ValueContact(new PathName("/udp2"), InetAddress.getByName("127.0.0.3")), + testContent + ); + + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + Thread udpThread1 = new Thread(udp1); + udpThread1.start(); + Thread udpThread2 = new Thread(udp2); + udpThread2.start(); + + try { + udp1.handle(msg1); + udp1.handle(msg2); + udp1.handle(msg3); + Thread.sleep(timeout + 2000); + } catch (InterruptedException | Module.InvalidMessageType e) { + e.printStackTrace(); } } -*/ } -- cgit v1.2.3 From 28c905a7365a37d0874b865f513c64b31d8679f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 6 Jan 2020 20:10:50 +0100 Subject: Add custom serialization to type collection --- src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/test/java/pl/edu') 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 c4bb8e7..8809312 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -14,6 +14,8 @@ import pl.edu.mimuw.cloudatlas.model.ValueInt; import java.net.InetAddress; import java.net.UnknownHostException; +// TODO add serialization tests that target custom serializers (type collections!) + public class UDUPTest { @Test -- cgit v1.2.3 From 90d3d2e3e1e116bbb288d78e9c6c996a7f1e0270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 15:26:52 +0100 Subject: Fix segmentation --- src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/test/java/pl/edu') 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 8809312..13a322b 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -44,6 +44,7 @@ public class UDUPTest { UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); + testContent.setMessageId("singleMsgTest"); msg1 = new UDUPMessage( "udup1", @@ -99,7 +100,7 @@ public class UDUPTest { InetAddress.getByName("127.0.0.2"), 5998, timeout, - 20); + 30); System.out.println("Starting udp2"); @@ -107,10 +108,11 @@ public class UDUPTest { InetAddress.getByName("127.0.0.3"), 5998, timeout, - 20); + 30); UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); + testContent.setMessageId("bigMsgTest"); msg1 = new UDUPMessage( "udup1", @@ -175,6 +177,7 @@ public class UDUPTest { UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); + testContent.setMessageId("multipleMsgTest"); msg1 = new UDUPMessage( "udup1", -- cgit v1.2.3