Search in sources :

Example 1 with BaseTopologyView

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));
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) InstanceDescription(org.apache.sling.discovery.InstanceDescription) DiscoveryService(org.apache.sling.discovery.DiscoveryService) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) TopologyView(org.apache.sling.discovery.TopologyView) DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 2 with BaseTopologyView

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));
}
Also used : DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 3 with BaseTopologyView

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);
}
Also used : DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 4 with BaseTopologyView

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);
}
Also used : DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 5 with BaseTopologyView

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;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ClusterSyncService(org.apache.sling.discovery.commons.providers.spi.ClusterSyncService) ViewStateManagerImpl(org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView)

Aggregations

BaseTopologyView (org.apache.sling.discovery.commons.providers.BaseTopologyView)23 DummyTopologyView (org.apache.sling.discovery.commons.providers.DummyTopologyView)19 Test (org.junit.Test)19 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 ClusterSyncService (org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)4 ViewStateManagerImpl (org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl)3 Random (java.util.Random)2 Before (org.junit.Before)2 Category (org.junit.experimental.categories.Category)2 LinkedList (java.util.LinkedList)1 ClusterView (org.apache.sling.discovery.ClusterView)1 DiscoveryService (org.apache.sling.discovery.DiscoveryService)1 InstanceDescription (org.apache.sling.discovery.InstanceDescription)1 TopologyView (org.apache.sling.discovery.TopologyView)1 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)1 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)1