From 9325737ff613f7f14e44338b68ab657e0ed52d37 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 5 Jan 2020 15:24:36 +0100 Subject: Don't apply stale zone updates --- .../mimuw/cloudatlas/agent/modules/StanikTest.java | 76 +++++++++++++--------- 1 file changed, 46 insertions(+), 30 deletions(-) (limited to 'src/test/java/pl/edu/mimuw/cloudatlas') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java index 2e1ccea..ab13642 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java @@ -16,12 +16,15 @@ import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; import pl.edu.mimuw.cloudatlas.agent.MockExecutor; import pl.edu.mimuw.cloudatlas.model.Attribute; import pl.edu.mimuw.cloudatlas.model.AttributesMap; +import pl.edu.mimuw.cloudatlas.model.PathName; import pl.edu.mimuw.cloudatlas.model.TestUtil; import pl.edu.mimuw.cloudatlas.model.Value; +import pl.edu.mimuw.cloudatlas.model.ValueDuration; import pl.edu.mimuw.cloudatlas.model.ValueInt; import pl.edu.mimuw.cloudatlas.model.ValueQuery; import pl.edu.mimuw.cloudatlas.model.ValueString; import pl.edu.mimuw.cloudatlas.model.ValueTime; +import pl.edu.mimuw.cloudatlas.model.ValueUtils; import pl.edu.mimuw.cloudatlas.model.ZMI; import org.junit.Before; @@ -31,11 +34,13 @@ import static org.junit.Assert.*; public class StanikTest { private Stanik stanik; private MockExecutor executor; + private ValueTime testTime; @Before public void setupLocals() { stanik = new Stanik(); executor = new MockExecutor(stanik); + testTime = ValueUtils.currentTime(); } @Test @@ -78,14 +83,14 @@ public class StanikTest { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); attributes.add("bar", new ValueString("baz")); - attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/", attributes); stanik.handleTyped(message); AttributesMap actualAttributes = stanik.getHierarchy().getAttributes(); assertEquals(3, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(1337l), actualAttributes.get("foo")); assertEquals(new ValueString("baz"), actualAttributes.get("bar")); - assertEquals(new ValueTime("2012/12/21 04:20:00.000"), actualAttributes.getOrNull("timestamp")); + assertEquals(testTime, actualAttributes.getOrNull("timestamp")); } @Test @@ -94,7 +99,7 @@ public class StanikTest { attributes.add("foo", new ValueInt(1337l)); attributes.add("bar", new ValueString("baz")); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); @@ -102,7 +107,7 @@ public class StanikTest { assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo")); assertEquals(new ValueString("baz"), actualAttributes.getOrNull("bar")); assertEquals(new ValueString("new"), actualAttributes.getOrNull("name")); - assertEquals(new ValueTime("2012/12/21 04:20:00.000"), actualAttributes.getOrNull("timestamp")); + assertEquals(testTime, actualAttributes.getOrNull("timestamp")); } @Test @@ -111,11 +116,12 @@ public class StanikTest { attributes.add("foo", new ValueInt(1337l)); attributes.add("bar", new ValueString("baz")); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/", attributes); - attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("timestamp", testTime); stanik.handleTyped(message); AttributesMap newAttributes = new AttributesMap(); - newAttributes.add("timestamp", new ValueTime("2012/12/21 04:20:42.000")); + ValueTime newTime = (ValueTime) testTime.addValue(new ValueDuration(1l)); + newAttributes.add("timestamp", newTime); newAttributes.add("foo", new ValueInt(1338l)); UpdateAttributesMessage newMessage = new UpdateAttributesMessage("test_msg2", 0, "/", newAttributes); stanik.handleTyped(newMessage); @@ -123,27 +129,40 @@ public class StanikTest { AttributesMap actualAttributes = stanik.getHierarchy().getAttributes(); assertEquals(2, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(1338l), actualAttributes.getOrNull("foo")); - assertEquals(new ValueTime("2012/12/21 04:20:42.000"), actualAttributes.getOrNull("timestamp")); + assertEquals(newTime, actualAttributes.getOrNull("timestamp")); } @Test public void dontApplyUpdateWithOlderTimestamp() throws Exception { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); - attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/", attributes); stanik.handleTyped(message); AttributesMap oldAttributes = new AttributesMap(); oldAttributes.add("foo", new ValueInt(1336l)); - oldAttributes.add("timestamp", new ValueTime("2012/12/21 04:19:00.000")); + ValueTime olderTime = (ValueTime) testTime.subtract(new ValueDuration(1l)); + oldAttributes.add("timestamp", olderTime); UpdateAttributesMessage newMessage = new UpdateAttributesMessage("test_msg2", 0, "/", oldAttributes); stanik.handleTyped(newMessage); AttributesMap actualAttributes = stanik.getHierarchy().getAttributes(); assertEquals(2, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo")); - assertEquals(new ValueTime("2012/12/21 04:20:00.000"), actualAttributes.getOrNull("timestamp")); + assertEquals(testTime, actualAttributes.getOrNull("timestamp")); + } + + @Test + public void dontApplyWithStaleTimestamp() throws Exception { + AttributesMap attributes = new AttributesMap(); + attributes.add("foo", new ValueInt(1337l)); + attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("name", new ValueString("new")); + UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); + stanik.handleTyped(message); + + assertFalse(stanik.getHierarchy().descendantExists(new PathName("/new"))); } @Test @@ -207,19 +226,14 @@ public class StanikTest { attributes.add("foo", new ValueInt(1337l)); attributes.add("bar", new ValueString("baz")); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime(42l)); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); - RemoveZMIMessage removeMessage = new RemoveZMIMessage("test_msg2", 0, "/new", new ValueTime(43l)); + RemoveZMIMessage removeMessage = new RemoveZMIMessage("test_msg2", 0, "/new", (ValueTime) testTime.addValue(new ValueDuration(1l))); stanik.handleTyped(removeMessage); - boolean noSuchZone = false; - try { - stanik.getHierarchy().findDescendant("/new"); - } catch (ZMI.NoSuchZoneException e) { - noSuchZone = true; - } - assertTrue(noSuchZone); + + assertFalse(stanik.getHierarchy().descendantExists(new PathName("/new"))); } @Test @@ -228,11 +242,11 @@ public class StanikTest { attributes.add("foo", new ValueInt(1337l)); attributes.add("bar", new ValueString("baz")); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime(42l)); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); - RemoveZMIMessage removeMessage = new RemoveZMIMessage("test_msg2", 0, "/new", new ValueTime(41l)); + RemoveZMIMessage removeMessage = new RemoveZMIMessage("test_msg2", 0, "/new", (ValueTime) testTime.subtract(new ValueDuration(1l))); stanik.handleTyped(removeMessage); stanik.getHierarchy().findDescendant("/new"); @@ -243,17 +257,17 @@ public class StanikTest { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime(42l)); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); - SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), new ValueTime(40l)); + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), (ValueTime) testTime.subtract(new ValueDuration(1l))); stanik.handleTyped(setMessage); AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); assertEquals(3, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(43l), actualAttributes.getOrNull("foo")); - assertEquals(new ValueTime(42l), actualAttributes.getOrNull("timestamp")); + assertEquals(testTime, actualAttributes.getOrNull("timestamp")); } @Test @@ -261,17 +275,18 @@ public class StanikTest { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime(42l)); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); - SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), new ValueTime(43l)); + ValueTime newTime = (ValueTime) testTime.addValue(new ValueDuration(1l)); + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), newTime); stanik.handleTyped(setMessage); AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); assertEquals(3, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(43l), actualAttributes.getOrNull("foo")); - assertEquals(new ValueTime(43l), actualAttributes.getOrNull("timestamp")); + assertEquals(newTime, actualAttributes.getOrNull("timestamp")); } @Test @@ -279,17 +294,18 @@ public class StanikTest { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); attributes.add("name", new ValueString("new")); - attributes.add("timestamp", new ValueTime(42l)); + attributes.add("timestamp", testTime); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); - SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("bar"), new ValueInt(43l), new ValueTime(43l)); + ValueTime newTime = (ValueTime) testTime.addValue(new ValueDuration(1l)); + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("bar"), new ValueInt(43l), newTime); stanik.handleTyped(setMessage); AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); assertEquals(4, TestUtil.iterableSize(actualAttributes)); assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo")); assertEquals(new ValueInt(43l), actualAttributes.getOrNull("bar")); - assertEquals(new ValueTime(43l), actualAttributes.getOrNull("timestamp")); + assertEquals(newTime, actualAttributes.getOrNull("timestamp")); } } -- cgit v1.2.3 From 89a5d7b00f71a5be805ecc7e7907e5b0c88c5f03 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 5 Jan 2020 19:33:37 +0100 Subject: Fix tests --- src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java | 3 ++- .../java/pl/edu/mimuw/cloudatlas/agent/ApiImplementationTests.java | 3 ++- src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/test/java/pl/edu/mimuw/cloudatlas') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java index 28b47a9..e4684cd 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java @@ -95,7 +95,8 @@ public class AgentIntegrationTest { assertEquals(new ValueInt(2l), attributes.get("level")); assertEquals(new ValueString("whatever01"), attributes.get("name")); assertEquals(new ValueString("/pjwstk/whatever01"), attributes.get("owner")); - assertEquals(new ValueTime("2012/11/09 21:12:00.000"), attributes.get("timestamp")); + long timestamp = ((ValueTime) attributes.get("timestamp")).getValue(); + assertTrue(timestamp <= System.currentTimeMillis()); assertEquals(new ValueInt(1l), attributes.get("cardinality")); assertEquals(new ValueTime("2012/10/18 07:03:00.000"), attributes.get("creation")); assertEquals(new ValueDouble(0.1), attributes.get("cpu_usage")); diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementationTests.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementationTests.java index 0a7a8df..002c43c 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementationTests.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementationTests.java @@ -63,7 +63,8 @@ public class ApiImplementationTests { assertEquals(new ValueInt(2l), attributes.get("level")); assertEquals(new ValueString("whatever01"), attributes.get("name")); assertEquals(new ValueString("/pjwstk/whatever01"), attributes.get("owner")); - assertEquals(new ValueTime("2012/11/09 21:12:00.000"), attributes.get("timestamp")); + long timestamp = ((ValueTime) attributes.get("timestamp")).getValue(); + assertTrue(timestamp <= System.currentTimeMillis()); assertEquals(new ValueInt(1l), attributes.get("cardinality")); assertEquals(new ValueTime("2012/10/18 07:03:00.000"), attributes.get("creation")); assertEquals(new ValueDouble(0.1), attributes.get("cpu_usage")); diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java index ab13642..1ca8608 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java @@ -157,7 +157,7 @@ public class StanikTest { public void dontApplyWithStaleTimestamp() throws Exception { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); - attributes.add("timestamp", new ValueTime("2012/12/21 04:20:00.000")); + attributes.add("timestamp", (ValueTime) testTime.subtract(new ValueDuration(61 * 1000l))); attributes.add("name", new ValueString("new")); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); -- cgit v1.2.3 From 88cc1f5da8ded831b15f4970e8877494d449a471 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 6 Jan 2020 12:02:46 +0100 Subject: Prune hierarchy of stale zones on read --- .../mimuw/cloudatlas/agent/modules/StanikTest.java | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/test/java/pl/edu/mimuw/cloudatlas') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java index 1ca8608..f3ea0b0 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java @@ -35,10 +35,11 @@ public class StanikTest { private Stanik stanik; private MockExecutor executor; private ValueTime testTime; + private static final long freshnessPeriod = 1000; @Before public void setupLocals() { - stanik = new Stanik(); + stanik = new Stanik(freshnessPeriod); executor = new MockExecutor(stanik); testTime = ValueUtils.currentTime(); } @@ -157,7 +158,7 @@ public class StanikTest { public void dontApplyWithStaleTimestamp() throws Exception { AttributesMap attributes = new AttributesMap(); attributes.add("foo", new ValueInt(1337l)); - attributes.add("timestamp", (ValueTime) testTime.subtract(new ValueDuration(61 * 1000l))); + attributes.add("timestamp", (ValueTime) testTime.subtract(new ValueDuration(freshnessPeriod + 100))); attributes.add("name", new ValueString("new")); UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); stanik.handleTyped(message); @@ -165,6 +166,30 @@ public class StanikTest { assertFalse(stanik.getHierarchy().descendantExists(new PathName("/new"))); } + @Test + public void zoneRemovedAfterFreshnessPeriod() throws Exception { + AttributesMap attributes = new AttributesMap(); + attributes.add("foo", new ValueInt(1337l)); + attributes.add("timestamp", testTime); + attributes.add("name", new ValueString("new")); + UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); + stanik.handleTyped(message); + Thread.sleep(freshnessPeriod + 100); + + AttributesMap attributes2 = new AttributesMap(); + attributes2.add("timestamp", ValueUtils.currentTime()); + UpdateAttributesMessage message2 = new UpdateAttributesMessage("test_msg", 0, "/", attributes2); + stanik.handleTyped(message2); + + GetStateMessage getStateMessage = new GetStateMessage("", 0, ModuleType.TEST, 0); + stanik.handleTyped(getStateMessage); + + StateMessage newReceivedMessage = (StateMessage) executor.messagesToPass.poll(); + assertNotNull(newReceivedMessage); + assertFalse(newReceivedMessage.getZMI().descendantExists(new PathName("/new"))); + assertFalse(stanik.getHierarchy().descendantExists(new PathName("/new"))); + } + @Test public void addQuery() throws Exception { HashMap> queries = new HashMap>(); -- cgit v1.2.3 From 8a44299b0072a8bedd1c0d74f92d258379c8447a Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 6 Jan 2020 12:57:33 +0100 Subject: Increase freshness threshold in tests --- src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java | 2 +- src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/java/pl/edu/mimuw/cloudatlas') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java index e4684cd..f69ed8f 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/AgentIntegrationTest.java @@ -47,7 +47,7 @@ public class AgentIntegrationTest { public static void bindApi() throws Exception { registryProcess = Runtime.getRuntime().exec("./scripts/registry"); Thread.sleep(10000); - agentProcess = Runtime.getRuntime().exec("./gradlew runAgent -Dhostname=localhost"); + agentProcess = Runtime.getRuntime().exec("./gradlew runAgent -Dhostname=localhost -DfreshnessPeriod=10000000"); Thread.sleep(10000); registry = LocateRegistry.getRegistry("localhost"); diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java index 431122b..2bd63f6 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java @@ -37,7 +37,7 @@ public class ClientTest { public static void bindApi() throws Exception { registryProcess = Runtime.getRuntime().exec("./scripts/registry"); Thread.sleep(10000); - agentProcess = Runtime.getRuntime().exec("./gradlew runAgent -Dhostname=localhost"); + agentProcess = Runtime.getRuntime().exec("./gradlew runAgent -Dhostname=localhost -DfreshnessPeriod=10000000"); Thread.sleep(10000); registry = LocateRegistry.getRegistry("localhost"); -- cgit v1.2.3