use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestMinEventDelayHandler method testReactivate.
@Test
public void testReactivate() throws Exception {
logger.info("testReactivate: start");
// install a minEventDelayHandler with a longer delay of 2sec
mgr.installMinEventDelayHandler(sds, scheduler, 2);
final DummyListener listener = new DummyListener();
logger.info("testReactivate: calling handleActivated");
mgr.bind(listener);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
final DummyTopologyView view1 = new DummyTopologyView().addInstance();
final DummyTopologyView view2 = DummyTopologyView.clone(view1).addInstance(UUID.randomUUID().toString(), (DefaultClusterView) view1.getLocalInstance().getClusterView(), false, false);
final DummyTopologyView view3 = DummyTopologyView.clone(view1).addInstance(UUID.randomUUID().toString(), (DefaultClusterView) view1.getLocalInstance().getClusterView(), false, false);
logger.info("testReactivate: calling handleNewView...");
mgr.handleNewView(view1);
logger.info("testReactivate: asserting init event");
TestHelper.assertEvents(mgr, listener, EventHelper.newInitEvent(view1));
logger.info("testReactivate: calling handleChanging...");
mgr.handleChanging();
TestHelper.assertEvents(mgr, listener, EventHelper.newChangingEvent(view1));
logger.info("testReactivate: calling handleNewView 2nd time...");
mgr.handleNewView(view2);
TestHelper.assertNoEvents(listener);
// make sure the MinEventDelayHandler finds a topology when coming back from the delaying, so:
sds.setTopoology(view2);
logger.info("testReactivate: waiting for async events to have been processed - 4sec");
Thread.sleep(4000);
logger.info("testReactivate: waiting for async events to have been processed - max another 2sec");
assertEquals(0, mgr.waitForAsyncEvents(2000));
logger.info("testReactivate: asserting CHANGED event");
TestHelper.assertEvents(mgr, listener, EventHelper.newChangedEvent(view1, view2));
// now do the above again, but this time do a handleDeactivated before receiving another changed event
logger.info("testReactivate: calling handleChanging...");
mgr.handleChanging();
TestHelper.assertEvents(mgr, listener, EventHelper.newChangingEvent(view2));
logger.info("testReactivate: calling handleNewView 2nd time...");
mgr.handleNewView(view3);
TestHelper.assertNoEvents(listener);
// make sure the MinEventDelayHandler finds a topology when coming back from the delaying, so:
sds.setTopoology(view3);
logger.info("testReactivate: doing handleDeactivated");
final AsyncEventSender asyncEventSender = mgr.getAsyncEventSender();
Field field = mgr.getClass().getDeclaredField("minEventDelayHandler");
field.setAccessible(true);
MinEventDelayHandler minEventDelayHandler = (MinEventDelayHandler) field.get(mgr);
assertNotNull(minEventDelayHandler);
// marking view3 as not current
view3.setNotCurrent();
sds.setTopoology(view3);
mgr.handleDeactivated();
TestHelper.assertNoEvents(listener);
logger.info("testReactivate: now waiting 5 sec to make sure the MinEventDelayHandler would be finished");
TestHelper.assertNoEvents(listener);
Thread.sleep(5000);
logger.info("testReactivate: after those 5 sec there should however still not be any new event");
TestHelper.assertNoEvents(listener);
int cnt = asyncEventSender.getInFlightEventCnt();
if (minEventDelayHandler != null && minEventDelayHandler.isDelaying()) {
cnt++;
}
assertEquals(0, cnt);
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestMinEventDelayHandler method testLongMinDelay.
@Test
public void testLongMinDelay() throws Exception {
mgr.installMinEventDelayHandler(sds, scheduler, 5);
final DummyListener listener = new DummyListener();
// first activate
logger.info("testLongMinDelay: calling handleActivated...");
mgr.handleActivated();
// paranoia
assertNoEvents(listener);
// then bind
logger.info("testLongMinDelay: calling bind...");
mgr.bind(listener);
// there was no changing or changed yet
assertNoEvents(listener);
logger.info("testLongMinDelay: calling handleChanging...");
mgr.handleChanging();
assertNoEvents(listener);
final DummyTopologyView view = new DummyTopologyView().addInstance();
DummyTopologyView clonedView = view.clone();
logger.info("testLongMinDelay: calling handleNewView...");
mgr.handleNewView(view);
TestHelper.assertEvents(mgr, listener, EventHelper.newInitEvent(view));
final DummyTopologyView view2 = new DummyTopologyView().addInstance();
view2.addInstance(UUID.randomUUID().toString(), (DefaultClusterView) view2.getLocalInstance().getClusterView(), false, false);
logger.info("testLongMinDelay: calling handleNewView...");
clonedView.setNotCurrent();
mgr.handleNewView(view2);
TestHelper.assertEvents(mgr, listener, EventHelper.newChangingEvent(clonedView));
assertFalse(view.isCurrent());
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestViewStateManager method testCancelSync.
@Test
public void testCancelSync() throws Exception {
final List<Runnable> syncCallbacks = new LinkedList<Runnable>();
mgr = new ViewStateManagerImpl(new ReentrantLock(), new ClusterSyncService() {
@Override
public void sync(BaseTopologyView view, Runnable callback) {
synchronized (syncCallbacks) {
syncCallbacks.add(callback);
}
}
@Override
public void cancelSync() {
synchronized (syncCallbacks) {
syncCallbacks.clear();
}
}
});
mgr.handleActivated();
final DummyListener listener = new DummyListener();
mgr.bind(listener);
mgr.handleChanging();
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
assertEquals(0, mgr.waitForAsyncEvents(1000));
TestHelper.assertNoEvents(listener);
synchronized (syncCallbacks) {
assertEquals(1, syncCallbacks.size());
}
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
final BaseTopologyView view2 = TestHelper.newView(true, id1, id1, id1, id2);
mgr.handleNewView(view2);
assertEquals(0, mgr.waitForAsyncEvents(1000));
TestHelper.assertNoEvents(listener);
synchronized (syncCallbacks) {
assertEquals(1, syncCallbacks.size());
syncCallbacks.get(0).run();
syncCallbacks.clear();
}
assertEquals(0, mgr.waitForAsyncEvents(1000));
assertEvents(listener, EventHelper.newInitEvent(view2));
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestViewStateManager method testBindChangingChangedActivate.
@Test
public void testBindChangingChangedActivate() throws Exception {
final DummyListener listener = new DummyListener();
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
TestHelper.assertNoEvents(listener);
mgr.handleActivated();
assertEvents(listener, EventHelper.newInitEvent(view));
randomEventLoop(defaultRandom, listener);
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestViewStateManager method testBindChangingChangedChangingActivate.
@Test
public void testBindChangingChangedChangingActivate() throws Exception {
final DummyListener listener = new DummyListener();
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view2 = new DummyTopologyView().addInstance();
mgr.handleNewView(view2);
assertEvents(listener, EventHelper.newInitEvent(view2));
randomEventLoop(defaultRandom, listener);
}
Aggregations