use of net.dempsy.config.ClusterId 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.config.ClusterId 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);
}
}
use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class BaseRouterTestWithSession method setTestName.
protected ClusterId setTestName(final String testName) {
final ClusterId cid = clusterId(testName);
this.testName = cid.applicationName;
return cid;
}
use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestManagedRoutingStrategy method testInboundSimpleHappyPathRegister.
@Test
public void testInboundSimpleHappyPathRegister() 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 = new ClusterId("test", "test");
final Utils<ContainerAddress> msutils = new Utils<>(infra, clusterId.clusterName, new ContainerAddress(new DummyNodeAddress("testInboundSimpleHappyPathRegister"), 0));
assertNotNull(ib);
assertTrue(ManagedInbound.class.isAssignableFrom(ib.getClass()));
ib.setContainerDetails(clusterId, new ContainerAddress(new DummyNodeAddress("testInboundSimpleHappyPathRegister"), 0), (l, m) -> {
});
ib.start(infra);
assertTrue(waitForShards(session, msutils, numShardsToExpect));
}
}
use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestInstanceManager method setupContainer.
@SuppressWarnings("resource")
public LockingContainer setupContainer(final MessageProcessorLifecycle<?> prototype) throws ContainerException {
dispatcher = new DummyDispatcher();
statsCollector = new BasicClusterStatsCollector();
nodeStats = new BasicNodeStatsCollector();
container = (LockingContainer) new LockingContainer().setMessageProcessor(prototype).setClusterId(new ClusterId("test", "test"));
container.setDispatcher(dispatcher);
container.setInbound(new DummyInbound());
tm = new DefaultThreadingModel(TestInstanceManager.class.getName());
tm.start(TestInstanceManager.class.getName());
container.start(new TestInfrastructure(tm) {
@Override
public BasicClusterStatsCollector getClusterStatsCollector(final ClusterId clusterId) {
return statsCollector;
}
@Override
public NodeStatsCollector getNodeStatsCollector() {
return nodeStats;
}
});
return container;
}
Aggregations