use of org.apache.sling.discovery.commons.providers.DefaultInstanceDescription in project sling by apache.
the class DefaultTopologyViewTest method createSingleInstanceTopology.
private DefaultTopologyView createSingleInstanceTopology(String slingId, String clusterViewId, String syncTokenId) {
LocalClusterView clusterView = new LocalClusterView(clusterViewId, syncTokenId);
DefaultInstanceDescription instance = TopologyHelper.createInstanceDescription(slingId, true, clusterView);
DefaultTopologyView t = new DefaultTopologyView();
t.setLocalClusterView(clusterView);
return t;
}
use of org.apache.sling.discovery.commons.providers.DefaultInstanceDescription in project sling by apache.
the class DefaultTopologyViewTest method testForcedLeaderChangeCompare.
@Test
public void testForcedLeaderChangeCompare() throws Exception {
// create view 1 with first instance the leader
final String slingId1 = UUID.randomUUID().toString();
final DefaultTopologyView view1 = TopologyHelper.createTopologyView(UUID.randomUUID().toString(), slingId1);
final DefaultInstanceDescription id2 = TopologyHelper.addInstanceDescription(view1, TopologyHelper.createInstanceDescription(view1.getClusterViews().iterator().next()));
final String slingId2 = id2.getSlingId();
final DefaultInstanceDescription id3 = TopologyHelper.addInstanceDescription(view1, TopologyHelper.createInstanceDescription(view1.getClusterViews().iterator().next()));
final String slingId3 = id3.getSlingId();
// now create view 2 with exactly the same instances as above, but the second instance the leader
DefaultTopologyView view2 = TopologyHelper.cloneTopologyView(view1, slingId2);
// make sure we've chosen a new leader:
assertNotEquals(view1.getClusterViews().iterator().next().getLeader().getSlingId(), view2.getClusterViews().iterator().next().getLeader().getSlingId());
// and now test the compare method which should catch the leader change
assertTrue(view1.compareTopology(view2) == Type.TOPOLOGY_CHANGED);
// same thing now with view3 which takes slingId3 as the leader
DefaultTopologyView view3 = TopologyHelper.cloneTopologyView(view1, slingId3);
// make sure we've chosen a new leader:
assertNotEquals(view1.getClusterViews().iterator().next().getLeader().getSlingId(), view3.getClusterViews().iterator().next().getLeader().getSlingId());
// and now test the compare method which should catch the leader change
assertTrue(view1.compareTopology(view3) == Type.TOPOLOGY_CHANGED);
}
use of org.apache.sling.discovery.commons.providers.DefaultInstanceDescription in project sling by apache.
the class DefaultTopologyViewTest method testFind.
@Test
public void testFind() throws Exception {
DefaultTopologyView newView = TopologyHelper.createTopologyView(UUID.randomUUID().toString(), UUID.randomUUID().toString());
TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
try {
newView.findInstances(null);
fail("should complain");
} catch (IllegalArgumentException iae) {
// ok
}
final DefaultInstanceDescription id = TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
assertEquals(4, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return true;
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return instance.getSlingId().equals(id.getSlingId());
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return instance.isLeader();
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
boolean first = true;
public boolean accept(InstanceDescription instance) {
if (!first) {
return false;
}
first = false;
return true;
}
}).size());
}
use of org.apache.sling.discovery.commons.providers.DefaultInstanceDescription in project sling by apache.
the class AnnouncementRegistryImplTest method testLists.
@Test
public void testLists() throws Exception {
try {
registry.listAnnouncementsInSameCluster(null);
fail("should complain");
} catch (IllegalArgumentException iae) {
// ok
}
try {
registry.listAnnouncementsInSameCluster(null);
fail("should complain");
} catch (IllegalArgumentException iae) {
// ok
}
assertEquals(0, registry.listLocalAnnouncements().size());
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
DefaultClusterView localCluster = new DefaultClusterView(UUID.randomUUID().toString());
DefaultInstanceDescription instance = TopologyHelper.createInstanceDescription(slingId, true, localCluster);
assertEquals(0, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(0, registry.listLocalAnnouncements().size());
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
Announcement ann = new Announcement(slingId);
ann.setLocalCluster(localCluster);
ann.setInherited(true);
registry.registerAnnouncement(ann);
assertEquals(1, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(1, registry.listLocalAnnouncements().size());
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
ann.setInherited(true);
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
assertTrue(registry.hasActiveAnnouncement(slingId));
assertFalse(registry.hasActiveAnnouncement(UUID.randomUUID().toString()));
registry.unregisterAnnouncement(slingId);
assertEquals(0, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(0, registry.listLocalAnnouncements().size());
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
assertFalse(registry.hasActiveAnnouncement(slingId));
assertFalse(registry.hasActiveAnnouncement(UUID.randomUUID().toString()));
ann.setInherited(false);
registry.registerAnnouncement(ann);
assertEquals(1, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(1, registry.listLocalAnnouncements().size());
assertEquals(1, registry.listLocalIncomingAnnouncements().size());
assertTrue(registry.hasActiveAnnouncement(slingId));
assertFalse(registry.hasActiveAnnouncement(UUID.randomUUID().toString()));
registry.unregisterAnnouncement(slingId);
assertEquals(0, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(0, registry.listLocalAnnouncements().size());
assertEquals(0, registry.listLocalIncomingAnnouncements().size());
assertFalse(registry.hasActiveAnnouncement(slingId));
assertFalse(registry.hasActiveAnnouncement(UUID.randomUUID().toString()));
assertEquals(1, ann.listInstances().size());
registry.addAllExcept(ann, localCluster, new AnnouncementFilter() {
public boolean accept(String receivingSlingId, Announcement announcement) {
assertNotNull(receivingSlingId);
assertNotNull(announcement);
return true;
}
});
assertEquals(1, ann.listInstances().size());
registry.registerAnnouncement(createAnnouncement(createCluster(3), 1, false));
assertEquals(1, registry.listAnnouncementsInSameCluster(localCluster).size());
assertEquals(3, registry.listInstances(localCluster).size());
registry.addAllExcept(ann, localCluster, new AnnouncementFilter() {
public boolean accept(String receivingSlingId, Announcement announcement) {
assertNotNull(receivingSlingId);
assertNotNull(announcement);
return true;
}
});
assertEquals(4, ann.listInstances().size());
registry.registerAnnouncement(ann);
assertEquals(2, registry.listAnnouncementsInSameCluster(localCluster).size());
}
use of org.apache.sling.discovery.commons.providers.DefaultInstanceDescription in project sling by apache.
the class TopologyHelper method createTopologyView.
public static DefaultTopologyView createTopologyView(String clusterViewId, String slingId) {
DefaultTopologyView t = new DefaultTopologyView();
DefaultClusterView c = new DefaultClusterView(clusterViewId);
DefaultInstanceDescription i = new DefaultInstanceDescription(c, true, false, slingId, new HashMap<String, String>());
Collection<InstanceDescription> instances = new LinkedList<InstanceDescription>();
instances.add(i);
t.addInstances(instances);
return t;
}
Aggregations