use of org.apache.sling.discovery.commons.providers.BaseTopologyView 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.BaseTopologyView 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.BaseTopologyView 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);
}
use of org.apache.sling.discovery.commons.providers.BaseTopologyView in project sling by apache.
the class TestViewStateManager method testBindActivateChangedDeactivateChangingActivateChanged.
@Test
public void testBindActivateChangedDeactivateChangingActivateChanged() throws Exception {
final DummyListener listener = new DummyListener();
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view1 = new DummyTopologyView().addInstance();
mgr.handleNewView(view1);
assertEvents(listener, EventHelper.newInitEvent(view1));
mgr.handleDeactivated();
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
// need to bind again after deactivate
mgr.bind(listener);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view2 = new DummyTopologyView().addInstance();
mgr.handleNewView(view2);
assertEvents(listener, EventHelper.newInitEvent(view2));
}
use of org.apache.sling.discovery.commons.providers.BaseTopologyView in project sling by apache.
the class TestMinEventDelayHandler method testFailedDelaying.
//TODO test takes env 45sec
@Category(Slow.class)
@Test
public void testFailedDelaying() throws Exception {
scheduler.failMode();
final DummyListener listener = new DummyListener();
// first activate
mgr.handleActivated();
// paranoia
assertNoEvents(listener);
// then bind
mgr.bind(listener);
// there was no changing or changed yet
assertNoEvents(listener);
mgr.handleChanging();
assertNoEvents(listener);
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
TestHelper.assertEvents(mgr, listener, EventHelper.newInitEvent(view));
for (int i = 0; i < 7; i++) {
TestHelper.randomEventLoop(mgr, sds, 100, -1, defaultRandom, listener);
Thread.sleep(1000);
}
}
Aggregations