final Map<String, AtomicLong> added = new HashMap<String, AtomicLong>();
final Map<String, AtomicLong> created = new HashMap<String, AtomicLong>();
final Map<String, AtomicLong> finished = new HashMap<String, AtomicLong>();
final List<String> topics = new ArrayList<String>();
for(int i=0;i<NUM_ORDERED_TOPICS;i++) {
added.put(ORDERED_TOPICS[i], new AtomicLong());
created.put(ORDERED_TOPICS[i], new AtomicLong());
finished.put(ORDERED_TOPICS[i], new AtomicLong());
topics.add(ORDERED_TOPICS[i]);
}
for(int i=0;i<NUM_PARALLEL_TOPICS;i++) {
added.put(PARALLEL_TOPICS[i], new AtomicLong());
created.put(PARALLEL_TOPICS[i], new AtomicLong());
finished.put(PARALLEL_TOPICS[i], new AtomicLong());
topics.add(PARALLEL_TOPICS[i]);
}
for(int i=0;i<NUM_ROUND_TOPICS;i++) {
added.put(ROUND_TOPICS[i], new AtomicLong());
created.put(ROUND_TOPICS[i], new AtomicLong());
finished.put(ROUND_TOPICS[i], new AtomicLong());
topics.add(ROUND_TOPICS[i]);
}
final List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
final List<Thread> threads = new ArrayList<Thread>();
final AtomicLong finishedThreads = new AtomicLong();
final ServiceRegistration eventHandler = this.registerEventHandler("org/apache/sling/event/notification/job/*",
new EventHandler() {
@Override
public void handleEvent(final Event event) {
final String topic = (String) event.getProperty(NotificationConstants.NOTIFICATION_PROPERTY_JOB_TOPIC);
if ( NotificationConstants.TOPIC_JOB_FINISHED.equals(event.getTopic())) {
finished.get(topic).incrementAndGet();
} else if ( NotificationConstants.TOPIC_JOB_ADDED.equals(event.getTopic())) {
added.get(topic).incrementAndGet();
}
}
});
try {
// setup job consumers
this.setupJobConsumers(registrations);
// setup job creation tests
this.setupJobCreationThreads(threads, jobManager, created, finishedThreads);
this.setupChaosThreads(threads, finishedThreads);
System.out.println("Starting threads...");
// start threads
for(final Thread t : threads) {
t.start();
}
System.out.println("Sleeping for " + DURATION + " seconds to wait for threads to finish...");
// for sure we can sleep for the duration
this.sleep(DURATION * 1000);
System.out.println("Polling for threads to finish...");
// wait until threads are finished
while ( finishedThreads.get() < threads.size() ) {
this.sleep(100);
}
System.out.println("Waiting for job handling to finish...");
final Set<String> allTopics = new HashSet<String>(topics);