Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #66 #73

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ public void didClose() {
.keyClass(String.class)
.valueClass(String.class)
.hostUri("warp://localhost:53556/")
.nodeUri("/join/map/all")
.nodeUri("/join/mapA/all")
.laneUri("join")
.observe(new JoinMapLinkController())
.open();

joinDidReceive.await(1, TimeUnit.SECONDS);
joinDidUpdate.await(1, TimeUnit.SECONDS);
joinDidReceive.await(3, TimeUnit.SECONDS);
joinDidUpdate.await(3, TimeUnit.SECONDS);
assertEquals(joinDidReceive.getCount(), 0);
assertEquals(joinDidUpdate.getCount(), 0);
assertEquals(join.size(), 4);
Expand All @@ -179,6 +179,63 @@ public void didClose() {
}
}

private static CountDownLatch laneWillDownlink = new CountDownLatch(2);
private static CountDownLatch laneDidDownlink = new CountDownLatch(2);
private static CountDownLatch laneWillUpdate = new CountDownLatch(4);
private static CountDownLatch laneDidUpdate0 = new CountDownLatch(2);
private static CountDownLatch laneDidUpdate1 = new CountDownLatch(2);
private static CountDownLatch laneWillRemove = new CountDownLatch(1);
private static CountDownLatch laneDidRemove = new CountDownLatch(1);

@Test
public void testJoinMapLaneCallback() throws InterruptedException {
final Kernel kernel = ServerLoader.loadServerStack();
final TestJoinMapPlane plane = kernel.openSpace(ActorSpaceDef.fromName("test"))
.openPlane("test", TestJoinMapPlane.class);

try {
kernel.openService(WebServiceDef.standard().port(53556).spaceName("test"));
kernel.start();
final MapDownlink<String, String> xs = plane.downlinkMap()
.keyClass(String.class)
.valueClass(String.class)
.hostUri("warp://localhost:53556/")
.nodeUri("/map/xs")
.laneUri("map")
.open();
xs.didSync(() -> {
xs.put("x0", "a");
xs.put("x1", "b");
});

final MapDownlink<String, String> join = plane.downlinkMap()
.keyClass(String.class)
.valueClass(String.class)
.hostUri("warp://localhost:53556/")
.nodeUri("/join/mapB/all")
.laneUri("join")
.open();

laneDidUpdate0.await(3, TimeUnit.SECONDS);
assertEquals(laneWillDownlink.getCount(), 0);
assertEquals(laneDidDownlink.getCount(), 0);
assertEquals(laneWillUpdate.getCount(), 2);
assertEquals(laneDidUpdate0.getCount(), 0);

xs.put("x0", "aa");
xs.put("x1", "bb");

laneDidUpdate1.await(3, TimeUnit.SECONDS);
assertEquals(laneWillDownlink.getCount(), 0);
assertEquals(laneDidDownlink.getCount(), 0);
assertEquals(laneWillUpdate.getCount(), 0);
assertEquals(laneDidUpdate1.getCount(), 0);

} finally {
kernel.stop();
}
}

static class TestMapLaneAgent extends AbstractAgent {

@SwimLane("map")
Expand Down Expand Up @@ -213,7 +270,20 @@ public void didRemove(String key, String oldValue) {

}

static class TestJoinMapLaneAgent extends AbstractAgent {
static class TestJoinMapLaneAgentA extends AbstractAgent {

@SwimLane("join")
JoinMapLane<String, String, String> testJoinMap = this.<String, String, String>joinMapLane();

@Override
public void didStart() {
this.testJoinMap.downlink("xs").hostUri("warp://localhost:53556").nodeUri("/map/xs").laneUri("map").open();
this.testJoinMap.downlink("ys").hostUri("warp://localhost:53556").nodeUri("/map/ys").laneUri("map").open();
}

}

static class TestJoinMapLaneAgentB extends AbstractAgent {

@SwimLane("join")
JoinMapLane<String, String, String> testJoinMap = this.<String, String, String>joinMapLane()
Expand All @@ -232,33 +302,51 @@ class TestJoinMapLaneController implements WillDownlinkMap<String>, DidDownlinkM
@Override
public MapDownlink<?, ?> willDownlink(String key, MapDownlink<?, ?> downlink) {
System.out.println(nodeUri() + " willDownlink key: " + Format.debug(key) + "; downlink: " + downlink);
laneWillDownlink.countDown();
return downlink;
}

@Override
public void didDownlink(String key, MapDownlink<?, ?> downlink) {
System.out.println(nodeUri() + " didDownlink key: " + Format.debug(key) + "; downlink: " + downlink);
laneDidDownlink.countDown();
}

@Override
public String willUpdate(String key, String newValue) {
System.out.println(nodeUri() + " willUpdate key: " + Format.debug(key) + "; newValue: " + Format.debug(newValue));
laneWillUpdate.countDown();
return newValue;
}

@Override
public void didUpdate(String key, String newValue, String oldValue) {
System.out.println(nodeUri() + " didUpdate key: " + Format.debug(key) + "; newValue: " + Format.debug(newValue) + "; oldValue: " + Format.debug(oldValue));
if (key.equals("x0") && newValue.equals("a")) {
//assertEquals(oldValue, "");
laneDidUpdate0.countDown();
} else if (key.equals("x0") && newValue.equals("aa")) {
assertEquals(oldValue, "a");
laneDidUpdate1.countDown();
} else if (key.equals("x1") && newValue.equals("b")) {
assertEquals(oldValue, "");
laneDidUpdate0.countDown();
} else if (key.equals("x1") && newValue.equals("bb")) {
//assertEquals(oldValue, "b");
laneDidUpdate1.countDown();
}
}

@Override
public void willRemove(String key) {
System.out.println(nodeUri() + " willRemove key: " + Format.debug(key));
laneWillRemove.countDown();
}

@Override
public void didRemove(String key, String oldValue) {
System.out.println(nodeUri() + " didRemove key: " + Format.debug(key) + "; oldValue: " + Format.debug(oldValue));
laneDidRemove.countDown();
}

}
Expand All @@ -270,8 +358,11 @@ static class TestJoinMapPlane extends AbstractPlane {
@SwimRoute("/map/:name")
AgentRoute<TestMapLaneAgent> mapRoute;

@SwimRoute("/join/map/:name")
AgentRoute<TestJoinMapLaneAgent> joinMapRoute;
@SwimRoute("/join/mapA/:name")
AgentRoute<TestJoinMapLaneAgentA> joinMapA;

@SwimRoute("/join/mapB/:name")
AgentRoute<TestJoinMapLaneAgentB> joinMapB;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ protected void beginPhase(int phase) {
if (this.oldValue == null) {
this.oldValue = Value.absent();
}

if (this.valueForm != null) {
this.oldObject = this.valueForm.cast(this.oldValue);
if (this.oldObject == null) {
this.oldObject = this.valueForm.unit();
}
}

}
}

Expand Down