use of org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl in project sling by apache.
the class ClusterTest method newMgr.
private ViewStateManagerImpl newMgr() {
ViewStateManagerImpl mgr = new ViewStateManagerImpl(new ReentrantLock(), new ClusterSyncService() {
public void sync(BaseTopologyView view, Runnable callback) {
callback.run();
}
@Override
public void cancelSync() {
// nothing to cancel, we're auto-run
}
});
mgrList.add(mgr);
return mgr;
}
use of org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl in project sling by apache.
the class ClusterTest method testTwoNodes.
@Test
public void testTwoNodes() throws Exception {
final ViewStateManagerImpl mgr1 = newMgr();
final String slingId1 = UUID.randomUUID().toString();
final ViewStateManagerImpl mgr2 = newMgr();
final String slingId2 = UUID.randomUUID().toString();
// bind l1
DummyListener l1 = new DummyListener();
mgr1.bind(l1);
assertCountEvents(mgr1, l1);
// bind l2
DummyListener l2 = new DummyListener();
mgr2.bind(l2);
assertCountEvents(mgr2, l2);
// fiddle with l1 - without any events expected to be sent
mgr1.handleChanging();
assertCountEvents(mgr1, l1);
mgr1.handleActivated();
assertCountEvents(mgr1, l1);
mgr1.handleChanging();
assertCountEvents(mgr1, l1);
// fiddle with l2 - without any events expected to be sent
mgr2.handleChanging();
assertCountEvents(mgr2, l2);
mgr2.handleActivated();
assertCountEvents(mgr2, l2);
mgr2.handleChanging();
assertCountEvents(mgr2, l2);
// call handleNewView with not-current views first...
BaseTopologyView vA1 = TestHelper.newView(false, slingId1, slingId1, slingId1, slingId2);
mgr1.handleNewView(vA1);
assertCountEvents(mgr1, l1);
assertCountEvents(mgr2, l2);
BaseTopologyView vB1 = TestHelper.newView(false, slingId1, slingId2, slingId1, slingId2);
mgr2.handleNewView(vB1);
assertCountEvents(mgr1, l1);
assertCountEvents(mgr2, l2);
// then call handleNewView with a current view - that should now sent the INIT
BaseTopologyView vA2 = TestHelper.newView(true, slingId1, slingId1, slingId1, slingId2);
mgr1.handleNewView(vA2);
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT);
assertCountEvents(mgr2, l2);
BaseTopologyView vB2 = TestHelper.newView(true, slingId1, slingId2, slingId1, slingId2);
mgr2.handleNewView(vB2);
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT);
assertCountEvents(mgr2, l2, Type.TOPOLOGY_INIT);
// now let instance1 get decoupled from the cluster (pseudo-network-partitioning)
BaseTopologyView vB3 = TestHelper.newView(true, slingId2, slingId2, slingId2);
mgr2.handleNewView(vB3);
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT);
assertCountEvents(mgr2, l2, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
// now let instance1 take note of this decoupling
mgr1.handleChanging();
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING);
assertCountEvents(mgr2, l2, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
// and now let instance1 rejoin
BaseTopologyView vA4 = TestHelper.newView(true, slingId2, slingId1, slingId1, slingId2);
mgr1.handleNewView(vA4);
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
assertCountEvents(mgr2, l2, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
BaseTopologyView vB4 = TestHelper.newView(true, slingId2, slingId2, slingId1, slingId2);
mgr2.handleNewView(vA4);
assertCountEvents(mgr1, l1, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
assertCountEvents(mgr2, l2, Type.TOPOLOGY_INIT, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED, Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
}
use of org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl in project sling by apache.
the class ClusterTest method setup.
@Before
public void setup() throws Exception {
mgrList = new LinkedList<ViewStateManagerImpl>();
// I want randomness yes, but deterministic, for some methods at least
defaultRandom = new Random(1234123412);
}
use of org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl in project sling by apache.
the class TestMinEventDelayHandler method setup.
@Before
public void setup() throws Exception {
mgr = new ViewStateManagerImpl(new ReentrantLock(), new ClusterSyncService() {
@Override
public void sync(BaseTopologyView view, Runnable callback) {
callback.run();
}
@Override
public void cancelSync() {
// nothing to cancel, we're auto-run
}
});
// I want randomness yes, but deterministic, for some methods at least
defaultRandom = new Random(1234123412);
scheduler = new DummyScheduler();
sds = new DummyDiscoveryService();
mgr.installMinEventDelayHandler(sds, scheduler, 1);
final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
// changed from Level.DEBUG
discoveryLogger.setLevel(Level.INFO);
}
Aggregations