use of org.apache.sling.discovery.commons.providers.spi.ClusterSyncService 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.spi.ClusterSyncService in project sling by apache.
the class ClusterSyncServiceChain method chainedSync.
private void chainedSync(final BaseTopologyView view, final Runnable callback, final Iterator<ClusterSyncService> chainIt) {
if (!chainIt.hasNext()) {
logger.debug("doSync: done with sync chain, invoking callback");
callback.run();
return;
}
ClusterSyncService next = chainIt.next();
next.sync(view, new Runnable() {
@Override
public void run() {
chainedSync(view, callback, chainIt);
}
});
}
Aggregations