use of org.apache.sling.discovery.base.commons.UndefinedClusterViewException 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");
}
use of org.apache.sling.discovery.base.commons.UndefinedClusterViewException in project sling by apache.
the class AbstractSingleInstanceTest method testGetters.
@Test
public void testGetters() throws UndefinedClusterViewException, InterruptedException {
logger.info("testGetters: start");
assertNotNull(instance);
logger.info("sling id=" + instance.getSlingId());
try {
instance.getClusterViewService().getLocalClusterView();
// SLING-5030
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
instance.heartbeatsAndCheckView();
// wait 4000ms for the vote to happen
Thread.sleep(4000);
assertNotNull(instance.getClusterViewService().getLocalClusterView());
ClusterView cv = instance.getClusterViewService().getLocalClusterView();
logger.info("cluster view: id=" + cv.getId());
assertNotNull(cv.getId());
assertNotSame(cv.getId(), "");
List<InstanceDescription> instances = cv.getInstances();
assertNotNull(instances);
assertTrue(instances.size() == 1);
InstanceDescription myInstance = instances.get(0);
assertNotNull(myInstance);
assertTrue(myInstance.getClusterView() == cv);
logger.info("instance id: " + myInstance.getSlingId());
assertEquals(instance.getSlingId(), myInstance.getSlingId());
Map<String, String> properties = myInstance.getProperties();
assertNotNull(properties);
assertNull(myInstance.getProperty("foo"));
assertTrue(myInstance.isLeader());
assertTrue(myInstance.isLocal());
logger.info("testGetters: end");
}
Aggregations