use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class AbstractClusterLoadTest method doDoTest.
private void doDoTest(final int size, final int loopCnt) throws Throwable {
if (size < 2) {
fail("can only test 2 or more instances");
}
VirtualInstanceBuilder builder = newBuilder().newRepository("/var/discovery/impl/ClusterLoadTest/doTest-" + size + "-" + loopCnt + "/", true).setDebugName("firstInstance-" + size + "_" + loopCnt).setConnectorPingTimeout(3).setConnectorPingInterval(20).setMinEventDelay(0);
VirtualInstance firstInstance = builder.build();
firstInstance.startViewChecker(1);
instances.add(firstInstance);
for (int i = 1; i < size; i++) {
VirtualInstanceBuilder builder2 = newBuilder().useRepositoryOf(builder).setDebugName("subsequentInstance-" + i + "-" + size + "_" + loopCnt).setConnectorPingTimeout(3).setMinEventDelay(0).setConnectorPingInterval(20);
VirtualInstance subsequentInstance = builder2.build();
instances.add(subsequentInstance);
subsequentInstance.startViewChecker(1);
}
for (int i = 0; i < loopCnt; i++) {
logger.info("=====================");
logger.info(" START of LOOP " + i);
logger.info("=====================");
// count how many instances had heartbeats running in the first place
int aliveCnt = 0;
for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
VirtualInstance instance = it.next();
if (instance.isViewCheckerRunning()) {
aliveCnt++;
}
}
logger.info("=====================");
logger.info(" original aliveCnt " + aliveCnt);
logger.info("=====================");
if (aliveCnt == 0) {
// if no one is sending heartbeats, all instances go back to isolated mode
aliveCnt = 1;
}
final int aliveCntFinal = aliveCnt;
for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
VirtualInstance instance = it.next();
try {
instance.dumpRepo();
} catch (Exception e) {
logger.error("Failed dumping repo for instance " + instance.getSlingId(), e);
}
}
// then verify that each instance sees that many instances
for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
final VirtualInstance instance = it.next();
if (!instance.isViewCheckerRunning()) {
// if the heartbeat is not running, this instance is considered dead
// hence we're not doing any assert here (as the count is only
// valid if heartbeat/checkView is running and that would void the test)
} else {
new RetryLoop(new ConditionImplementation(instance, aliveCntFinal), INSTANCE_VIEW_TIMEOUT_SECONDS, INSTANCE_VIEW_POLL_INTERVAL_MILLIS);
}
}
// start/stop heartbeats accordingly
logger.info("Starting/Stopping heartbeats with count=" + instances.size());
for (Iterator<VirtualInstance> it = instances.iterator(); it.hasNext(); ) {
VirtualInstance instance = it.next();
if (random.nextBoolean()) {
logger.info("Starting heartbeats with " + instance.slingId);
instance.startViewChecker(1);
logger.info("Started heartbeats with " + instance.slingId);
} else {
logger.info("Stopping heartbeats with " + instance.slingId);
instance.stopViewChecker();
logger.info("Stopped heartbeats with " + instance.slingId);
}
}
}
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class EventsCounterUtil method waitForEvent.
public static void waitForEvent(final HttpTestBase b, final String topic, int timeoutSeconds, final int previousCount) {
final Condition c = new Condition() {
public String getDescription() {
return "Wait for OSGi event on topic " + topic;
}
public boolean isTrue() throws Exception {
return getEventsCount(b, topic) > previousCount;
}
};
new RetryLoop(c, timeoutSeconds, 500);
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class HtmlDefaultServletTest method tearDown.
@Override
protected void tearDown() throws Exception {
// disable the HtmlDefaultServlet after testing
Map<String, String> properties = new HashMap<String, String>();
properties.put("apply", "true");
properties.put("delete", "true");
assertEquals(200, testClient.post(CONFIG_SERVLET, properties));
// Verify that our test servlet is gone
final String url = testNodeNORT.nodeUrl + ".html";
final Condition c = new Condition() {
public String getDescription() {
return url + " is not served by a test servlet";
}
public boolean isTrue() throws Exception {
assertNotTestServlet(getContent(url, CONTENT_TYPE_HTML));
return true;
}
};
new RetryLoop(c, 10, 100);
// forces an async reregistration of the resource resolver factory
try {
Thread.sleep(3000);
} catch (final InterruptedException ie) {
// ignore
}
super.tearDown();
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class HtmlDefaultServletTest method testHtmlExtension.
public void testHtmlExtension() throws IOException {
final String url = testNodeNORT.nodeUrl + ".html";
final Condition c = new Condition() {
public String getDescription() {
return url + " returns plain text";
}
public boolean isTrue() throws Exception {
assertServlet(getContent(url, CONTENT_TYPE_PLAIN), HTML_DEFAULT_SERVLET_SUFFIX);
return true;
}
};
new RetryLoop(c, 10, 100);
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class HtmlDefaultServletTest method testJsonExtension.
public void testJsonExtension() throws IOException {
final String url = testNodeNORT.nodeUrl + ".json";
final Condition c = new Condition() {
public String getDescription() {
return url + " returns JSON";
}
public boolean isTrue() throws Exception {
assertNotTestServlet(getContent(url, CONTENT_TYPE_DONTCARE));
return true;
}
};
new RetryLoop(c, 10, 100);
}
Aggregations