diff options
9 files changed, 158 insertions, 51 deletions
diff --git a/build.gradle b/build.gradle index 9ef400c..01e8685 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,10 @@ ext.hostname = { return System.getProperty("hostname") ?: "localhost" } +ext.freshnessPeriod = { + return System.getProperty("freshnessPeriod") ?: 60 * 1000 +} + repositories { // Use jcenter for resolving dependencies. // You can declare any Maven/Ivy/file repository here. @@ -56,6 +60,7 @@ task runAgent(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath main = 'pl.edu.mimuw.cloudatlas.agent.Agent' systemProperty 'java.rmi.server.hostname', hostname() + systemProperty 'freshness_period', freshnessPeriod() } task runClient(type: JavaExec) { diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java index ef4f48d..256fa6b 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -43,7 +43,8 @@ public class Agent { HashMap<ModuleType, Module> modules = new HashMap<ModuleType, Module>(); modules.put(ModuleType.TIMER_SCHEDULER, new TimerScheduler(ModuleType.TIMER_SCHEDULER)); modules.put(ModuleType.RMI, new Remik()); - modules.put(ModuleType.STATE, new Stanik()); + Long freshnessPeriod = new Long(System.getProperty("freshness_period")); + modules.put(ModuleType.STATE, new Stanik(freshnessPeriod)); modules.put(ModuleType.QUERY, new Qurnik()); try { modules.put(ModuleType.UDP, new UDUP(InetAddress.getByName("127.0.0.1"), 5988, 5000, 20000)); diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java index 3e5b790..6761c94 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java @@ -1,6 +1,8 @@ package pl.edu.mimuw.cloudatlas.agent.modules; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map.Entry; import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; @@ -19,6 +21,7 @@ import pl.edu.mimuw.cloudatlas.model.Type; import pl.edu.mimuw.cloudatlas.model.TypePrimitive; import pl.edu.mimuw.cloudatlas.model.Value; import pl.edu.mimuw.cloudatlas.model.ValueBoolean; +import pl.edu.mimuw.cloudatlas.model.ValueDuration; import pl.edu.mimuw.cloudatlas.model.ValueQuery; import pl.edu.mimuw.cloudatlas.model.ValueString; import pl.edu.mimuw.cloudatlas.model.ValueTime; @@ -34,12 +37,18 @@ public class Stanik extends Module { private ZMI hierarchy; private HashMap<Attribute, Entry<ValueQuery, ValueTime>> queries; + private long freshnessPeriod; - public Stanik() { + public Stanik(long freshnessPeriod) { super(ModuleType.STATE); hierarchy = new ZMI(); queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>(); hierarchy.getAttributes().add("timestamp", new ValueTime(0l)); + this.freshnessPeriod = freshnessPeriod; + } + + public Stanik() { + this(60 * 1000); } public void handleTyped(StanikMessage message) throws InterruptedException, InvalidMessageType { @@ -65,6 +74,7 @@ public class Stanik extends Module { } public void handleGetState(GetStateMessage message) throws InterruptedException { + pruneHierarchy(); StateMessage response = new StateMessage( "", message.getRequestingModule(), @@ -76,6 +86,40 @@ public class Stanik extends Module { sendMessage(response); } + private void pruneHierarchy() { + ValueTime now = ValueUtils.currentTime(); + pruneZMI(hierarchy, now); + } + + private boolean pruneZMI(ZMI zmi, ValueTime time) { + Value timestamp = zmi.getAttributes().get("timestamp"); + + boolean isLeaf = zmi.getSons().isEmpty(); + + List<ZMI> sonsToRemove = new LinkedList(); + if (ValueUtils.valueLower(timestamp, time.subtract(new ValueDuration(freshnessPeriod)))) { + if (zmi.getFather() != null) { + return true; + } + } else { + for (ZMI son : zmi.getSons()) { + if (pruneZMI(son, time)) { + sonsToRemove.add(son); + } + } + } + + for (ZMI son : sonsToRemove) { + zmi.removeSon(son); + } + + if (!isLeaf && zmi.getSons().isEmpty()) { + return true; + } + + return false; + } + public void handleRemoveZMI(RemoveZMIMessage message) { try { ZMI zmi = hierarchy.findDescendant(new PathName(message.getPathName())); @@ -113,13 +157,20 @@ public class Stanik extends Module { public void handleUpdateAttributes(UpdateAttributesMessage message) { try { validateUpdateAttributesMessage(message); - addMissingZones(new PathName(message.getPathName())); - ZMI zone = hierarchy.findDescendant(message.getPathName()); - AttributesMap attributes = zone.getAttributes(); - if (ValueUtils.valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) { - AttributesUtil.transferAttributes(message.getAttributes(), attributes); + if (!ValueUtils.valueLower( + message.getAttributes().get("timestamp"), + new ValueTime(System.currentTimeMillis() - freshnessPeriod) + )) { + addMissingZones(new PathName(message.getPathName())); + ZMI zone = hierarchy.findDescendant(message.getPathName()); + AttributesMap attributes = zone.getAttributes(); + if (ValueUtils.valueLower(attributes.get("timestamp"), message.getAttributes().get("timestamp"))) { + AttributesUtil.transferAttributes(message.getAttributes(), attributes); + } else { + System.out.println("DEBUG: not applying update with older attributes"); + } } else { - System.out.println("DEBUG: not applying update with older attributes"); + System.out.println("DEBUG: not applying update with stale attributes"); } } catch (InvalidUpdateAttributesMessage e) { System.out.println("ERROR: invalid UpdateAttributesMessage " + e.getMessage()); diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java index 1e0bb4f..7419ad4 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Main.java @@ -50,6 +50,7 @@ import pl.edu.mimuw.cloudatlas.model.ValueList; import pl.edu.mimuw.cloudatlas.model.ValueSet; 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; public class Main { @@ -274,29 +275,31 @@ public class Main { List<Value> list; + ValueTime time = ValueUtils.currentTime(); + ZMI root = new ZMI(); root.getAttributes().add("level", new ValueInt(0l)); root.getAttributes().add("name", new ValueString(null)); - root.getAttributes().add("timestamp", new ValueTime(10l)); + root.getAttributes().add("timestamp", time); ZMI uw = new ZMI(root); root.addSon(uw); uw.getAttributes().add("level", new ValueInt(1l)); uw.getAttributes().add("name", new ValueString("uw")); - uw.getAttributes().add("timestamp", new ValueTime(10l)); + uw.getAttributes().add("timestamp", time); ZMI pjwstk = new ZMI(root); root.addSon(pjwstk); pjwstk.getAttributes().add("level", new ValueInt(1l)); pjwstk.getAttributes().add("name", new ValueString("pjwstk")); - pjwstk.getAttributes().add("timestamp", new ValueTime(10l)); + pjwstk.getAttributes().add("timestamp", time); ZMI violet07 = new ZMI(uw); uw.addSon(violet07); violet07.getAttributes().add("level", new ValueInt(2l)); violet07.getAttributes().add("name", new ValueString("violet07")); violet07.getAttributes().add("owner", new ValueString("/uw/violet07")); - violet07.getAttributes().add("timestamp", new ValueTime("2012/11/09 18:00:00.000")); + violet07.getAttributes().add("timestamp", time); list = Arrays.asList(new Value[] { violet07Contact, khaki31Contact, khaki13Contact }); @@ -322,7 +325,7 @@ public class Main { khaki31.getAttributes().add("level", new ValueInt(2l)); khaki31.getAttributes().add("name", new ValueString("khaki31")); khaki31.getAttributes().add("owner", new ValueString("/uw/khaki31")); - khaki31.getAttributes().add("timestamp", new ValueTime("2012/11/09 20:03:00.000")); + khaki31.getAttributes().add("timestamp", time); list = Arrays.asList(new Value[] { violet08Contact }); @@ -348,7 +351,7 @@ public class Main { khaki13.getAttributes().add("level", new ValueInt(2l)); khaki13.getAttributes().add("name", new ValueString("khaki13")); khaki13.getAttributes().add("owner", new ValueString("/uw/khaki13")); - khaki13.getAttributes().add("timestamp", new ValueTime("2012/11/09 21:03:00.000")); + khaki13.getAttributes().add("timestamp", time); list = Arrays.asList(new Value[] { khaki14Contact, khaki32Contact }); @@ -372,7 +375,7 @@ public class Main { whatever01.getAttributes().add("level", new ValueInt(2l)); whatever01.getAttributes().add("name", new ValueString("whatever01")); whatever01.getAttributes().add("owner", new ValueString("/pjwstk/whatever01")); - whatever01.getAttributes().add("timestamp", new ValueTime("2012/11/09 21:12:00.000")); + whatever01.getAttributes().add("timestamp", time); list = Arrays.asList(new Value[] { whatever02Contact, }); @@ -396,7 +399,7 @@ public class Main { whatever02.getAttributes().add("level", new ValueInt(2l)); whatever02.getAttributes().add("name", new ValueString("whatever02")); whatever02.getAttributes().add("owner", new ValueString("/pjwstk/whatever02")); - whatever02.getAttributes().add("timestamp", new ValueTime("2012/11/09 21:13:00.000")); + whatever02.getAttributes().add("timestamp", time); list = Arrays.asList(new Value[] { whatever01Contact, }); diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java index 02b2ce4..3df8231 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java @@ -8,4 +8,8 @@ public class ValueUtils { public static boolean valueLower(Value a, Value b) { return ((ValueBoolean) a.isLowerThan(b)).getValue(); } + + public static ValueTime currentTime() { + return new ValueTime(System.currentTimeMillis()); + } } 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..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"); @@ -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 2e1ccea..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 @@ -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,14 @@ import static org.junit.Assert.*; 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(); } @Test @@ -78,14 +84,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 +100,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 +108,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 +117,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 +130,64 @@ 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", (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); + + 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 @@ -207,19 +251,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 +267,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 +282,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 +300,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 +319,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")); } } 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"); |