use of net.dempsy.router.shardutils.Utils in project Dempsy by Dempsy.
the class TestManagedRoutingStrategy method testInboundWithOutbound.
@Test
public void testInboundWithOutbound() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
final ClusterId cid = setTestName("testInboundWithOutbound");
final ContainerAddress oca = new ContainerAddress(new DummyNodeAddress("here"), 0);
final Infrastructure infra = makeInfra(session, sched);
final Utils<ContainerAddress> msutils = new Utils<>(infra, cid.clusterName, oca);
ib.setContainerDetails(cid, oca, (l, m) -> {
});
ib.start(infra);
checkForShardDistribution(session, msutils, numShardsToExpect, 1);
try (final ClusterInfoSession ses2 = sessFact.createSession();
final RoutingStrategyManager obman = chain(new RoutingStrategyManager(), o -> o.start(makeInfra(ses2, sched)));
final RoutingStrategy.Factory obf = obman.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
obf.start(makeInfra(ses2, sched));
assertTrue(poll(o -> obf.isReady()));
final RoutingStrategy.Router ob = obf.getStrategy(cid);
assertTrue(poll(o -> obf.isReady()));
final KeyedMessageWithType km = new KeyedMessageWithType(new Object(), new Object(), "");
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
final ContainerAddress ca = ob.selectDestinationForMessage(km);
assertNotNull(ca);
assertEquals("here", ((DummyNodeAddress) ca.node).name);
// now disrupt the session
session.close();
try (ClusterInfoSession ses3 = sessFact.createSession();
RoutingStrategy.Inbound ib2 = manager.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
ib2.setContainerDetails(cid, ca, (l, m) -> {
});
ib2.start(makeInfra(ses3, sched));
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
}
}
}
}
use of net.dempsy.router.shardutils.Utils in project Dempsy by Dempsy.
the class TestManagedRoutingStrategy method testInboundDoubleHappyPathRegister.
@Test
public void testInboundDoubleHappyPathRegister() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
try (final RoutingStrategy.Inbound ib1 = new Manager<>(RoutingStrategy.Inbound.class).getAssociatedInstance(ManagedInbound.class.getPackage().getName());
final RoutingStrategy.Inbound ib2 = new Manager<>(RoutingStrategy.Inbound.class).getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
final ClusterId clusterId = new ClusterId("test", "test");
final ContainerAddress node1Ca = new ContainerAddress(new DummyNodeAddress("node1"), 0);
final Utils<ContainerAddress> utils = new Utils<>(infra, clusterId.clusterName, node1Ca);
ib1.setContainerDetails(clusterId, node1Ca, (l, m) -> {
});
ib1.start(infra);
final ContainerAddress node2Ca = new ContainerAddress(new DummyNodeAddress("node2"), 0);
ib2.setContainerDetails(clusterId, node2Ca, (l, m) -> {
});
try (final ClusterInfoSession session2 = sessFact.createSession()) {
ib2.start(new TestInfrastructure(session2, infra.getScheduler()));
assertTrue(waitForShards(session, utils, numShardsToExpect));
// if this worked right then numShardsToExpect/2 should be owned by each ... eventually.
checkForShardDistribution(session, utils, numShardsToExpect, 2);
// disrupt the session. This should cause a reshuffle but not fail
disruptor.accept(session2);
// everything should settle back
checkForShardDistribution(session, utils, numShardsToExpect, 2);
// now kill the second session.
// this will disconnect the second Inbound and so the first should take over
session2.close();
// see if we now have 1 session and it has all shards
checkForShardDistribution(session, utils, numShardsToExpect, 1);
}
}
}
use of net.dempsy.router.shardutils.Utils in project Dempsy by Dempsy.
the class TestManagedRoutingStrategy method testInboundResillience.
@Test
public void testInboundResillience() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
final ClusterId clusterId = super.setTestName("testInboundResillience");
final ContainerAddress ca = new ContainerAddress(new DummyNodeAddress("theOnlyNode"), 0);
final Infrastructure infra = makeInfra(session, sched);
final Utils<ContainerAddress> msutils = new Utils<>(infra, clusterId.clusterName, ca);
ib.setContainerDetails(clusterId, ca, (l, m) -> {
});
ib.start(infra);
checkForShardDistribution(session, msutils, numShardsToExpect, 1);
disruptor.accept(session);
checkForShardDistribution(session, msutils, numShardsToExpect, 1);
}
}
use of net.dempsy.router.shardutils.Utils in project Dempsy by Dempsy.
the class TestGroupRoutingStrategy method testInboundDoubleHappyPathRegister.
@Test
public void testInboundDoubleHappyPathRegister() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final String groupName = "testInboundDoubleHappyPathRegister";
try (final RoutingStrategy.Inbound ib1 = new RoutingInboundManager().getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName);
final RoutingStrategy.Inbound ib2 = new RoutingInboundManager().getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
final ClusterId clusterId = new ClusterId("test", "test");
final NodeAddress node1Addr = new DummyNodeAddress("node1");
final GroupDetails gd1 = new GroupDetails(groupName, node1Addr);
final ContainerAddress node1Ca = new ContainerAddress(node1Addr, 0);
final Utils<GroupDetails> utils = new Utils<>(infra, groupName, gd1);
ib1.setContainerDetails(clusterId, node1Ca, (l, m) -> {
});
ib1.start(infra);
final NodeAddress node2Addr = new DummyNodeAddress("node2");
final ContainerAddress node2Ca = new ContainerAddress(node2Addr, 0);
ib2.setContainerDetails(clusterId, node2Ca, (l, m) -> {
});
try (final ClusterInfoSession session2 = sessFact.createSession()) {
ib2.start(new TestInfrastructure(session2, infra.getScheduler()));
assertTrue(waitForShards(session, utils, numShardsToExpect));
// if this worked right then numShardsToExpect/2 should be owned by each ... eventually.
checkForShardDistribution(session, utils, numShardsToExpect, 2);
// disrupt the session. This should cause a reshuffle but not fail
disruptor.accept(session2);
// everything should settle back
checkForShardDistribution(session, utils, numShardsToExpect, 2);
// now kill the second session.
// this will disconnect the second Inbound and so the first should take over
session2.close();
// see if we now have 1 session and it has all shards
checkForShardDistribution(session, utils, numShardsToExpect, 1);
}
}
}
use of net.dempsy.router.shardutils.Utils in project Dempsy by Dempsy.
the class TestGroupRoutingStrategy method testInboundWithOutbound.
@Test
public void testInboundWithOutbound() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final String groupName = "testInboundWithOutbound";
final Manager<RoutingStrategy.Inbound> manager = new RoutingInboundManager();
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
final ClusterId cid = setTestName("testInboundWithOutbound");
final NodeAddress na = new DummyNodeAddress("here");
final ContainerAddress oca = new ContainerAddress(na, 0);
final Infrastructure infra = makeInfra(session, sched);
final GroupDetails ogd = new GroupDetails(groupName, na);
final Map<String, ContainerAddress> ocaiByCluster = new HashMap<>();
ocaiByCluster.put(cid.clusterName, oca);
ogd.fillout(ocaiByCluster);
final Utils<GroupDetails> msutils = new Utils<>(infra, groupName, ogd);
ib.setContainerDetails(cid, oca, (l, m) -> {
});
ib.start(infra);
checkForShardDistribution(session, msutils, numShardsToExpect, 1);
try (final ClusterInfoSession ses2 = sessFact.createSession();
final RoutingStrategyManager obman = chain(new RoutingStrategyManager(), o -> o.start(makeInfra(ses2, sched)));
final RoutingStrategy.Factory obf = obman.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
obf.start(makeInfra(ses2, sched));
assertTrue(poll(o -> obf.isReady()));
final RoutingStrategy.Router ob = obf.getStrategy(cid);
assertTrue(poll(o -> obf.isReady()));
final KeyedMessageWithType km = new KeyedMessageWithType(new Object(), new Object(), "");
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
final ContainerAddress ca = ob.selectDestinationForMessage(km);
assertNotNull(ca);
assertEquals("here", ((DummyNodeAddress) ca.node).name);
// now disrupt the session
session.close();
// the destination should clear until a new one runs
// NO: destination will not necessarily clear.
// poll(o -> ob.selectDestinationForMessage(km) == null);
final ContainerAddress nca = new ContainerAddress(new DummyNodeAddress("here-again"), 0);
ogd.fillout(ocaiByCluster);
try (ClusterInfoSession ses3 = sessFact.createSession();
RoutingStrategy.Inbound ib2 = new RoutingInboundManager().getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
ib2.setContainerDetails(cid, nca, (l, m) -> {
});
ib2.start(makeInfra(ses3, sched));
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
}
}
}
}
Aggregations