use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class LargeTopologyWithHubTest method testLargeTopologyWithHub.
@Test
@Retry(timeoutMsec = 30000, intervalMsec = 500)
public void testLargeTopologyWithHub() throws Exception {
hub.dumpRepo();
final TopologyView tv = hub.getDiscoveryService().getTopology();
assertNotNull(tv);
logger.info("testLargeTopologyWithHub: checking if all connectors are registered, TopologyView has {} Instances", tv.getInstances().size());
TopologyHelper.assertTopologyConsistsOf(tv, slingIds.toArray(new String[slingIds.size()]));
logger.info("testLargeTopologyWithHub: test passed");
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class AbstractClusterTest method assertTopology.
private void assertTopology(VirtualInstance instance, SimpleClusterView... assertedClusterViews) {
final TopologyView topology = instance.getDiscoveryService().getTopology();
logger.info("assertTopology: instance " + instance.slingId + " sees topology: " + topology + ", expected: " + assertedClusterViews);
assertNotNull(topology);
if (assertedClusterViews.length != topology.getClusterViews().size()) {
dumpFailureDetails(topology, assertedClusterViews);
fail("instance " + instance.slingId + " expected " + assertedClusterViews.length + ", got: " + topology.getClusterViews().size());
}
final Set<ClusterView> actualClusters = new HashSet<ClusterView>(topology.getClusterViews());
for (int i = 0; i < assertedClusterViews.length; i++) {
final SimpleClusterView assertedClusterView = assertedClusterViews[i];
boolean foundMatch = false;
for (Iterator<ClusterView> it = actualClusters.iterator(); it.hasNext(); ) {
final ClusterView actualClusterView = it.next();
if (matches(assertedClusterView, actualClusterView)) {
it.remove();
foundMatch = true;
break;
}
}
if (!foundMatch) {
dumpFailureDetails(topology, assertedClusterViews);
fail("instance " + instance.slingId + " could not find a match in the topology with instance=" + instance.slingId + " and clusterViews=" + assertedClusterViews.length);
}
}
assertEquals("not all asserted clusterviews are in the actual view with instance=" + instance + " and clusterViews=" + assertedClusterViews, actualClusters.size(), 0);
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class AbstractClusterTest method testConnectorSwitching4139.
/* ok, this test should do the following:
* cluster A with instance 1 and instance 2
* cluster B with instance 3 and instance 4
* cluster C with instance 5
* initially, instance3 is pinging instance1, and instance 5 is pinging instance1 as well (MAC hub)
* that should result in instance3 and 5 to inherit the rest from instance1
* then simulate load balancer switching from instance1 to instance2 - hence pings go to instance2
*
*/
//TODO: this takes env 45sec
@Category(Slow.class)
@Test
public void testConnectorSwitching4139() throws Throwable {
final int MIN_EVENT_DELAY = 1;
// reset any setup that was done - we start with a different setup than the default one
tearDown();
final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.DEBUG);
instance1 = newBuilder().setDebugName("instance1").newRepository("/var/discovery/clusterA/", true).setConnectorPingTimeout(10).setConnectorPingInterval(999).setMinEventDelay(MIN_EVENT_DELAY).build();
instance2 = newBuilder().setDebugName("instance2").useRepositoryOf(instance1).setConnectorPingTimeout(10).setConnectorPingInterval(999).setMinEventDelay(MIN_EVENT_DELAY).build();
// now launch the remote instance
instance3 = newBuilder().setDebugName("instance3").newRepository("/var/discovery/clusterB/", false).setConnectorPingTimeout(10).setConnectorPingInterval(999).setMinEventDelay(MIN_EVENT_DELAY).build();
instance4 = newBuilder().setDebugName("instance4").useRepositoryOf(instance3).setConnectorPingTimeout(10).setConnectorPingInterval(999).setMinEventDelay(MIN_EVENT_DELAY).build();
instance5 = newBuilder().setDebugName("instance5").newRepository("/var/discovery/clusterC/", false).setConnectorPingTimeout(10).setConnectorPingInterval(999).setMinEventDelay(MIN_EVENT_DELAY).build();
// join the instances to form a cluster by sending out heartbeats
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
Thread.sleep(500);
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
Thread.sleep(500);
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
Thread.sleep(500);
assertSameTopology(new SimpleClusterView(instance1, instance2));
assertSameTopology(new SimpleClusterView(instance3, instance4));
assertSameTopology(new SimpleClusterView(instance5));
// create a topology connector from instance3 to instance1
// -> corresponds to starting to ping
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
pingConnector(instance3, instance1);
pingConnector(instance5, instance1);
Thread.sleep(500);
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
pingConnector(instance3, instance1);
pingConnector(instance5, instance1);
Thread.sleep(500);
// make asserts on the topology
logger.info("testConnectorSwitching4139: instance1.slingId=" + instance1.slingId);
logger.info("testConnectorSwitching4139: instance2.slingId=" + instance2.slingId);
logger.info("testConnectorSwitching4139: instance3.slingId=" + instance3.slingId);
logger.info("testConnectorSwitching4139: instance4.slingId=" + instance4.slingId);
logger.info("testConnectorSwitching4139: instance5.slingId=" + instance5.slingId);
instance1.dumpRepo();
assertSameTopology(new SimpleClusterView(instance1, instance2), new SimpleClusterView(instance3, instance4), new SimpleClusterView(instance5));
// simulate a crash of instance1, resulting in load-balancer to switch the pings
boolean success = false;
for (int i = 0; i < 25; i++) {
// loop for max 25 times, min 20 times
runHeartbeatOnceWith(instance2, instance3, instance4, instance5);
final boolean ping1 = pingConnector(instance3, instance2);
final boolean ping2 = pingConnector(instance5, instance2);
if (ping1 && ping2) {
// both pings were fine - hence break
success = true;
logger.info("testConnectorSwitching4139: successfully switched all pings to instance2 after " + i + " rounds.");
if (i < 20) {
logger.info("testConnectorSwitching4139: min loop cnt not yet reached: i=" + i);
// 20x1000ms = 20sec max - (vs 10sec timeout) - should be enough for timing out
Thread.sleep(1000);
continue;
}
break;
}
logger.info("testConnectorSwitching4139: looping cos ping1=" + ping1 + ", ping2=" + ping2);
// 25x1000ms = 25sec max - (vs 10sec timeout)
Thread.sleep(1000);
}
assertTrue(success);
// one final heartbeat
runHeartbeatOnceWith(instance2, instance3, instance4, instance5);
assertTrue(pingConnector(instance3, instance2));
assertTrue(pingConnector(instance5, instance2));
instance2.dumpRepo();
assertSameTopology(new SimpleClusterView(instance2), new SimpleClusterView(instance3, instance4), new SimpleClusterView(instance5));
// restart instance1, crash instance4
instance4.stopViewChecker();
instance1Restarted = newBuilder().setDebugName("instance1").useRepositoryOf(instance2).setConnectorPingTimeout(Integer.MAX_VALUE).setMinEventDelay(1).setSlingId(instance1.getSlingId()).build();
runHeartbeatOnceWith(instance1Restarted, instance2, instance3, instance5);
// give these heartbeats/votes some time .. so sleep 2sec (timeout is 10sec, so should be safe)
Thread.sleep(2000);
assertTrue(pingConnector(instance3, instance2));
assertTrue(pingConnector(instance5, instance2));
success = false;
for (int i = 0; i < 40; i++) {
runHeartbeatOnceWith(instance1Restarted, instance2, instance3, instance5);
instance1.getViewChecker().checkView();
// since instance3 *can* have an undefined cluster view..
try {
pingConnector(instance3, instance2);
} catch (UndefinedClusterViewException ucve) {
// ignore
}
pingConnector(instance5, instance2);
final TopologyView topology = instance3.getDiscoveryService().getTopology();
InstanceDescription i3 = null;
for (Iterator<InstanceDescription> it = topology.getInstances().iterator(); it.hasNext(); ) {
final InstanceDescription id = it.next();
if (id.getSlingId().equals(instance3.slingId)) {
i3 = id;
break;
}
}
assertNotNull(i3);
assertEquals(instance3.slingId, i3.getSlingId());
final ClusterView i3Cluster = i3.getClusterView();
final int i3ClusterSize = i3Cluster.getInstances().size();
if (i3ClusterSize == 1) {
if (i < 30) {
logger.info("testConnectorSwitching4139: [2] min loop cnt not yet reached: i=" + i);
// 30x500ms = 15sec max - (vs 10sec-2sec[sleep] timeout) - should be enough for timing out
Thread.sleep(500);
continue;
}
success = true;
logger.info("testConnectorSwitching4139: i3ClusterSize: " + i3ClusterSize + ", i=" + i + " (success)");
break;
}
logger.info("testConnectorSwitching4139: i3ClusterSize: " + i3ClusterSize + ", i=" + i);
Thread.sleep(500);
}
logger.info("testConnectorSwitching4139: instance1Restarted.slingId=" + instance1Restarted.slingId);
logger.info("testConnectorSwitching4139: instance2.slingId=" + instance2.slingId);
logger.info("testConnectorSwitching4139: instance3.slingId=" + instance3.slingId);
logger.info("testConnectorSwitching4139: instance4.slingId=" + instance4.slingId);
logger.info("testConnectorSwitching4139: instance5.slingId=" + instance5.slingId);
instance1Restarted.dumpRepo();
assertTrue(success);
assertSameTopology(new SimpleClusterView(instance1Restarted, instance2), new SimpleClusterView(instance3), new SimpleClusterView(instance5));
instance1Restarted.stop();
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class AbstractDiscoveryServiceTest method assertStableTopology.
private void assertStableTopology(Tester... instances) {
for (Tester tester : instances) {
logger.info("asserting tester: " + tester.instance.getDebugName());
TopologyEvent lastEvent = tester.previousEvent;
Type type = lastEvent.getType();
if (type == Type.TOPOLOGY_CHANGED || type == Type.TOPOLOGY_INIT) {
// fine
} else {
fail("wrong type, expected CHANGED or INIT, got: " + type);
}
assertNotNull(lastEvent.getNewView());
assertEquals(instances.length, lastEvent.getNewView().getInstances().size());
TopologyView t = tester.instance.getDiscoveryService().getTopology();
assertTrue(t.isCurrent());
assertEquals(instances.length, t.getInstances().size());
}
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class AbstractDiscoveryServiceTest method isStableTopology.
private boolean isStableTopology(Tester... instances) {
for (Tester tester : instances) {
TopologyEvent lastEvent = tester.previousEvent;
if (lastEvent == null) {
return false;
}
Type type = lastEvent.getType();
if (type == Type.TOPOLOGY_CHANGED || type == Type.TOPOLOGY_INIT) {
// fine
} else {
return false;
}
TopologyView newView = lastEvent.getNewView();
if (newView == null) {
return false;
}
if (instances.length != newView.getInstances().size()) {
return false;
}
TopologyView t = tester.instance.getDiscoveryService().getTopology();
if (!t.isCurrent()) {
return false;
}
if (instances.length != t.getInstances().size()) {
return false;
}
for (Tester t2 : instances) {
boolean foundMatch = false;
for (InstanceDescription id : t.getInstances()) {
if (t2.instance.getSlingId().equals(id.getSlingId())) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
return false;
}
}
}
return true;
}
Aggregations