use of org.apache.sling.discovery.base.its.setup.mock.AcceptsMultiple in project sling by apache.
the class AbstractClusterTest method testAdditionalInstance.
//TODO: this takes env 15sec
@Category(Slow.class)
@Test
public void testAdditionalInstance() throws Throwable {
logger.info("testAdditionalInstance: start");
assertNotNull(instance1);
assertNotNull(instance2);
assertEquals(instance1.getSlingId(), instance1.getClusterViewService().getSlingId());
assertEquals(instance2.getSlingId(), instance2.getClusterViewService().getSlingId());
try {
instance1.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
try {
instance2.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
instance1.dumpRepo();
logger.info("testAdditionalInstance: 1st 2s sleep");
Thread.sleep(2000);
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
logger.info("testAdditionalInstance: 2nd 2s sleep");
Thread.sleep(2000);
instance1.dumpRepo();
String clusterId1 = instance1.getClusterViewService().getLocalClusterView().getId();
logger.info("clusterId1=" + clusterId1);
String clusterId2 = instance2.getClusterViewService().getLocalClusterView().getId();
logger.info("clusterId2=" + clusterId2);
assertEquals(clusterId1, clusterId2);
assertEquals(2, instance1.getClusterViewService().getLocalClusterView().getInstances().size());
assertEquals(2, instance2.getClusterViewService().getLocalClusterView().getInstances().size());
AssertingTopologyEventListener assertingTopologyEventListener = new AssertingTopologyEventListener();
assertingTopologyEventListener.addExpected(Type.TOPOLOGY_INIT);
assertEquals(1, assertingTopologyEventListener.getRemainingExpectedCount());
instance1.bindTopologyEventListener(assertingTopologyEventListener);
// SLING-4755: async event sending requires some minimal wait time nowadays
Thread.sleep(500);
assertEquals(0, assertingTopologyEventListener.getRemainingExpectedCount());
// startup instance 3
AcceptsMultiple acceptsMultiple = new AcceptsMultiple(Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
assertingTopologyEventListener.addExpected(acceptsMultiple);
assertingTopologyEventListener.addExpected(acceptsMultiple);
instance3 = newBuilder().setDebugName("thirdInstance").useRepositoryOf(instance1).build();
for (int i = 0; i < 4; i++) {
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
instance3.heartbeatsAndCheckView();
logger.info("testAdditionalInstance: i=" + i + ", 2s sleep");
Thread.sleep(2000);
}
assertEquals(1, acceptsMultiple.getEventCnt(Type.TOPOLOGY_CHANGING));
assertEquals(1, acceptsMultiple.getEventCnt(Type.TOPOLOGY_CHANGED));
logger.info("testAdditionalInstance: end");
}
Aggregations