Search in sources :

Example 11 with BaseTopologyView

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

Example 12 with BaseTopologyView

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

Example 13 with BaseTopologyView

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

Example 14 with BaseTopologyView

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

Example 15 with BaseTopologyView

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

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