use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class ITMDCFilter method startContainer.
@Before
public void startContainer() throws Exception {
if (testContainer == null) {
ServerConfiguration sc = new ServerConfiguration();
ExamSystem system = DefaultExamSystem.create(sc.config());
testContainer = PaxExamRuntime.createContainer(system);
testContainer.start();
new RetryLoop(new RetryLoop.Condition() {
public String getDescription() {
return "Check if MDCTestServlet is up";
}
public boolean isTrue() throws Exception {
RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
executor.execute(rb.buildGetRequest("/mdc")).assertStatus(200);
rb = new RequestBuilder(ServerConfiguration.getServerUrl());
//Create test config via servlet
executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true"));
TimeUnit.SECONDS.sleep(1);
return true;
}
}, 5, 100);
}
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class ClassloadingTest method testFailedClassloading.
@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testFailedClassloading() throws Exception {
final AtomicInteger failedJobsCount = new AtomicInteger(0);
final List<Event> finishedEvents = Collections.synchronizedList(new ArrayList<Event>());
this.registerJobConsumer(TOPIC + "/failed", new JobConsumer() {
@Override
public JobResult process(Job job) {
failedJobsCount.incrementAndGet();
return JobResult.OK;
}
});
this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED, new EventHandler() {
@Override
public void handleEvent(Event event) {
finishedEvents.add(event);
}
});
final JobManager jobManager = this.getJobManager();
// dao is an invisible class for the dynamic class loader as it is not public
// therefore scheduling this job should fail!
final DataObject dao = new DataObject();
// we start a single job
final Map<String, Object> props = new HashMap<String, Object>();
props.put("dao", dao);
final String id = jobManager.addJob(TOPIC + "/failed", props).getId();
try {
// wait until the conditions are met
new RetryLoop(new RetryLoop.Condition() {
@Override
public boolean isTrue() throws Exception {
return failedJobsCount.get() == 0 && finishedEvents.size() == 0 && jobManager.findJobs(JobManager.QueryType.ALL, TOPIC + "/failed", -1, (Map<String, Object>[]) null).size() == 1 && jobManager.getStatistics().getNumberOfQueuedJobs() == 0 && jobManager.getStatistics().getNumberOfActiveJobs() == 0;
}
@Override
public String getDescription() {
return "Waiting for job failure to be recorded. Conditions " + "faildJobsCount=" + failedJobsCount.get() + ", finishedEvents=" + finishedEvents.size() + ", findJobs= " + jobManager.findJobs(JobManager.QueryType.ALL, TOPIC + "/failed", -1, (Map<String, Object>[]) null).size() + ", queuedJobs=" + jobManager.getStatistics().getNumberOfQueuedJobs() + ", activeJobs=" + jobManager.getStatistics().getNumberOfActiveJobs();
}
}, CONDITION_TIMEOUT_SECONDS, CONDITION_INTERVAL_MILLIS);
// moves the job to the history section
jobManager.removeJobById(id);
assertEquals(0, jobManager.findJobs(JobManager.QueryType.ALL, TOPIC + "/failed", -1, (Map<String, Object>[]) null).size());
} finally {
// removes the job permanently
jobManager.removeJobById(id);
}
}
use of org.apache.sling.testing.tools.retry.RetryLoop in project sling by apache.
the class JspScriptingTest method testChangingJsp.
/* Verify that overwriting a JSP script changes the output within a reasonable time
* (might not be immediate as there's some observation and caching involved) */
@Test
public void testChangingJsp() throws Exception {
String toDelete = null;
try {
final String[] scripts = { "jsp1.jsp", "jsp2.jsp" };
for (String script : scripts) {
toDelete = H.uploadTestScript(unstructuredNode.scriptPath, script, "html.jsp");
final String expected = "text from " + script + ":" + unstructuredNode.testText;
final Condition c = new Condition() {
public String getDescription() {
return "Expecting " + expected;
}
public boolean isTrue() throws Exception {
final String content = H.getContent(unstructuredNode.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
return content.contains(expected);
}
};
new RetryLoop(c, CHECK_CONTENT_TIMEOUT_SECONDS, CHECK_CONTENT_INTERVAL_MSEC);
}
} finally {
if (toDelete != null) {
H.getTestClient().delete(toDelete);
}
}
}
Aggregations