From bb0d92a3a0339695776797d25252815bf8921fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 15:53:02 +0100 Subject: Separate server from udup --- .../pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 69 +++++++++++++--------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'src/test/java/pl') 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 13a322b..93ed8be 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -6,12 +6,14 @@ 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.agent.modules.UDUPServer; 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.SocketException; import java.net.UnknownHostException; // TODO add serialization tests that target custom serializers (type collections!) @@ -22,25 +24,30 @@ public class UDUPTest { public void messageBetweenUDUPs() { UDUP udp1 = null; UDUP udp2 = null; + UDUPServer server1 = null; + UDUPServer server2 = null; UDUPMessage msg1 = null; boolean testSuccess = true; + int timeout = 5000; try { System.out.println("Starting udp1"); + server1 = new UDUPServer(InetAddress.getByName("127.0.0.2"), 5996, 1000); udp1 = new UDUP( - InetAddress.getByName("127.0.0.2"), - 5999, - 5000, - 1000); + 5997, + timeout, + 1000, + server1); System.out.println("Starting udp2"); + server2 = new UDUPServer(InetAddress.getByName("127.0.0.3"), 5996, 1000); udp2 = new UDUP( - InetAddress.getByName("127.0.0.3"), - 5999, - 5000, - 1000); + 5997, + timeout, + 1000, + server2); UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); @@ -52,13 +59,13 @@ public class UDUPTest { testContent ); - } catch (UnknownHostException e) { + } catch (UnknownHostException | SocketException e) { e.printStackTrace(); } - Thread udpThread1 = new Thread(udp1); + Thread udpThread1 = new Thread(server1); udpThread1.start(); - Thread udpThread2 = new Thread(udp2); + Thread udpThread2 = new Thread(server2); udpThread2.start(); try { @@ -89,6 +96,8 @@ public class UDUPTest { public void bigMessageBetweenUDUPs() { UDUP udp1 = null; UDUP udp2 = null; + UDUPServer server1 = null; + UDUPServer server2 = null; UDUPMessage msg1 = null; boolean testSuccess = true; int timeout = 5000; @@ -96,19 +105,21 @@ public class UDUPTest { try { System.out.println("Starting udp1"); + server1 = new UDUPServer(InetAddress.getByName("127.0.0.2"), 5991, 1000); udp1 = new UDUP( - InetAddress.getByName("127.0.0.2"), - 5998, + 5997, timeout, - 30); + 30, + server1); System.out.println("Starting udp2"); + server2 = new UDUPServer(InetAddress.getByName("127.0.0.3"), 5991, 1000); udp2 = new UDUP( - InetAddress.getByName("127.0.0.3"), - 5998, + 5997, timeout, - 30); + 30, + server2); UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); @@ -120,13 +131,13 @@ public class UDUPTest { testContent ); - } catch (UnknownHostException e) { + } catch (UnknownHostException | SocketException e) { e.printStackTrace(); } - Thread udpThread1 = new Thread(udp1); + Thread udpThread1 = new Thread(server1); udpThread1.start(); - Thread udpThread2 = new Thread(udp2); + Thread udpThread2 = new Thread(server2); udpThread2.start(); try { @@ -152,6 +163,8 @@ public class UDUPTest { public void sendMultipleMessages() { UDUP udp1 = null; UDUP udp2 = null; + UDUPServer server1 = null; + UDUPServer server2 = null; UDUPMessage msg1 = null; UDUPMessage msg2 = null; UDUPMessage msg3 = null; @@ -161,19 +174,21 @@ public class UDUPTest { try { System.out.println("Starting udp1"); + server1 = new UDUPServer(InetAddress.getByName("127.0.0.2"), 5997, 1000); udp1 = new UDUP( - InetAddress.getByName("127.0.0.2"), 5997, timeout, - 1000); + 1000, + server1); System.out.println("Starting udp2"); + server2 = new UDUPServer(InetAddress.getByName("127.0.0.3"), 5997, 1000); udp2 = new UDUP( - InetAddress.getByName("127.0.0.3"), 5997, timeout, - 1000); + 1000, + server2); UDUPMessage testContent = new UDUPMessage(); testContent.setDestinationModule(ModuleType.TEST); @@ -197,13 +212,13 @@ public class UDUPTest { testContent ); - } catch (UnknownHostException e) { + } catch (UnknownHostException | SocketException e) { e.printStackTrace(); } - Thread udpThread1 = new Thread(udp1); + Thread udpThread1 = new Thread(server1); udpThread1.start(); - Thread udpThread2 = new Thread(udp2); + Thread udpThread2 = new Thread(server2); udpThread2.start(); try { -- cgit v1.2.3 From 1f87c2d319b2671bd2d61feb3a76d102059c4c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 19:06:26 +0100 Subject: Make UDUP handle only gossip girl messages with its timestamps --- .../pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 60 +++++++++++++++------- 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'src/test/java/pl') 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 93ed8be..ac2c587 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -1,6 +1,8 @@ package pl.edu.mimuw.cloudatlas.agent; import org.junit.*; +import pl.edu.mimuw.cloudatlas.agent.messages.GossipGirlMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.RemoteGossipGirlMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UDUPMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; import pl.edu.mimuw.cloudatlas.agent.modules.Module; @@ -49,9 +51,9 @@ public class UDUPTest { 1000, server2); - UDUPMessage testContent = new UDUPMessage(); + RemoteGossipGirlMessage testContent = + new RemoteGossipGirlMessage("singleMsgTest", 0, GossipGirlMessage.Type.NO_CO_TAM); testContent.setDestinationModule(ModuleType.TEST); - testContent.setMessageId("singleMsgTest"); msg1 = new UDUPMessage( "udup1", @@ -61,6 +63,7 @@ public class UDUPTest { } catch (UnknownHostException | SocketException e) { e.printStackTrace(); + testSuccess = false; } Thread udpThread1 = new Thread(server1); @@ -69,13 +72,12 @@ public class UDUPTest { udpThread2.start(); try { - Thread.sleep(5000); - System.out.println("Sending message"); + Thread.sleep(500); if (udp1 == null | udp2 == null) { - Assert.fail("UDPs not initialized"); + testSuccess = false; } else { udp1.handle(msg1); - Thread.sleep(10000); + Thread.sleep(timeout); } } catch (InterruptedException | Module.InvalidMessageType e) { e.printStackTrace(); @@ -100,7 +102,7 @@ public class UDUPTest { UDUPServer server2 = null; UDUPMessage msg1 = null; boolean testSuccess = true; - int timeout = 5000; + int timeout = 3000; try { System.out.println("Starting udp1"); @@ -121,9 +123,9 @@ public class UDUPTest { 30, server2); - UDUPMessage testContent = new UDUPMessage(); + RemoteGossipGirlMessage testContent = + new RemoteGossipGirlMessage("bigMsgTest", 0, GossipGirlMessage.Type.NO_CO_TAM); testContent.setDestinationModule(ModuleType.TEST); - testContent.setMessageId("bigMsgTest"); msg1 = new UDUPMessage( "udup1", @@ -133,6 +135,7 @@ public class UDUPTest { } catch (UnknownHostException | SocketException e) { e.printStackTrace(); + testSuccess = false; } Thread udpThread1 = new Thread(server1); @@ -141,8 +144,13 @@ public class UDUPTest { udpThread2.start(); try { - udp1.handle(msg1); - Thread.sleep(timeout + 1000); + Thread.sleep(500); + if (udp1 == null | udp2 == null) { + testSuccess = false; + } else { + udp1.handle(msg1); + Thread.sleep(timeout); + } } catch (InterruptedException | Module.InvalidMessageType e) { e.printStackTrace(); testSuccess = false; @@ -169,7 +177,7 @@ public class UDUPTest { UDUPMessage msg2 = null; UDUPMessage msg3 = null; boolean testSuccess = true; - int timeout = 5000; + int timeout = 3000; try { System.out.println("Starting udp1"); @@ -190,9 +198,9 @@ public class UDUPTest { 1000, server2); - UDUPMessage testContent = new UDUPMessage(); + RemoteGossipGirlMessage testContent = + new RemoteGossipGirlMessage("multipleMsgTest", 0, GossipGirlMessage.Type.NO_CO_TAM); testContent.setDestinationModule(ModuleType.TEST); - testContent.setMessageId("multipleMsgTest"); msg1 = new UDUPMessage( "udup1", @@ -214,6 +222,7 @@ public class UDUPTest { } catch (UnknownHostException | SocketException e) { e.printStackTrace(); + testSuccess = false; } Thread udpThread1 = new Thread(server1); @@ -222,12 +231,27 @@ public class UDUPTest { udpThread2.start(); try { - udp1.handle(msg1); - udp1.handle(msg2); - udp1.handle(msg3); - Thread.sleep(timeout + 2000); + Thread.sleep(500); + if (udp1 == null | udp2 == null) { + testSuccess = false; + } else { + udp1.handle(msg1); + udp1.handle(msg2); + udp1.handle(msg3); + Thread.sleep(timeout); + } } catch (InterruptedException | Module.InvalidMessageType e) { e.printStackTrace(); + testSuccess = false; + } + + udpThread1.interrupt(); + udpThread2.interrupt(); + + if (testSuccess) { + Assert.assertTrue(true); + } else { + Assert.fail(); } } } -- cgit v1.2.3