use of net.dempsy.router.RoutingStrategy.ContainerAddress in project Dempsy by Dempsy.
the class TestSimpleRoutingStrategy method testInboundWithOutbound.
@Test
public void testInboundWithOutbound() throws Exception {
final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
assertNotNull(ib);
assertTrue(SimpleInboundSide.class.isAssignableFrom(ib.getClass()));
final ClusterId cid = new ClusterId("test", "test");
ib.setContainerDetails(cid, new ContainerAddress(new DummyNodeAddress("here"), 0), (l, m) -> {
});
ib.start(infra);
assertTrue(waitForReg(session));
try (final ClusterInfoSession ses2 = sessFact.createSession()) {
try (final RoutingStrategyManager obman = chain(new RoutingStrategyManager(), o -> o.start(makeInfra(ses2, sched)));
final RoutingStrategy.Factory obf = obman.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
obf.start(makeInfra(ses2, sched));
final RoutingStrategy.Router ob = obf.getStrategy(cid);
final KeyedMessageWithType km = new KeyedMessageWithType(null, null, "");
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
final ContainerAddress ca = ob.selectDestinationForMessage(km);
assertNotNull(ca);
assertEquals("here", ((DummyNodeAddress) ca.node).name);
// now distupt the session
session.close();
// the destination should clear until a new in runs
assertTrue(poll(o -> ob.selectDestinationForMessage(km) == null));
try (ClusterInfoSession ses3 = sessFact.createSession();
RoutingStrategy.Inbound ib2 = manager.getAssociatedInstance(SimpleRoutingStrategy.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.RoutingStrategy.ContainerAddress in project Dempsy by Dempsy.
the class TestGroupRoutingStrategy method testInboundSimpleHappyPathRegister.
@Test
public void testInboundSimpleHappyPathRegister() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final RoutingInboundManager manager = new RoutingInboundManager();
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":testInboundSimpleHappyPathRegister")) {
final Utils<Object> msutils = new Utils<>(infra, "testInboundSimpleHappyPathRegister", new Object());
assertNotNull(ib);
assertTrue(ClusterGroupInbound.Proxy.class.isAssignableFrom(ib.getClass()));
ib.setContainerDetails(new ClusterId("test", "test"), new ContainerAddress(new DummyNodeAddress("testInboundSimpleHappyPathRegister"), 0), (l, m) -> {
});
ib.start(infra);
assertTrue(waitForShards(session, msutils, numShardsToExpect));
}
}
use of net.dempsy.router.RoutingStrategy.ContainerAddress in project Dempsy by Dempsy.
the class TestGroupRoutingStrategy method testInboundResillience.
@Test
public void testInboundResillience() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final String groupName = "testInboundResillience";
final Manager<RoutingStrategy.Inbound> manager = new RoutingInboundManager();
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
final ClusterId clusterId = super.setTestName("testInboundResillience");
final NodeAddress na = new DummyNodeAddress("theOnlyNode");
final ContainerAddress ca = new ContainerAddress(na, 0);
final GroupDetails gd = new GroupDetails(groupName, na);
final Infrastructure infra = makeInfra(session, sched);
final Utils<GroupDetails> msutils = new Utils<>(infra, groupName, gd);
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.RoutingStrategy.ContainerAddress in project Dempsy by Dempsy.
the class TestLeaderAndSubscriber method testLeaderWithSubscriber.
@Test
public void testLeaderWithSubscriber() throws Exception {
final ClusterId cid = setTestName("testLeaderWithSubscriber");
final Utils<ContainerAddress> utils = new Utils<>(makeInfra(session, sched), cid.clusterName, new ContainerAddress(new DummyNodeAddress(), new int[] { 0 }));
final AtomicBoolean isRunning = new AtomicBoolean(true);
try {
final Subscriber<ContainerAddress> s = new Subscriber<>(utils, infra, isRunning, (l, m) -> {
}, 256);
s.process();
final Leader<ContainerAddress> l = new Leader<>(utils, 256, 1, infra, isRunning, ContainerAddress[]::new);
l.process();
assertTrue(poll(o -> l.imIt()));
// wait until it owns 1
assertTrue(poll(o -> s.isReady()));
// s should now own all shards.
for (int i = 0; i < 256; i++) assertTrue(s.doIOwnShard(i));
} finally {
isRunning.set(false);
}
}
use of net.dempsy.router.RoutingStrategy.ContainerAddress in project Dempsy by Dempsy.
the class TestLeaderAndSubscriber method testMultiLeader.
@Test
public void testMultiLeader() throws Exception {
final int NUM_THREADS = 10;
final ClusterId cid = setTestName("testMultiLeader");
final AtomicBoolean isRunning = new AtomicBoolean(true);
final AtomicBoolean go = new AtomicBoolean(false);
final List<ListenerHolder> allHolders = new ArrayList<>();
try {
final List<ListenerHolder> holders = new ArrayList<>();
for (int i = 0; i < NUM_THREADS; i++) {
final ClusterInfoSession session = sessFact.createSession();
final Utils<ContainerAddress> utils = new Utils<>(makeInfra(session, sched), cid.clusterName, new ContainerAddress(new DummyNodeAddress(), new int[] { 0 }));
final Leader<ContainerAddress> l = new Leader<>(utils, 256, 1, infra, isRunning, ContainerAddress[]::new);
final Thread t = new Thread(() -> {
// wait for it.
while (!go.get()) {
if (!isRunning.get())
return;
Thread.yield();
}
l.process();
}, "testMultiLeader-" + i);
holders.add(new ListenerHolder(session, l, t));
t.start();
}
// all threads running.
Thread.sleep(50);
// we're going to modify holders
allHolders.addAll(holders);
// let 'em go.
go.set(true);
// once they're all ready, one should be 'it'
assertTrue(poll(o -> holders.stream().map(h -> h.l).filter(l -> l.isReady()).count() == NUM_THREADS));
assertEquals(1, holders.stream().map(h -> h.l).filter(l -> l.imIt()).count());
// find the leader and kill it.
final ListenerHolder h = holders.stream().filter(l -> l.l.imIt()).findFirst().get();
disruptor.accept(h.session);
holders.remove(h);
assertTrue(poll(o -> holders.stream().filter(l -> l.l.imIt()).count() == 1L));
Thread.sleep(50);
assertEquals(1, holders.stream().filter(l -> l.l.imIt()).count());
isRunning.set(false);
assertTrue(poll(o -> holders.stream().filter(l -> l.t.isAlive()).count() == 0));
} finally {
allHolders.forEach(h -> h.session.close());
isRunning.set(false);
}
}
Aggregations