Search in sources :

Example 1 with VirtualInstance

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

the class LargeTopologyWithHubTest method tearDown.

@After
public void tearDown() throws Exception {
    for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
        final VirtualInstance instance = it.next();
        instance.stop();
    }
}
Also used : VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) After(org.junit.After)

Example 2 with VirtualInstance

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

the class AbstractClusterTest method assertSameTopology.

private void assertSameTopology(SimpleClusterView... clusters) throws UndefinedClusterViewException {
    if (clusters == null) {
        return;
    }
    for (int i = 0; i < clusters.length; i++) {
        // go through all clusters
        final SimpleClusterView aCluster = clusters[i];
        assertSameClusterIds(aCluster.instances);
        for (int j = 0; j < aCluster.instances.length; j++) {
            // and all instances therein
            final VirtualInstance anInstance = aCluster.instances[j];
            // an verify that they all see the same
            assertTopology(anInstance, clusters);
            for (int k = 0; k < clusters.length; k++) {
                final SimpleClusterView otherCluster = clusters[k];
                if (aCluster == otherCluster) {
                    // then ignore this one
                    continue;
                }
                for (int m = 0; m < otherCluster.instances.length; m++) {
                    assertNotSameClusterIds(anInstance, otherCluster.instances[m]);
                }
            }
        }
    }
}
Also used : VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance)

Example 3 with VirtualInstance

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

the class TopologyTest method testTwoNodes.

@Test
public void testTwoNodes() throws Throwable {
    VirtualInstanceBuilder builder1 = newBuilder().newRepository("/var/discovery/impl/", true).setDebugName("instance1").setConnectorPingInterval(20).setConnectorPingTimeout(200);
    VirtualInstance instance1 = builder1.build();
    instances.add(instance1);
    VirtualInstanceBuilder builder2 = newBuilder().useRepositoryOf(builder1).setDebugName("instance2").setConnectorPingInterval(20).setConnectorPingTimeout(200);
    VirtualInstance instance2 = builder2.build();
    instances.add(instance2);
    instance1.getConfig().setViewCheckTimeout(8);
    instance1.getConfig().setViewCheckInterval(1);
    instance2.getConfig().setViewCheckTimeout(2);
    instance2.getConfig().setViewCheckInterval(1);
    for (int i = 0; i < 5; i++) {
        instance1.heartbeatsAndCheckView();
        instance2.heartbeatsAndCheckView();
        Thread.sleep(500);
    }
    Set<InstanceDescription> instances1 = instance1.getDiscoveryService().getTopology().getInstances();
    Set<InstanceDescription> instances2 = instance2.getDiscoveryService().getTopology().getInstances();
    assertEquals(1, instances1.size());
    assertEquals(1, instances2.size());
    assertEquals(instance1.getSlingId(), instances1.iterator().next().getSlingId());
    assertEquals(instance2.getSlingId(), instances2.iterator().next().getSlingId());
    new VirtualConnector(instance1, instance2);
    // check instance 1's announcements
    Collection<Announcement> instance1LocalAnnouncements = instance1.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(1, instance1LocalAnnouncements.size());
    Announcement instance1LocalAnnouncement = instance1LocalAnnouncements.iterator().next();
    assertEquals(instance2.getSlingId(), instance1LocalAnnouncement.getOwnerId());
    assertEquals(true, instance1LocalAnnouncement.isInherited());
    // check instance 2's announcements
    Collection<Announcement> instance2LocalAnnouncements = instance2.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(1, instance2LocalAnnouncements.size());
    Announcement instance2LocalAnnouncement = instance2LocalAnnouncements.iterator().next();
    assertEquals(instance1.getSlingId(), instance2LocalAnnouncement.getOwnerId());
    assertEquals(false, instance2LocalAnnouncement.isInherited());
    // check topology
    TopologyHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId(), instance2.getSlingId());
    TopologyHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance1.getSlingId(), instance2.getSlingId());
    instance1LocalAnnouncements = instance1.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(1, instance1LocalAnnouncements.size());
    instance2LocalAnnouncements = instance2.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(1, instance2LocalAnnouncements.size());
    // sleep of 2.2sec ensures instance2's heartbeat timeout (which is 2sec) hits
    Thread.sleep(2200);
    instance1LocalAnnouncements = instance1.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(1, instance1LocalAnnouncements.size());
    instance2LocalAnnouncements = instance2.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(0, instance2LocalAnnouncements.size());
    logger.info("testTwoNodes: instance1: " + instance1.getSlingId());
    instance1.dumpRepo();
    logger.info("testTwoNodes: instance2: " + instance2.getSlingId());
    instance2.dumpRepo();
    TopologyHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId(), instance2.getSlingId());
    TopologyHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance2.getSlingId());
    // another sleep 6s (2.2+6 = 8.2sec) ensures instance1's heartbeat timeout (which is 8sec) hits as well
    Thread.sleep(6000);
    instance1LocalAnnouncements = instance1.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(0, instance1LocalAnnouncements.size());
    instance2LocalAnnouncements = instance2.getAnnouncementRegistry().listLocalAnnouncements();
    assertEquals(0, instance2LocalAnnouncements.size());
    TopologyHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId());
    TopologyHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance2.getSlingId());
}
Also used : VirtualInstanceBuilder(org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder) DummyVirtualInstanceBuilder(org.apache.sling.discovery.base.connectors.DummyVirtualInstanceBuilder) VirtualConnector(org.apache.sling.discovery.base.its.setup.VirtualConnector) Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) InstanceDescription(org.apache.sling.discovery.InstanceDescription) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) Test(org.junit.Test)

Example 4 with VirtualInstance

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

the class AbstractClusterLoadTest method doDoTest.

private void doDoTest(final int size, final int loopCnt) throws Throwable {
    if (size < 2) {
        fail("can only test 2 or more instances");
    }
    VirtualInstanceBuilder builder = newBuilder().newRepository("/var/discovery/impl/ClusterLoadTest/doTest-" + size + "-" + loopCnt + "/", true).setDebugName("firstInstance-" + size + "_" + loopCnt).setConnectorPingTimeout(3).setConnectorPingInterval(20).setMinEventDelay(0);
    VirtualInstance firstInstance = builder.build();
    firstInstance.startViewChecker(1);
    instances.add(firstInstance);
    for (int i = 1; i < size; i++) {
        VirtualInstanceBuilder builder2 = newBuilder().useRepositoryOf(builder).setDebugName("subsequentInstance-" + i + "-" + size + "_" + loopCnt).setConnectorPingTimeout(3).setMinEventDelay(0).setConnectorPingInterval(20);
        VirtualInstance subsequentInstance = builder2.build();
        instances.add(subsequentInstance);
        subsequentInstance.startViewChecker(1);
    }
    for (int i = 0; i < loopCnt; i++) {
        logger.info("=====================");
        logger.info(" START of LOOP " + i);
        logger.info("=====================");
        // count how many instances had heartbeats running in the first place
        int aliveCnt = 0;
        for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
            VirtualInstance instance = it.next();
            if (instance.isViewCheckerRunning()) {
                aliveCnt++;
            }
        }
        logger.info("=====================");
        logger.info(" original aliveCnt " + aliveCnt);
        logger.info("=====================");
        if (aliveCnt == 0) {
            // if no one is sending heartbeats, all instances go back to isolated mode
            aliveCnt = 1;
        }
        final int aliveCntFinal = aliveCnt;
        for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
            VirtualInstance instance = it.next();
            try {
                instance.dumpRepo();
            } catch (Exception e) {
                logger.error("Failed dumping repo for instance " + instance.getSlingId(), e);
            }
        }
        // then verify that each instance sees that many instances
        for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
            final VirtualInstance instance = it.next();
            if (!instance.isViewCheckerRunning()) {
            // if the heartbeat is not running, this instance is considered dead
            // hence we're not doing any assert here (as the count is only
            // valid if heartbeat/checkView is running and that would void the test)
            } else {
                new RetryLoop(new ConditionImplementation(instance, aliveCntFinal), INSTANCE_VIEW_TIMEOUT_SECONDS, INSTANCE_VIEW_POLL_INTERVAL_MILLIS);
            }
        }
        // start/stop heartbeats accordingly
        logger.info("Starting/Stopping heartbeats with count=" + instances.size());
        for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
            VirtualInstance instance = it.next();
            if (random.nextBoolean()) {
                logger.info("Starting heartbeats with " + instance.slingId);
                instance.startViewChecker(1);
                logger.info("Started heartbeats with " + instance.slingId);
            } else {
                logger.info("Stopping heartbeats with " + instance.slingId);
                instance.stopViewChecker();
                logger.info("Stopped heartbeats with " + instance.slingId);
            }
        }
    }
}
Also used : VirtualInstanceBuilder(org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException)

Example 5 with VirtualInstance

use of org.apache.sling.discovery.base.its.setup.VirtualInstance 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

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