use of org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener in project sling by apache.
the class AbstractSingleInstanceTest method testBootstrap.
@Test
public void testBootstrap() throws Throwable {
logger.info("testBootstrap: start");
try {
instance.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// SLING-5030 : isolated mode is gone, replaced with exception
// ok
}
// SLING-3750 : with delaying the init event, we now should NOT get any events
// before we let the view establish (which happens via heartbeats below)
AssertingTopologyEventListener ada = new AssertingTopologyEventListener();
instance.bindTopologyEventListener(ada);
assertEquals(0, ada.getEvents().size());
assertEquals(0, ada.getUnexpectedCount());
try {
instance.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
ada.addExpected(Type.TOPOLOGY_INIT);
instance.heartbeatsAndCheckView();
Thread.sleep(1000);
instance.heartbeatsAndCheckView();
Thread.sleep(1000);
logger.info("testBoostrap: dumping repo...");
instance.dumpRepo();
logger.info("testBoostrap: dumping listener...");
ada.dump();
assertEquals(0, ada.getUnexpectedCount());
assertEquals(1, ada.getEvents().size());
TopologyEvent initEvent = ada.getEvents().remove(0);
assertNotNull(initEvent);
assertNotNull(initEvent.getNewView());
assertNotNull(initEvent.getNewView().getClusterViews());
// after the view was established though, we expect it to be a normal
// EstablishedInstanceDescription
instance.assertEstablishedView();
logger.info("testBootstrap: end");
}
use of org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener in project sling by apache.
the class AbstractTopologyEventTest method testDelayedInitEvent.
/**
* Tests the fact that the INIT event is delayed until voting has succeeded
* (which is the default with SLIGN-5030 and SLING-4959
* @throws Throwable
*/
@Test
public void testDelayedInitEvent() throws Throwable {
logger.info("testDelayedInitEvent: start");
instance1 = newBuilder().setDebugName("firstInstanceA").newRepository("/var/discovery/impl/", true).setConnectorPingTimeout(3).setMinEventDelay(3).build();
AssertingTopologyEventListener l1 = new AssertingTopologyEventListener("instance1.l1");
l1.addExpected(Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
logger.info("testDelayedInitEvent: instance1 created, no events expected yet. slingId=" + instance1.slingId);
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
logger.info("testDelayedInitEvent: 2nd/3rd heartbeat sent - now expecting a TOPOLOGY_INIT");
instance1.dumpRepo();
// one event
assertEquals(1, l1.getEvents().size());
// the expected one
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
logger.info("testDelayedInitEvent: creating instance2");
instance2 = newBuilder().setDebugName("secondInstanceB").useRepositoryOf(instance1).setConnectorPingTimeout(20).setMinEventDelay(3).build();
logger.info("testDelayedInitEvent: instance2 created with slingId=" + instance2.slingId);
AssertingTopologyEventListener l2 = new AssertingTopologyEventListener("instance2.l2");
instance2.bindTopologyEventListener(l2);
logger.info("testDelayedInitEvent: listener instance2.l2 added - it should not get any events though");
AssertingTopologyEventListener l1Two = new AssertingTopologyEventListener("instance1.l1Two");
l1Two.addExpected(Type.TOPOLOGY_INIT);
logger.info("testDelayedInitEvent: listener instance1.l1Two added - it expects an INIT now");
instance1.bindTopologyEventListener(l1Two);
// SLING-4755: async event sending requires some minimal wait time nowadays
Thread.sleep(500);
// just because instance2 is started doesn't kick off any events yet
// since instance2 didn't send heartbeats yet
// one event
assertEquals(1, l1.getEvents().size());
// the expected one
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
assertEquals(0, l2.getEvents().size());
assertEquals(0, l2.getUnexpectedCount());
assertEquals(1, l1Two.getEvents().size());
// the expected one
assertEquals(0, l1Two.getRemainingExpectedCount());
assertEquals(0, l1Two.getUnexpectedCount());
// the second & third heartbeat though triggers the voting etc
logger.info("testDelayedInitEvent: two more heartbeats should trigger events");
l1.addExpected(Type.TOPOLOGY_CHANGING);
l1Two.addExpected(Type.TOPOLOGY_CHANGING);
Thread.sleep(500);
l2.addExpected(Type.TOPOLOGY_INIT);
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
Thread.sleep(500);
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
Thread.sleep(500);
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
logger.info("testDelayedInitEvent: instance1: " + instance1.slingId);
logger.info("testDelayedInitEvent: instance2: " + instance2.slingId);
instance1.dumpRepo();
assertEquals(0, l1.getUnexpectedCount());
assertEquals(2, l1.getEvents().size());
assertEquals(0, l2.getUnexpectedCount());
// with the switch to use the SyncTokenService in discovery.impl tests
// by default, the following check is no longer possible:
// assertEquals(1, l2.getEvents().size());
// (this is due to the fact that synching requires some more time
// and we're a bit early at this stage - the below same check
// is the only one that we can do here really - and that one must work)
assertEquals(0, l1Two.getUnexpectedCount());
assertEquals(2, l1Two.getEvents().size());
// wait until CHANGED is sent - which is 3 sec after CHANGING
l1.addExpected(Type.TOPOLOGY_CHANGED);
l1Two.addExpected(Type.TOPOLOGY_CHANGED);
Thread.sleep(4000);
assertEquals(0, l1.getUnexpectedCount());
// one event
assertEquals(3, l1.getEvents().size());
assertEquals(0, l2.getUnexpectedCount());
assertEquals(1, l2.getEvents().size());
assertEquals(0, l1Two.getUnexpectedCount());
assertEquals(3, l1Two.getEvents().size());
logger.info("testDelayedInitEvent: end");
}
use of org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener in project sling by apache.
the class AbstractTopologyEventTest method testGetDuringDelay.
@Test
public void testGetDuringDelay() throws Throwable {
instance1 = newBuilder().setDebugName("firstInstanceA").newRepository("/var/discovery/impl/", true).setConnectorPingTimeout(20).setMinEventDelay(6).build();
AssertingTopologyEventListener l1 = new AssertingTopologyEventListener("instance1.l1");
l1.addExpected(TopologyEvent.Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
TopologyView earlyTopo = instance1.getDiscoveryService().getTopology();
assertNotNull(earlyTopo);
assertFalse(earlyTopo.isCurrent());
assertEquals(1, earlyTopo.getInstances().size());
for (int i = 0; i < 4; i++) {
instance1.heartbeatsAndCheckView();
Thread.sleep(125);
}
TopologyView secondTopo = instance1.getDiscoveryService().getTopology();
assertEquals(1, secondTopo.getInstances().size());
assertEquals(instance1.getSlingId(), secondTopo.getInstances().iterator().next().getSlingId());
assertTrue(secondTopo.isCurrent());
instance1.dumpRepo();
assertEarlyAndFirstClusterViewIdMatches(earlyTopo, secondTopo);
Thread.sleep(500);
// should have gotten the INIT, hence 0 remaining expected events
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
l1.addExpected(TopologyEvent.Type.TOPOLOGY_CHANGING);
instance2 = newBuilder().setDebugName("secondInstanceB").useRepositoryOf(instance1).setConnectorPingTimeout(20).setMinEventDelay(1).build();
AssertingTopologyEventListener l2 = new AssertingTopologyEventListener("instance2.l1");
l2.addExpected(TopologyEvent.Type.TOPOLOGY_INIT);
instance2.bindTopologyEventListener(l2);
for (int i = 0; i < 4; i++) {
instance2.heartbeatsAndCheckView();
instance1.heartbeatsAndCheckView();
Thread.sleep(750);
}
assertEquals(0, l1.getUnexpectedCount());
TopologyView topo2 = instance2.getDiscoveryService().getTopology();
assertTrue(topo2.isCurrent());
assertEquals(2, topo2.getInstances().size());
TopologyView topo1 = instance1.getDiscoveryService().getTopology();
assertTrue(topo1.isCurrent());
assertEquals(2, topo1.getInstances().size());
l1.addExpected(TopologyEvent.Type.TOPOLOGY_CHANGED);
Thread.sleep(5000);
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
assertEquals(0, l2.getRemainingExpectedCount());
assertEquals(0, l2.getUnexpectedCount());
assertTrue(instance2.getDiscoveryService().getTopology().isCurrent());
assertEquals(2, instance2.getDiscoveryService().getTopology().getInstances().size());
assertTrue(instance1.getDiscoveryService().getTopology().isCurrent());
assertEquals(2, instance1.getDiscoveryService().getTopology().getInstances().size());
}
use of org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener in project sling by apache.
the class RepositoryDelaysTest method testOldView.
/**
* Tests whether the not-current view returned by getTopology()
* matches what listeners get in TOPOLOGY_CHANGING - it should
* basically be the same.
*/
@Test
public void testOldView() throws Throwable {
final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
// info should do
discoveryLogger.setLevel(Level.INFO);
FullJR2VirtualInstanceBuilder builder = newBuilder();
builder.setDebugName("firstInstanceA").newRepository("/var/discovery/impl/", true).setConnectorPingTimeout(3).setMinEventDelay(3);
instance1 = builder.fullBuild();
instance1.stopVoting();
TopologyView t1 = instance1.getDiscoveryService().getTopology();
// current it should not be
assertFalse(t1.isCurrent());
// but it can as well contain the local instance
assertEquals(1, t1.getInstances().size());
AssertingTopologyEventListener l1 = new AssertingTopologyEventListener("instance1.l1");
l1.addExpected(Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
logger.info("testOldView: instance1 created, no events expected yet. slingId=" + instance1.slingId);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
logger.info("testOldView: 2nd/3rd heartbeat sent - now expecting a TOPOLOGY_INIT");
instance1.dumpRepo();
// one event
assertEquals(1, l1.getEvents().size());
// the expected one
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// current it should now be
assertTrue(t1.isCurrent());
// and it must contain the local instance
assertEquals(1, t1.getInstances().size());
logger.info("testOldView: creating instance2");
l1.addExpected(Type.TOPOLOGY_CHANGING);
FullJR2VirtualInstanceBuilder builder2 = newBuilder();
builder2.setDebugName("secondInstanceB").useRepositoryOf(instance1).setConnectorPingTimeout(3).setMinEventDelay(3);
instance2 = builder2.fullBuild();
instance2.stopVoting();
logger.info("testOldView: instance2 created, now issuing one heartbeat with instance2 first, so that instance1 can take note of it");
instance2.heartbeatsAndCheckView();
logger.info("testOldView: now instance1 is also doing a heartbeat and should see that a new instance is there");
instance1.heartbeatsAndCheckView();
logger.info("testOldView: 500ms sleep...");
// allow some time for CHANGING to be sent
Thread.sleep(500);
logger.info("testOldView: 500ms sleep done.");
// INIT and CHANGING
assertEquals(2, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// current it should not be
assertFalse(t1.isCurrent());
// but it should still contain the local instance from before
assertEquals(1, t1.getInstances().size());
l1.addExpected(Type.TOPOLOGY_CHANGED);
logger.info("testOldView: now issuing 3 rounds of heartbeats/checks and expecting a TOPOLOGY_CHANGED then");
instance2.heartbeatsAndCheckView();
// instance2.analyzeVotings();
instance1.heartbeatsAndCheckView();
// instance1.analyzeVotings();
Thread.sleep(1200);
instance2.heartbeatsAndCheckView();
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
instance2.heartbeatsAndCheckView();
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
// INIT, CHANGING and CHANGED
assertEquals(3, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// and we should be current again
assertTrue(t1.isCurrent());
// and contain both instances now
assertEquals(2, t1.getInstances().size());
// timeout is set to 3sec, so we now do heartbeats for 4sec with only instance1
// to let instance2 crash
// force instance1 to no longer analyze the votings
// since stopVoting() only deactivates the listener, we also
// have to set votingHandler of heartbeatHandler to null
PrivateAccessor.setField(instance1.getHeartbeatHandler(), "votingHandler", null);
l1.addExpected(Type.TOPOLOGY_CHANGING);
for (int i = 0; i < 8; i++) {
instance1.getHeartbeatHandler().heartbeatAndCheckView();
Thread.sleep(500);
}
// INIT, CHANGING, CHANGED and CHANGED
assertEquals(4, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// we should still be !current
assertFalse(t1.isCurrent());
// and contain both instances
assertEquals(2, t1.getInstances().size());
}
use of org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener in project sling by apache.
the class OakDiscoveryServiceTest method testOldView.
/**
* Tests whether the not-current view returned by getTopology()
* matches what listeners get in TOPOLOGY_CHANGING - it should
* basically be the same.
*/
@Test
public void testOldView() throws Throwable {
final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
// info should do
discoveryLogger.setLevel(Level.INFO);
OakVirtualInstanceBuilder builder = newBuilder();
builder.setDebugName("firstInstanceA").newRepository("/var/discovery/oak/", true).setConnectorPingTimeout(3).setMinEventDelay(3);
instance1 = builder.build();
instance1.stopViewChecker();
// instance1.stopVoting();
TopologyView t1 = instance1.getDiscoveryService().getTopology();
// current it should not be
assertFalse(t1.isCurrent());
// but it can as well contain the local instance
assertEquals(1, t1.getInstances().size());
AssertingTopologyEventListener l1 = new AssertingTopologyEventListener("instance1.l1");
l1.addExpected(Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
logger.info("testOldView: instance1 created, no events expected yet. slingId=" + instance1.slingId);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
instance1.heartbeatsAndCheckView();
Thread.sleep(200);
logger.info("testOldView: 2nd/3rd heartbeat sent - now expecting a TOPOLOGY_INIT");
instance1.dumpRepo();
// one event
assertEquals(1, l1.getEvents().size());
// the expected one
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// current it should now be
assertTrue(t1.isCurrent());
// and it must contain the local instance
assertEquals(1, t1.getInstances().size());
logger.info("testOldView: creating instance2");
builder.getSimulatedLeaseCollection().setFinal(false);
l1.addExpected(Type.TOPOLOGY_CHANGING);
VirtualInstanceBuilder builder2 = newBuilder();
builder2.setDebugName("secondInstanceB").useRepositoryOf(instance1).setConnectorPingTimeout(3).setMinEventDelay(3);
instance2 = builder2.build();
instance2.stopViewChecker();
// instance2.stopVoting();
logger.info("testOldView: instance2 created, now issuing one heartbeat with instance2 first, so that instance1 can take note of it");
instance2.getViewChecker().checkView();
OakDiscoveryService oakDisco1 = (OakDiscoveryService) instance2.getDiscoveryService();
oakDisco1.checkForTopologyChange();
logger.info("testOldView: now instance1 is also doing a heartbeat and should see that a new instance is there");
instance1.getViewChecker().checkView();
OakDiscoveryService oakDisco2 = (OakDiscoveryService) instance1.getDiscoveryService();
oakDisco2.checkForTopologyChange();
logger.info("testOldView: 500ms sleep...");
// allow some time for CHANGING to be sent
Thread.sleep(500);
logger.info("testOldView: 500ms sleep done.");
// INIT and CHANGING
assertEquals(2, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// current it should not be
assertFalse(t1.isCurrent());
// but it should still contain the local instance from before
assertEquals(1, t1.getInstances().size());
builder.getSimulatedLeaseCollection().setFinal(true);
l1.addExpected(Type.TOPOLOGY_CHANGED);
logger.info("testOldView: now issuing 3 rounds of heartbeats/checks and expecting a TOPOLOGY_CHANGED then");
instance2.heartbeatsAndCheckView();
// instance2.analyzeVotings();
instance1.heartbeatsAndCheckView();
// instance1.analyzeVotings();
Thread.sleep(1200);
instance2.heartbeatsAndCheckView();
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
instance2.heartbeatsAndCheckView();
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
// INIT, CHANGING and CHANGED
assertEquals(3, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// and we should be current again
assertTrue(t1.isCurrent());
// and contain both instances now
assertEquals(2, t1.getInstances().size());
// timeout is set to 3sec, so we now do heartbeats for 4sec with only instance1
// to let instance2 crash
builder.getSimulatedLeaseCollection().setFinal(false);
l1.addExpected(Type.TOPOLOGY_CHANGING);
for (int i = 0; i < 8; i++) {
instance1.heartbeatsAndCheckView();
Thread.sleep(500);
}
// INIT, CHANGING, CHANGED and CHANGING
assertEquals(4, l1.getEvents().size());
// no remaining expected
assertEquals(0, l1.getRemainingExpectedCount());
// and no unexpected
assertEquals(0, l1.getUnexpectedCount());
t1 = instance1.getDiscoveryService().getTopology();
// and we should be current again
assertFalse(t1.isCurrent());
// and contain both instances now
assertEquals(2, t1.getInstances().size());
}
Aggregations