Search in sources :

Example 6 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance in project sling by apache.

the class DiscoveryWithSyncTokenTest method tearDown.

@After
public void tearDown() throws Exception {
    logger.info("teardown: start");
    for (VirtualInstance virtualInstance : instances) {
        virtualInstance.stop();
    }
    logger.info("teardown: end");
}
Also used : VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) After(org.junit.After)

Example 7 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance in project sling by apache.

the class HeartbeatTest method tearDown.

@After
public void tearDown() throws Exception {
    final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
    discoveryLogger.setLevel(logLevel);
    Iterator<VirtualInstance> it = instances.iterator();
    while (it.hasNext()) {
        VirtualInstance i = it.next();
        i.stop();
    }
}
Also used : VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) FullJR2VirtualInstance(org.apache.sling.discovery.impl.setup.FullJR2VirtualInstance) After(org.junit.After)

Example 8 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance in project sling by apache.

the class OakDiscoveryServiceTest method testDescriptorSeqNumChange.

@Test
public void testDescriptorSeqNumChange() throws Exception {
    logger.info("testDescriptorSeqNumChange: start");
    OakVirtualInstanceBuilder builder1 = (OakVirtualInstanceBuilder) new OakVirtualInstanceBuilder().setDebugName("instance1").newRepository("/foo/barry/foo/", true).setConnectorPingInterval(999).setConnectorPingTimeout(999);
    VirtualInstance instance1 = builder1.build();
    OakVirtualInstanceBuilder builder2 = (OakVirtualInstanceBuilder) new OakVirtualInstanceBuilder().setDebugName("instance2").useRepositoryOf(instance1).setConnectorPingInterval(999).setConnectorPingTimeout(999);
    VirtualInstance instance2 = builder2.build();
    logger.info("testDescriptorSeqNumChange: created both instances, binding listener...");
    DummyListener listener = new DummyListener();
    OakDiscoveryService discoveryService = (OakDiscoveryService) instance1.getDiscoveryService();
    discoveryService.bindTopologyEventListener(listener);
    logger.info("testDescriptorSeqNumChange: waiting 2sec, listener should not get anything yet");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(0, listener.countEvents());
    logger.info("testDescriptorSeqNumChange: issuing 2 heartbeats with each instance should let the topology get established");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    logger.info("testDescriptorSeqNumChange: listener should get an event within 2sec from now at latest");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    ResourceResolverFactory factory = instance1.getResourceResolverFactory();
    ResourceResolver resolver = factory.getServiceResourceResolver(null);
    instance1.heartbeatsAndCheckView();
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    // increment the seqNum by 2 - simulating a coming and going instance
    // while we were sleeping
    SimulatedLeaseCollection c = builder1.getSimulatedLeaseCollection();
    c.incSeqNum(2);
    logger.info("testDescriptorSeqNumChange: incremented seqnum by 2 - issuing another heartbeat should trigger a topology change");
    instance1.heartbeatsAndCheckView();
    // due to the nature of the syncService/minEventDelay we now explicitly first sleep 2sec before waiting for async events for another 2sec
    logger.info("testDescriptorSeqNumChange: sleeping 2sec for topology change to happen");
    Thread.sleep(2000);
    logger.info("testDescriptorSeqNumChange: ensuring no async events are still in the pipe - for another 2sec");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    logger.info("testDescriptorSeqNumChange: now listener should have received 3 events, it got: " + listener.countEvents());
    assertEquals(3, listener.countEvents());
}
Also used : OakVirtualInstanceBuilder(org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder) SimulatedLeaseCollection(org.apache.sling.discovery.oak.its.setup.SimulatedLeaseCollection) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) DummyListener(org.apache.sling.discovery.commons.providers.base.DummyListener) Test(org.junit.Test)

Example 9 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance in project sling by apache.

the class DiscoveryServiceImplTest method testLocalClusterSyncTokenIdChange.

@Test
public void testLocalClusterSyncTokenIdChange() throws Exception {
    logger.info("testLocalClusterSyncTokenIdChange: start");
    logger.info("testLocalClusterSyncTokenIdChange: creating instance1...");
    FullJR2VirtualInstanceBuilder builder1 = (FullJR2VirtualInstanceBuilder) new FullJR2VirtualInstanceBuilder().setDebugName("instance1").newRepository("/var/testLocalClusterSyncTokenIdChange/", true).setConnectorPingInterval(999).setConnectorPingTimeout(999).setMinEventDelay(0);
    VirtualInstance instance1 = builder1.build();
    logger.info("testLocalClusterSyncTokenIdChange: creating instance2...");
    FullJR2VirtualInstanceBuilder builder2 = (FullJR2VirtualInstanceBuilder) new FullJR2VirtualInstanceBuilder().setDebugName("instance2").useRepositoryOf(instance1).setConnectorPingInterval(999).setConnectorPingTimeout(999).setMinEventDelay(0);
    VirtualInstance instance2 = builder2.build();
    logger.info("testLocalClusterSyncTokenIdChange: registering listener...");
    DummyListener listener = new DummyListener();
    DiscoveryServiceImpl discoveryService = (DiscoveryServiceImpl) instance1.getDiscoveryService();
    discoveryService.bindTopologyEventListener(listener);
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(0, listener.countEvents());
    logger.info("testLocalClusterSyncTokenIdChange: doing some heartbeating...");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(2000);
    logger.info("testLocalClusterSyncTokenIdChange: expecting to have received the INIT...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    ResourceResolverFactory factory = instance1.getResourceResolverFactory();
    ResourceResolver resolver = factory.getServiceResourceResolver(null);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    logger.info("testLocalClusterSyncTokenIdChange: after another heartbeat nothing more should have been triggered...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    // simulate a change in the establishedView's viewId - which can be
    // achieved by triggering a revoting - which should result with the
    // same view cos the instances have not changed
    HeartbeatHandler heartbeatHandler = (HeartbeatHandler) instance1.getViewChecker();
    logger.info("testLocalClusterSyncTokenIdChange: forcing a new voting to start...");
    heartbeatHandler.startNewVoting();
    logger.info("testLocalClusterSyncTokenIdChange: doing some heartbeats to finish the voting...");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(3000);
    logger.info("testLocalClusterSyncTokenIdChange: now we should have gotten a CHANGING/CHANGED pair additionally...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(3, listener.countEvents());
}
Also used : FullJR2VirtualInstanceBuilder(org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) HeartbeatHandler(org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) DummyListener(org.apache.sling.discovery.commons.providers.base.DummyListener) Test(org.junit.Test) AbstractDiscoveryServiceTest(org.apache.sling.discovery.base.its.AbstractDiscoveryServiceTest)

Example 10 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance in project sling by apache.

the class OakVirtualInstanceBuilder method build.

@Override
public VirtualInstance build() throws Exception {
    if (path == null) {
        if (ownRepository) {
            setPath("/var/discovery/impl/");
            getConfig().setDiscoveryResourcePath("/var/discovery/impl/");
        } else {
            OakVirtualInstanceBuilder other = (OakVirtualInstanceBuilder) hookedToBuilder;
            this.path = other.path;
            getConfig().setDiscoveryResourcePath(other.path);
        }
    }
    if (path == null) {
        throw new IllegalStateException("no path set");
    }
    if (!path.startsWith("/")) {
        throw new IllegalStateException("path must start with /: " + path);
    }
    if (!path.endsWith("/")) {
        throw new IllegalStateException("path must end with /: " + path);
    }
    VirtualInstance result = new VirtualInstance(this) {
    };
    return result;
}
Also used : VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance)

Aggregations

VirtualInstance (org.apache.sling.discovery.base.its.setup.VirtualInstance)15 VirtualInstanceBuilder (org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder)5 After (org.junit.After)5 Test (org.junit.Test)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)2 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)2 VirtualConnector (org.apache.sling.discovery.base.its.setup.VirtualConnector)2 DummyListener (org.apache.sling.discovery.commons.providers.base.DummyListener)2 FullJR2VirtualInstanceBuilder (org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder)2 ClusterView (org.apache.sling.discovery.ClusterView)1 InstanceDescription (org.apache.sling.discovery.InstanceDescription)1 TopologyEvent (org.apache.sling.discovery.TopologyEvent)1 TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)1 DummyVirtualInstanceBuilder (org.apache.sling.discovery.base.connectors.DummyVirtualInstanceBuilder)1 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)1 AbstractDiscoveryServiceTest (org.apache.sling.discovery.base.its.AbstractDiscoveryServiceTest)1 HeartbeatHandler (org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler)1 FullJR2VirtualInstance (org.apache.sling.discovery.impl.setup.FullJR2VirtualInstance)1 OakVirtualInstanceBuilder (org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder)1