Search in sources :

Example 1 with TopologyEvent

use of org.apache.sling.discovery.TopologyEvent in project sling by apache.

the class AbstractDiscoveryServiceTest method assertStableTopology.

private void assertStableTopology(Tester... instances) {
    for (Tester tester : instances) {
        logger.info("asserting tester: " + tester.instance.getDebugName());
        TopologyEvent lastEvent = tester.previousEvent;
        Type type = lastEvent.getType();
        if (type == Type.TOPOLOGY_CHANGED || type == Type.TOPOLOGY_INIT) {
        // fine
        } else {
            fail("wrong type, expected CHANGED or INIT, got: " + type);
        }
        assertNotNull(lastEvent.getNewView());
        assertEquals(instances.length, lastEvent.getNewView().getInstances().size());
        TopologyView t = tester.instance.getDiscoveryService().getTopology();
        assertTrue(t.isCurrent());
        assertEquals(instances.length, t.getInstances().size());
    }
}
Also used : Type(org.apache.sling.discovery.TopologyEvent.Type) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyView(org.apache.sling.discovery.TopologyView)

Example 2 with TopologyEvent

use of org.apache.sling.discovery.TopologyEvent in project sling by apache.

the class AbstractDiscoveryServiceTest method isStableTopology.

private boolean isStableTopology(Tester... instances) {
    for (Tester tester : instances) {
        TopologyEvent lastEvent = tester.previousEvent;
        if (lastEvent == null) {
            return false;
        }
        Type type = lastEvent.getType();
        if (type == Type.TOPOLOGY_CHANGED || type == Type.TOPOLOGY_INIT) {
        // fine
        } else {
            return false;
        }
        TopologyView newView = lastEvent.getNewView();
        if (newView == null) {
            return false;
        }
        if (instances.length != newView.getInstances().size()) {
            return false;
        }
        TopologyView t = tester.instance.getDiscoveryService().getTopology();
        if (!t.isCurrent()) {
            return false;
        }
        if (instances.length != t.getInstances().size()) {
            return false;
        }
        for (Tester t2 : instances) {
            boolean foundMatch = false;
            for (InstanceDescription id : t.getInstances()) {
                if (t2.instance.getSlingId().equals(id.getSlingId())) {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch) {
                return false;
            }
        }
    }
    return true;
}
Also used : Type(org.apache.sling.discovery.TopologyEvent.Type) TopologyEvent(org.apache.sling.discovery.TopologyEvent) InstanceDescription(org.apache.sling.discovery.InstanceDescription) TopologyView(org.apache.sling.discovery.TopologyView)

Example 3 with TopologyEvent

use of org.apache.sling.discovery.TopologyEvent in project sling by apache.

the class AbstractSingleInstanceTest method testBootstrap.

@Test
public void testBootstrap() throws Throwable {
    logger.info("testBootstrap: start");
    try {
        instance.getClusterViewService().getLocalClusterView();
        fail("should complain");
    } catch (UndefinedClusterViewException e) {
    // SLING-5030 : isolated mode is gone, replaced with exception
    // ok
    }
    // SLING-3750 : with delaying the init event, we now should NOT get any events
    // before we let the view establish (which happens via heartbeats below)
    AssertingTopologyEventListener ada = new AssertingTopologyEventListener();
    instance.bindTopologyEventListener(ada);
    assertEquals(0, ada.getEvents().size());
    assertEquals(0, ada.getUnexpectedCount());
    try {
        instance.getClusterViewService().getLocalClusterView();
        fail("should complain");
    } catch (UndefinedClusterViewException e) {
    // ok
    }
    ada.addExpected(Type.TOPOLOGY_INIT);
    instance.heartbeatsAndCheckView();
    Thread.sleep(1000);
    instance.heartbeatsAndCheckView();
    Thread.sleep(1000);
    logger.info("testBoostrap: dumping repo...");
    instance.dumpRepo();
    logger.info("testBoostrap: dumping listener...");
    ada.dump();
    assertEquals(0, ada.getUnexpectedCount());
    assertEquals(1, ada.getEvents().size());
    TopologyEvent initEvent = ada.getEvents().remove(0);
    assertNotNull(initEvent);
    assertNotNull(initEvent.getNewView());
    assertNotNull(initEvent.getNewView().getClusterViews());
    // after the view was established though, we expect it to be a normal
    // EstablishedInstanceDescription
    instance.assertEstablishedView();
    logger.info("testBootstrap: end");
}
Also used : TopologyEvent(org.apache.sling.discovery.TopologyEvent) AssertingTopologyEventListener(org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException) Test(org.junit.Test)

Example 4 with TopologyEvent

use of org.apache.sling.discovery.TopologyEvent in project sling by apache.

the class TestInitDelayingTopologyEventListener method testConstructor.

@Test
public void testConstructor() throws Exception {
    final TopologyEventListener delegate = new TopologyEventListener() {

        @Override
        public void handleTopologyEvent(TopologyEvent event) {
        // nothing here atm
        }
    };
    final Scheduler scheduler = createScheduler();
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) Test(org.junit.Test)

Example 5 with TopologyEvent

use of org.apache.sling.discovery.TopologyEvent in project sling by apache.

the class DiscoveryWithSyncTokenTest method testTwoNodes.

@Test
public void testTwoNodes() throws Throwable {
    logger.info("testTwoNodes: start");
    FullJR2VirtualInstanceBuilder b1 = new FullJR2VirtualInstanceBuilder();
    b1.setDebugName("i1").newRepository("/var/twon/", true);
    b1.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
    VirtualInstance i1 = b1.build();
    instances.add(i1);
    i1.bindTopologyEventListener(new TopologyEventListener() {

        @Override
        public void handleTopologyEvent(TopologyEvent event) {
            logger.info("GOT EVENT: " + event);
        }
    });
    FullJR2VirtualInstanceBuilder b2 = new FullJR2VirtualInstanceBuilder();
    b2.setDebugName("i2").useRepositoryOf(i1);
    b2.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
    VirtualInstance i2 = b2.build();
    instances.add(i2);
    i1.heartbeatsAndCheckView();
    i2.heartbeatsAndCheckView();
    i1.heartbeatsAndCheckView();
    i2.heartbeatsAndCheckView();
    Thread.sleep(999);
//TODO: finalize test
}
Also used : FullJR2VirtualInstanceBuilder(org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) Test(org.junit.Test)

Aggregations

TopologyEvent (org.apache.sling.discovery.TopologyEvent)21 TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)10 Test (org.junit.Test)10 TopologyView (org.apache.sling.discovery.TopologyView)7 ArrayList (java.util.ArrayList)5 Type (org.apache.sling.discovery.TopologyEvent.Type)4 DiscoveryService (org.apache.sling.discovery.DiscoveryService)3 InstanceDescription (org.apache.sling.discovery.InstanceDescription)2 InitDelayingTopologyEventListener (org.apache.sling.discovery.commons.InitDelayingTopologyEventListener)2 DummyTopologyView (org.apache.sling.discovery.commons.providers.DummyTopologyView)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Level (org.apache.log4j.Level)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 Scheduler (org.apache.sling.commons.scheduler.Scheduler)1 PropertyProvider (org.apache.sling.discovery.PropertyProvider)1