Search in sources :

Example 1 with VirtualConnector

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

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

the class LargeTopologyWithHubTest method setup.

@Before
public void setup() throws Throwable {
    instances = new LinkedList<VirtualInstance>();
    // 1 hour should be enough, really
    final int defaultHeartbeatTimeout = 3600;
    final int heartbeatTimeout = TimeoutsProvider.getInstance().getTimeout(defaultHeartbeatTimeout);
    VirtualInstanceBuilder hubBuilder = newBuilder().newRepository("/var/discovery/impl/", true).setDebugName("hub").setConnectorPingInterval(5).setConnectorPingTimeout(heartbeatTimeout);
    hub = hubBuilder.build();
    instances.add(hub);
    hub.getConfig().setViewCheckTimeout(heartbeatTimeout);
    //        hub.installVotingOnHeartbeatHandler();
    hub.heartbeatsAndCheckView();
    hub.heartbeatsAndCheckView();
    assertNotNull(hub.getClusterViewService().getLocalClusterView());
    hub.startViewChecker(1);
    hub.dumpRepo();
    slingIds = new LinkedList<String>();
    slingIds.add(hub.getSlingId());
    logger.info("setUp: using heartbeatTimeout of " + heartbeatTimeout + "sec " + "(default: " + defaultHeartbeatTimeout + ")");
    for (int i = 0; i < TEST_SIZE; i++) {
        logger.info("setUp: creating instance" + i);
        VirtualInstanceBuilder builder2 = newBuilder().newRepository("/var/discovery/impl/", false).setDebugName("instance" + i).setConnectorPingInterval(5).setConnectorPingTimeout(heartbeatTimeout);
        VirtualInstance instance = builder2.build();
        instances.add(instance);
        instance.getConfig().setViewCheckTimeout(heartbeatTimeout);
        //            instance.installVotingOnHeartbeatHandler();
        instance.heartbeatsAndCheckView();
        instance.heartbeatsAndCheckView();
        ClusterView clusterView = instance.getClusterViewService().getLocalClusterView();
        assertNotNull(clusterView);
        new VirtualConnector(instance, hub);
        slingIds.add(instance.getSlingId());
    }
}
Also used : VirtualInstanceBuilder(org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder) ClusterView(org.apache.sling.discovery.ClusterView) VirtualConnector(org.apache.sling.discovery.base.its.setup.VirtualConnector) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) Before(org.junit.Before)

Aggregations

VirtualConnector (org.apache.sling.discovery.base.its.setup.VirtualConnector)2 VirtualInstance (org.apache.sling.discovery.base.its.setup.VirtualInstance)2 VirtualInstanceBuilder (org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder)2 ClusterView (org.apache.sling.discovery.ClusterView)1 InstanceDescription (org.apache.sling.discovery.InstanceDescription)1 DummyVirtualInstanceBuilder (org.apache.sling.discovery.base.connectors.DummyVirtualInstanceBuilder)1 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)1 Before (org.junit.Before)1 Test (org.junit.Test)1