use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestViewStateManager method testActivateBindChangingDuplicateHandleNewView.
@Test
public void testActivateBindChangingDuplicateHandleNewView() throws Exception {
final DummyListener listener = new DummyListener();
mgr.handleActivated();
mgr.bind(listener);
mgr.handleChanging();
final DummyTopologyView view = new DummyTopologyView().addInstance();
mgr.handleNewView(view);
assertEvents(listener, EventHelper.newInitEvent(view));
mgr.handleNewView(DummyTopologyView.clone(view));
TestHelper.assertNoEvents(listener);
randomEventLoop(defaultRandom, listener);
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView in project sling by apache.
the class TestViewStateManager method testOnlyDiffersInProperties.
@Test
public void testOnlyDiffersInProperties() throws Exception {
final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
// changed from Level.DEBUG
discoveryLogger.setLevel(Level.INFO);
logger.info("testOnlyDiffersInProperties: start");
final String slingId1 = UUID.randomUUID().toString();
final String slingId2 = UUID.randomUUID().toString();
final String slingId3 = UUID.randomUUID().toString();
final String clusterId = UUID.randomUUID().toString();
final DefaultClusterView cluster = new DefaultClusterView(clusterId);
final DummyTopologyView view1 = new DummyTopologyView().addInstance(slingId1, cluster, true, true).addInstance(slingId2, cluster, false, false).addInstance(slingId3, cluster, false, false);
final DummyTopologyView view2 = DummyTopologyView.clone(view1).removeInstance(slingId2);
final DummyTopologyView view3 = DummyTopologyView.clone(view1).removeInstance(slingId2).removeInstance(slingId3);
DummyTopologyView view1Cloned = DummyTopologyView.clone(view1);
logger.info("testOnlyDiffersInProperties: handleNewView(view1)");
mgr.handleNewView(view1);
logger.info("testOnlyDiffersInProperties: handleActivated()");
mgr.handleActivated();
assertEquals(0, mgr.waitForAsyncEvents(5000));
assertFalse(mgr.onlyDiffersInProperties(view1));
assertFalse(mgr.onlyDiffersInProperties(view2));
assertFalse(mgr.onlyDiffersInProperties(view3));
logger.info("testOnlyDiffersInProperties: handleNewView(view2)");
mgr.handleNewView(view2);
assertEquals(0, mgr.waitForAsyncEvents(5000));
assertFalse(mgr.onlyDiffersInProperties(view1));
assertFalse(mgr.onlyDiffersInProperties(view2));
assertFalse(mgr.onlyDiffersInProperties(view3));
logger.info("testOnlyDiffersInProperties: handleNewView(view3)");
mgr.handleNewView(view3);
assertEquals(0, mgr.waitForAsyncEvents(5000));
assertFalse(mgr.onlyDiffersInProperties(view1));
assertFalse(mgr.onlyDiffersInProperties(view2));
assertFalse(mgr.onlyDiffersInProperties(view3));
final DummyTopologyView view4 = DummyTopologyView.clone(view1Cloned);
final DummyTopologyView view5 = DummyTopologyView.clone(view1Cloned);
final DummyTopologyView view6 = DummyTopologyView.clone(view1Cloned);
logger.info("testOnlyDiffersInProperties: handleNewView(view1cloned)");
mgr.handleNewView(view1Cloned);
assertEquals(0, mgr.waitForAsyncEvents(5000));
DefaultInstanceDescription i4_1 = (DefaultInstanceDescription) view4.getInstance(slingId1);
i4_1.setProperty("a", "b");
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view4)");
assertTrue(mgr.onlyDiffersInProperties(view4));
DefaultInstanceDescription i5_1 = (DefaultInstanceDescription) view5.getInstance(slingId1);
i5_1.setProperty("a", "b");
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view5)");
assertTrue(mgr.onlyDiffersInProperties(view5));
DummyTopologyView view4Cloned = DummyTopologyView.clone(view4);
mgr.handleNewView(view4);
assertEquals(0, mgr.waitForAsyncEvents(5000));
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view4Cloned)");
assertFalse(mgr.onlyDiffersInProperties(view4Cloned));
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view5)");
assertFalse(mgr.onlyDiffersInProperties(view5));
DefaultInstanceDescription i6_1 = (DefaultInstanceDescription) view6.getInstance(slingId1);
i6_1.setProperty("a", "c");
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6)");
assertTrue(mgr.onlyDiffersInProperties(view6));
String originalId = view6.getLocalClusterSyncTokenId();
view6.setId(UUID.randomUUID().toString());
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [2]");
assertFalse(mgr.onlyDiffersInProperties(view6));
view6.setId(originalId);
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [3]");
assertTrue(mgr.onlyDiffersInProperties(view6));
view6.setId(null);
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [4]");
assertFalse(mgr.onlyDiffersInProperties(view6));
view6.setId(originalId);
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [5]");
assertTrue(mgr.onlyDiffersInProperties(view6));
// hack: we're modifying the view *in the ViewStateManagerImpl* here!!:
view4.setId(null);
view6.setId(null);
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [6]");
assertTrue(mgr.onlyDiffersInProperties(view6));
view6.setId(originalId);
logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [7]");
assertFalse(mgr.onlyDiffersInProperties(view6));
}
use of org.apache.sling.discovery.commons.providers.DummyTopologyView 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.DummyTopologyView 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.DummyTopologyView 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);
}
Aggregations