use of org.apache.sling.discovery.commons.providers.BaseTopologyView in project sling by apache.
the class TestViewStateManager method testChangedPropertiesChanged.
@Test
public void testChangedPropertiesChanged() throws Exception {
final DummyListener listener = new DummyListener();
mgr.installMinEventDelayHandler(new DiscoveryService() {
@Override
public TopologyView getTopology() {
throw new IllegalStateException("not yet impl");
}
}, new DummyScheduler(), 1);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view1 = new DummyTopologyView().addInstance();
InstanceDescription instance1 = view1.getInstances().iterator().next();
ClusterView cluster1 = instance1.getClusterView();
mgr.handleNewView(view1);
assertEvents(listener, EventHelper.newInitEvent(view1));
DefaultClusterView cluster2 = new DefaultClusterView(new String(cluster1.getId()));
final BaseTopologyView view2 = new DummyTopologyView(view1.getLocalClusterSyncTokenId()).addInstance(instance1.getSlingId(), cluster2, instance1.isLeader(), instance1.isLocal());
DefaultInstanceDescription instance2 = (DefaultInstanceDescription) view2.getLocalInstance();
instance2.setProperty("foo", "bar");
mgr.handleNewView(view2);
assertEvents(listener, EventHelper.newPropertiesChangedEvent(view1, view2));
}
use of org.apache.sling.discovery.commons.providers.BaseTopologyView in project sling by apache.
the class TestViewStateManager method testBindActivateChangedChangingDeactivateActivateChangingChanged.
@Test
public void testBindActivateChangedChangingDeactivateActivateChangingChanged() 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.handleChanging();
assertEvents(listener, EventHelper.newChangingEvent(view1));
mgr.handleDeactivated();
TestHelper.assertNoEvents(listener);
// need to bind again after deactivate
mgr.bind(listener);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
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 TestViewStateManager method testActivateChangingBindChanged.
@Test
public void testActivateChangingBindChanged() throws Exception {
final DummyListener listener = new DummyListener();
// first activate
mgr.handleActivated();
// paranoia
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
// no listener yet
TestHelper.assertNoEvents(listener);
// then bind
mgr.bind(listener);
// no changed event yet
TestHelper.assertNoEvents(listener);
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
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 testBindActivateBindChangingChanged.
@Test
public void testBindActivateBindChangingChanged() throws Exception {
final DummyListener listener1 = new DummyListener();
final DummyListener listener2 = new DummyListener();
mgr.bind(listener1);
TestHelper.assertNoEvents(listener1);
mgr.handleActivated();
TestHelper.assertNoEvents(listener1);
mgr.bind(listener2);
TestHelper.assertNoEvents(listener1);
TestHelper.assertNoEvents(listener2);
mgr.handleChanging();
TestHelper.assertNoEvents(listener1);
TestHelper.assertNoEvents(listener2);
final BaseTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
assertEvents(listener1, EventHelper.newInitEvent(view));
assertEvents(listener2, EventHelper.newInitEvent(view));
randomEventLoop(defaultRandom, listener1, listener2);
}
use of org.apache.sling.discovery.commons.providers.BaseTopologyView 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;
}
Aggregations