Search in sources :

Example 6 with DummySlingSettingsService

use of org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService in project sling by apache.

the class AnnouncementRegistryImplTest method doTestCluster.

private void doTestCluster(boolean includeFinalExpiryCheck) throws Exception {
    ClusterView cluster1 = createCluster(2);
    ClusterView cluster2 = createCluster(4);
    ClusterView cluster3 = createCluster(7);
    Announcement ann1 = createAnnouncement(cluster1, 1, true);
    Announcement ann2 = createAnnouncement(cluster2, 2, true);
    Announcement ann3 = createAnnouncement(cluster3, 3, false);
    final String instance1 = UUID.randomUUID().toString();
    final String instance2 = UUID.randomUUID().toString();
    final String instance3 = UUID.randomUUID().toString();
    ClusterView myCluster = createCluster(instance1, instance2, instance3);
    AnnouncementRegistryImpl registry1 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance1), config);
    AnnouncementRegistryImpl registry2 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance2), config);
    AnnouncementRegistryImpl registry3 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance3), config);
    assertTrue(registry1.registerAnnouncement(ann1) != -1);
    assertTrue(registry2.registerAnnouncement(ann2) != -1);
    assertTrue(registry3.registerAnnouncement(ann3) != -1);
    assertTrue(registry1.hasActiveAnnouncement(cluster1.getInstances().get(1).getSlingId()));
    assertTrue(registry2.hasActiveAnnouncement(cluster2.getInstances().get(2).getSlingId()));
    assertTrue(registry3.hasActiveAnnouncement(cluster3.getInstances().get(3).getSlingId()));
    assertEquals(3, registry1.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry1.listLocalAnnouncements().size());
    assertEquals(0, registry1.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry1, myCluster, 4, 16);
    assertEquals(3, registry2.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry2.listLocalAnnouncements().size());
    assertEquals(0, registry2.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry2, myCluster, 4, 16);
    assertEquals(3, registry3.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry3.listLocalAnnouncements().size());
    assertEquals(1, registry3.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry3, myCluster, 4, 16);
    myCluster = createCluster(instance1, instance2);
    VirtualInstanceHelper.dumpRepo(resourceResolverFactory);
    assertEquals(2, registry1.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry1.listLocalAnnouncements().size());
    assertEquals(0, registry1.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry1, myCluster, 3, 8);
    assertEquals(2, registry2.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry2.listLocalAnnouncements().size());
    assertEquals(0, registry2.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry2, myCluster, 3, 8);
    if (includeFinalExpiryCheck) {
        Thread.sleep(10500);
        assertAnnouncements(registry1, myCluster, 3, 8);
        assertAnnouncements(registry2, myCluster, 3, 8);
        registry1.checkExpiredAnnouncements();
        registry2.checkExpiredAnnouncements();
        assertAnnouncements(registry1, myCluster, 1, 2);
        assertAnnouncements(registry2, myCluster, 1, 2);
    }
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)

Aggregations

DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)6 SimpleConnectorConfig (org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig)2 Before (org.junit.Before)2 Test (org.junit.Test)2 URL (java.net.URL)1 Session (javax.jcr.Session)1 ModifiableThreadPoolConfig (org.apache.sling.commons.threads.ModifiableThreadPoolConfig)1 DefaultThreadPool (org.apache.sling.commons.threads.impl.DefaultThreadPool)1 ClusterView (org.apache.sling.discovery.ClusterView)1 ClusterViewService (org.apache.sling.discovery.base.commons.ClusterViewService)1 BaseConfig (org.apache.sling.discovery.base.connectors.BaseConfig)1 AnnouncementRegistryImpl (org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistryImpl)1 DummyResourceResolverFactory (org.apache.sling.discovery.base.its.setup.mock.DummyResourceResolverFactory)1 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)1 DummyListener (org.apache.sling.discovery.commons.providers.base.DummyListener)1 DiscoveryLiteDescriptorBuilder (org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder)1 IdMapService (org.apache.sling.discovery.commons.providers.spi.base.IdMapService)1 HeartbeatHandler (org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler)1 TestConfig (org.apache.sling.discovery.impl.setup.TestConfig)1 OakVirtualInstanceBuilder (org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder)1