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);
}
}
Aggregations