use of org.apache.sling.discovery.TopologyEvent 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.TopologyEvent 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;
}
use of org.apache.sling.discovery.TopologyEvent in project sling by apache.
the class AbstractSingleInstanceTest method testBootstrap.
@Test
public void testBootstrap() throws Throwable {
logger.info("testBootstrap: start");
try {
instance.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// SLING-5030 : isolated mode is gone, replaced with exception
// ok
}
// SLING-3750 : with delaying the init event, we now should NOT get any events
// before we let the view establish (which happens via heartbeats below)
AssertingTopologyEventListener ada = new AssertingTopologyEventListener();
instance.bindTopologyEventListener(ada);
assertEquals(0, ada.getEvents().size());
assertEquals(0, ada.getUnexpectedCount());
try {
instance.getClusterViewService().getLocalClusterView();
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
ada.addExpected(Type.TOPOLOGY_INIT);
instance.heartbeatsAndCheckView();
Thread.sleep(1000);
instance.heartbeatsAndCheckView();
Thread.sleep(1000);
logger.info("testBoostrap: dumping repo...");
instance.dumpRepo();
logger.info("testBoostrap: dumping listener...");
ada.dump();
assertEquals(0, ada.getUnexpectedCount());
assertEquals(1, ada.getEvents().size());
TopologyEvent initEvent = ada.getEvents().remove(0);
assertNotNull(initEvent);
assertNotNull(initEvent.getNewView());
assertNotNull(initEvent.getNewView().getClusterViews());
// after the view was established though, we expect it to be a normal
// EstablishedInstanceDescription
instance.assertEstablishedView();
logger.info("testBootstrap: end");
}
use of org.apache.sling.discovery.TopologyEvent in project sling by apache.
the class TestInitDelayingTopologyEventListener method testConstructor.
@Test
public void testConstructor() throws Exception {
final TopologyEventListener delegate = new TopologyEventListener() {
@Override
public void handleTopologyEvent(TopologyEvent event) {
// nothing here atm
}
};
final Scheduler scheduler = createScheduler();
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
}
use of org.apache.sling.discovery.TopologyEvent in project sling by apache.
the class DiscoveryWithSyncTokenTest method testTwoNodes.
@Test
public void testTwoNodes() throws Throwable {
logger.info("testTwoNodes: start");
FullJR2VirtualInstanceBuilder b1 = new FullJR2VirtualInstanceBuilder();
b1.setDebugName("i1").newRepository("/var/twon/", true);
b1.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
VirtualInstance i1 = b1.build();
instances.add(i1);
i1.bindTopologyEventListener(new TopologyEventListener() {
@Override
public void handleTopologyEvent(TopologyEvent event) {
logger.info("GOT EVENT: " + event);
}
});
FullJR2VirtualInstanceBuilder b2 = new FullJR2VirtualInstanceBuilder();
b2.setDebugName("i2").useRepositoryOf(i1);
b2.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
VirtualInstance i2 = b2.build();
instances.add(i2);
i1.heartbeatsAndCheckView();
i2.heartbeatsAndCheckView();
i1.heartbeatsAndCheckView();
i2.heartbeatsAndCheckView();
Thread.sleep(999);
//TODO: finalize test
}
Aggregations