From 7956fb8b67e6f10760431cbe77db2fcf33d5e9e0 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 10 Jan 2020 20:14:43 +0100 Subject: Send state updates after gossip --- .../cloudatlas/agent/modules/GossipGirlTest.java | 85 +++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java index 7ac27e9..fffb577 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java @@ -24,6 +24,8 @@ import pl.edu.mimuw.cloudatlas.agent.messages.NoCoTamMessage; import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage; import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UDUPMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; import pl.edu.mimuw.cloudatlas.model.AttributesMap; import pl.edu.mimuw.cloudatlas.model.Attribute; @@ -49,6 +51,10 @@ public class GossipGirlTest { private Map> initiatorQueries; private StateMessage initiatorStateMessage; private NoCoTamMessage noCoTamMessage; + private AttributesMessage attributesMessage1; + private AttributesMessage attributesMessage2; + private QueryMessage queryMessage1; + private QueryMessage queryMessage2; @Before public void setupLocals() throws Exception { @@ -75,6 +81,37 @@ public class GossipGirlTest { Map otherQueryTimestamps = makeOtherQueryTimestamps(); noCoTamMessage = new NoCoTamMessage("", 0, 0, 42, otherZoneTimestamps, otherQueryTimestamps, TestUtil.addToTime(testTime, 10), TestUtil.addToTime(testTime, 22)); + + attributesMessage1 = makeAttributesMessage("/son/bro", makeAttributes1()); + attributesMessage2 = makeAttributesMessage("/son/whodis", makeAttributes2()); + queryMessage1 = makeQueryMessage("&one", "SELECT 3 AS one"); + queryMessage2 = makeQueryMessage("&three", "SELECT 3 AS three"); + } + + public QueryMessage makeQueryMessage(String name, String query) throws Exception { + return new QueryMessage("", 0, new Attribute(name), new ValueQuery(query), 0); + } + + public AttributesMap makeAttributes1() { + AttributesMap attributes = new AttributesMap(); + attributes.add("name", new ValueString("bro")); + attributes.add("timestamp", testTime); + attributes.add("foo", new ValueInt(140l)); + attributes.add("bar", new ValueString(":wq")); + return attributes; + } + + public AttributesMap makeAttributes2() { + AttributesMap attributes = new AttributesMap(); + attributes.add("name", new ValueString("whodis")); + attributes.add("timestamp", TestUtil.addToTime(testTime, -300)); + attributes.add("foo", new ValueInt(61l)); + attributes.add("bar", new ValueString("nice")); + return attributes; + } + + public AttributesMessage makeAttributesMessage(String path, AttributesMap attributes) { + return new AttributesMessage("", 0, new PathName(path), attributes, 0); } public Map makeOtherZoneTimestamps() { @@ -165,7 +202,6 @@ public class GossipGirlTest { ); HejkaMessage hejkaMessage = (HejkaMessage) ((UDUPMessage) receivedMessage).getContent(); assertEquals(0, hejkaMessage.getSenderGossipId()); - System.out.println(hejkaMessage.getZoneTimestamps().keySet()); assertEquals(3, TestUtil.iterableSize(hejkaMessage.getZoneTimestamps().keySet())); Set zoneSet = hejkaMessage.getZoneTimestamps().keySet(); assertThat(zoneSet, hasItems(new PathName("/daughter"))); @@ -203,6 +239,53 @@ public class GossipGirlTest { assertQueryMessage(receivedMessage5, "/son/bro", "&query", "SELECT sum(foo) AS foo"); } + @Test + public void initiatorModifiesStateOnAttributes() throws Exception { + gossipGirl.handleTyped(initiateGossipMessage); + executor.messagesToPass.take(); + gossipGirl.handleTyped(initiatorStateMessage); + executor.messagesToPass.take(); + gossipGirl.handleTyped(noCoTamMessage); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + + gossipGirl.handleTyped(attributesMessage1); + AgentMessage receivedMessage1 = executor.messagesToPass.poll(); + assertNotNull(receivedMessage1); + assertEquals(ModuleType.STATE, receivedMessage1.getDestinationModule()); + StanikMessage stanikMessage1 = (StanikMessage) receivedMessage1; + assertEquals(StanikMessage.Type.UPDATE_ATTRIBUTES, stanikMessage1.getType()); + UpdateAttributesMessage updateMessage1 = (UpdateAttributesMessage) stanikMessage1; + assertEquals("/son/bro", updateMessage1.getPathName()); + // TODO: this should be modified by GTP + assertEquals(testTime, updateMessage1.getAttributes().getOrNull("timestamp")); + assertEquals(new ValueInt(140l), updateMessage1.getAttributes().getOrNull("foo")); + assertEquals(new ValueString(":wq"), updateMessage1.getAttributes().getOrNull("bar")); + + gossipGirl.handleTyped(queryMessage1); + AgentMessage receivedMessage2 = executor.messagesToPass.poll(); + assertNotNull(receivedMessage2); + assertEquals(ModuleType.STATE, receivedMessage2.getDestinationModule()); + StanikMessage stanikMessage2 = (StanikMessage) receivedMessage2; + assertEquals(StanikMessage.Type.UPDATE_QUERIES, stanikMessage2.getType()); + UpdateQueriesMessage updateMessage2 = (UpdateQueriesMessage) stanikMessage2; + assertEquals(1, updateMessage2.getQueries().keySet().size()); + assertThat(updateMessage2.getQueries().keySet(), hasItems(new Attribute("&one"))); + assertEquals(updateMessage2.getQueries().get(new Attribute("&one")), + new SimpleImmutableEntry( + new ValueQuery("SELECT 3 AS one"), + // TODO: this should be modified by GTP + TestUtil.addToTime(testTime, 10) + ) + ); + + gossipGirl.handleTyped(attributesMessage2); + gossipGirl.handleTyped(queryMessage2); + } + private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception { assertUDUPMessage( message, -- cgit v1.2.3 From 89af38da0b95445180440e85bb8248ab910ef9f8 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 10 Jan 2020 22:58:32 +0100 Subject: Send NoCoTam when responder gets state --- .../cloudatlas/agent/modules/GossipGirlTest.java | 63 +++++++++++++++++++--- 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java index fffb577..170b76e 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java @@ -49,13 +49,15 @@ public class GossipGirlTest { private ValueTime testTime; private ZMI initiatorHierarchy; private Map> initiatorQueries; - private StateMessage initiatorStateMessage; + private StateMessage stateMessage; private NoCoTamMessage noCoTamMessage; private AttributesMessage attributesMessage1; private AttributesMessage attributesMessage2; private QueryMessage queryMessage1; private QueryMessage queryMessage2; + private HejkaMessage hejkaMessage; + @Before public void setupLocals() throws Exception { gossipGirl = new GossipGirl(); @@ -75,19 +77,25 @@ public class GossipGirlTest { testTime = ValueUtils.currentTime(); setupHierarchy(); setupQueries(); - initiatorStateMessage = new StateMessage("", ModuleType.GOSSIP, 0, 0, initiatorHierarchy, initiatorQueries); + stateMessage = new StateMessage("", ModuleType.GOSSIP, 0, 0, initiatorHierarchy, initiatorQueries); Map otherZoneTimestamps = makeOtherZoneTimestamps(); Map otherQueryTimestamps = makeOtherQueryTimestamps(); - noCoTamMessage = new NoCoTamMessage("", 0, 0, 42, otherZoneTimestamps, otherQueryTimestamps, TestUtil.addToTime(testTime, 10), TestUtil.addToTime(testTime, 22)); + noCoTamMessage = new NoCoTamMessage("", 0, 42, 0, otherZoneTimestamps, otherQueryTimestamps, TestUtil.addToTime(testTime, 10), TestUtil.addToTime(testTime, 22)); attributesMessage1 = makeAttributesMessage("/son/bro", makeAttributes1()); attributesMessage2 = makeAttributesMessage("/son/whodis", makeAttributes2()); queryMessage1 = makeQueryMessage("&one", "SELECT 3 AS one"); queryMessage2 = makeQueryMessage("&three", "SELECT 3 AS three"); + + hejkaMessage = new HejkaMessage("", 0, 123, new PathName("/son/bro"), new PathName("/son/grand"), otherZoneTimestamps, otherQueryTimestamps); + hejkaMessage.setSentTimestamp(testTime); + hejkaMessage.setReceivedTimestamp(TestUtil.addToTime(testTime, 15)); + hejkaMessage.setSenderAddress(theirContact.getAddress()); } + public QueryMessage makeQueryMessage(String name, String query) throws Exception { return new QueryMessage("", 0, new Attribute(name), new ValueQuery(query), 0); } @@ -192,7 +200,7 @@ public class GossipGirlTest { public void initiatorSendsHejkaOnState() throws Exception { gossipGirl.handleTyped(initiateGossipMessage); executor.messagesToPass.take(); - gossipGirl.handleTyped(initiatorStateMessage); + gossipGirl.handleTyped(stateMessage); AgentMessage receivedMessage = executor.messagesToPass.poll(); assertUDUPMessage( @@ -202,6 +210,8 @@ public class GossipGirlTest { ); HejkaMessage hejkaMessage = (HejkaMessage) ((UDUPMessage) receivedMessage).getContent(); assertEquals(0, hejkaMessage.getSenderGossipId()); + assertEquals(new PathName("/son/grand"), hejkaMessage.getSenderPath()); + assertEquals(new PathName("/son/bro"), hejkaMessage.getReceiverPath()); assertEquals(3, TestUtil.iterableSize(hejkaMessage.getZoneTimestamps().keySet())); Set zoneSet = hejkaMessage.getZoneTimestamps().keySet(); assertThat(zoneSet, hasItems(new PathName("/daughter"))); @@ -219,7 +229,7 @@ public class GossipGirlTest { public void initiatorSendsZonesAndQueriesOnNoCoTam() throws Exception { gossipGirl.handleTyped(initiateGossipMessage); executor.messagesToPass.take(); - gossipGirl.handleTyped(initiatorStateMessage); + gossipGirl.handleTyped(stateMessage); executor.messagesToPass.take(); gossipGirl.handleTyped(noCoTamMessage); @@ -243,7 +253,7 @@ public class GossipGirlTest { public void initiatorModifiesStateOnAttributes() throws Exception { gossipGirl.handleTyped(initiateGossipMessage); executor.messagesToPass.take(); - gossipGirl.handleTyped(initiatorStateMessage); + gossipGirl.handleTyped(stateMessage); executor.messagesToPass.take(); gossipGirl.handleTyped(noCoTamMessage); executor.messagesToPass.take(); @@ -286,6 +296,47 @@ public class GossipGirlTest { gossipGirl.handleTyped(queryMessage2); } + @Test + public void getsStateOnHejka() throws Exception { + gossipGirl.handleTyped(hejkaMessage); + + AgentMessage receivedMessage = executor.messagesToPass.poll(); + assertNotNull(receivedMessage); + assertEquals(ModuleType.STATE, receivedMessage.getDestinationModule()); + StanikMessage stanikMessage = (StanikMessage) receivedMessage; + assertEquals(StanikMessage.Type.GET_STATE, stanikMessage.getType()); + GetStateMessage getStateMessage = (GetStateMessage) stanikMessage; + assertEquals(ModuleType.GOSSIP, getStateMessage.getRequestingModule()); + } + + @Test + public void receiverSendsNoCoTamOnState() throws Exception { + gossipGirl.handleTyped(hejkaMessage); + executor.messagesToPass.poll(); + + gossipGirl.handleTyped(stateMessage); + AgentMessage receivedMessage = executor.messagesToPass.poll(); + assertUDUPMessage( + receivedMessage, + new PathName("/son/bro"), + GossipGirlMessage.Type.NO_CO_TAM + ); + NoCoTamMessage noCoTamMessage = (NoCoTamMessage) ((UDUPMessage) receivedMessage).getContent(); + assertEquals(0, noCoTamMessage.getSenderGossipId()); + assertEquals(123, noCoTamMessage.getReceiverGossipId()); + assertEquals(3, TestUtil.iterableSize(noCoTamMessage.getZoneTimestamps().keySet())); + Set zoneSet = noCoTamMessage.getZoneTimestamps().keySet(); + assertThat(zoneSet, hasItems(new PathName("/daughter"))); + assertThat(zoneSet, hasItems(new PathName("/son/sis"))); + assertThat(zoneSet, hasItems(new PathName("/son/grand"))); + + assertEquals(3, TestUtil.iterableSize(noCoTamMessage.getQueryTimestamps().keySet())); + Set querySet = noCoTamMessage.getQueryTimestamps().keySet(); + assertThat(querySet, hasItems(new Attribute("&one"))); + assertThat(querySet, hasItems(new Attribute("&two"))); + assertThat(querySet, hasItems(new Attribute("&query"))); + } + private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception { assertUDUPMessage( message, -- cgit v1.2.3 From 0fca21f2011958d709a25aa1f4d863c1d646da6e Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 11 Jan 2020 12:08:02 +0100 Subject: Send info back from responder --- .../cloudatlas/agent/modules/GossipGirlTest.java | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java index 170b76e..37fdbe7 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java @@ -312,7 +312,7 @@ public class GossipGirlTest { @Test public void receiverSendsNoCoTamOnState() throws Exception { gossipGirl.handleTyped(hejkaMessage); - executor.messagesToPass.poll(); + executor.messagesToPass.take(); gossipGirl.handleTyped(stateMessage); AgentMessage receivedMessage = executor.messagesToPass.poll(); @@ -337,6 +337,31 @@ public class GossipGirlTest { assertThat(querySet, hasItems(new Attribute("&query"))); } + @Test + public void receiverSendsInfoOnFirstReceivedInfo() throws Exception { + gossipGirl.handleTyped(hejkaMessage); + executor.messagesToPass.take(); + gossipGirl.handleTyped(stateMessage); + executor.messagesToPass.take(); + + gossipGirl.handleTyped(attributesMessage1); + + // 3 ZMIs, 2 queries, 1 own attributes update + assertEquals(6, executor.messagesToPass.size()); + + AgentMessage receivedMessage1 = executor.messagesToPass.poll(); + assertAttributeMessage(receivedMessage1, "/son/bro", "/daughter"); + AgentMessage receivedMessage2 = executor.messagesToPass.poll(); + assertAttributeMessage(receivedMessage2, "/son/bro", "/son/sis"); + AgentMessage receivedMessage3 = executor.messagesToPass.poll(); + assertAttributeMessage(receivedMessage3, "/son/bro", "/son/grand"); + + AgentMessage receivedMessage4 = executor.messagesToPass.poll(); + assertQueryMessage(receivedMessage4, "/son/bro", "&two", "SELECT 2 AS two"); + AgentMessage receivedMessage5 = executor.messagesToPass.poll(); + assertQueryMessage(receivedMessage5, "/son/bro", "&query", "SELECT sum(foo) AS foo"); + } + private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception { assertUDUPMessage( message, -- cgit v1.2.3 From 63ed859398a815e310129de1af1f8821b690b700 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 11 Jan 2020 12:15:17 +0100 Subject: Update state on receiving info --- .../cloudatlas/agent/modules/GossipGirlTest.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java index 37fdbe7..bf6255e 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java @@ -362,6 +362,54 @@ public class GossipGirlTest { assertQueryMessage(receivedMessage5, "/son/bro", "&query", "SELECT sum(foo) AS foo"); } + @Test + public void receiverModifiesStateOnReceivedInfo() throws Exception { + gossipGirl.handleTyped(hejkaMessage); + executor.messagesToPass.take(); + gossipGirl.handleTyped(stateMessage); + executor.messagesToPass.take(); + + gossipGirl.handleTyped(attributesMessage1); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + executor.messagesToPass.take(); + + AgentMessage receivedMessage1 = executor.messagesToPass.poll(); + assertNotNull(receivedMessage1); + assertEquals(ModuleType.STATE, receivedMessage1.getDestinationModule()); + StanikMessage stanikMessage1 = (StanikMessage) receivedMessage1; + assertEquals(StanikMessage.Type.UPDATE_ATTRIBUTES, stanikMessage1.getType()); + UpdateAttributesMessage updateMessage1 = (UpdateAttributesMessage) stanikMessage1; + assertEquals("/son/bro", updateMessage1.getPathName()); + // TODO: this should be modified by GTP + assertEquals(testTime, updateMessage1.getAttributes().getOrNull("timestamp")); + assertEquals(new ValueInt(140l), updateMessage1.getAttributes().getOrNull("foo")); + assertEquals(new ValueString(":wq"), updateMessage1.getAttributes().getOrNull("bar")); + + gossipGirl.handleTyped(queryMessage1); + AgentMessage receivedMessage2 = executor.messagesToPass.poll(); + assertNotNull(receivedMessage2); + assertEquals(ModuleType.STATE, receivedMessage2.getDestinationModule()); + StanikMessage stanikMessage2 = (StanikMessage) receivedMessage2; + assertEquals(StanikMessage.Type.UPDATE_QUERIES, stanikMessage2.getType()); + UpdateQueriesMessage updateMessage2 = (UpdateQueriesMessage) stanikMessage2; + assertEquals(1, updateMessage2.getQueries().keySet().size()); + assertThat(updateMessage2.getQueries().keySet(), hasItems(new Attribute("&one"))); + assertEquals(updateMessage2.getQueries().get(new Attribute("&one")), + new SimpleImmutableEntry( + new ValueQuery("SELECT 3 AS one"), + // TODO: this should be modified by GTP + TestUtil.addToTime(testTime, 10) + ) + ); + + gossipGirl.handleTyped(attributesMessage2); + gossipGirl.handleTyped(queryMessage2); + assertTrue(false); + } + private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception { assertUDUPMessage( message, -- cgit v1.2.3 From f624f7350e0018060ad3f38be1c3988bc3fb0545 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 11 Jan 2020 12:19:53 +0100 Subject: Fix test --- src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java index bf6255e..a812e61 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java @@ -407,7 +407,6 @@ public class GossipGirlTest { gossipGirl.handleTyped(attributesMessage2); gossipGirl.handleTyped(queryMessage2); - assertTrue(false); } private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception { -- cgit v1.2.3