jmsConnFactory = loadJmsFactory(getSysTest().getSpiClass(), factory.getFactorySettings());
setProviderMetaData(jmsConnFactory.createConnection().getMetaData(), getJmsClientProperties());
// Create performance sampler
PerformanceReportWriter writer = createPerfWriter();
writer.openReportWriter();
writer.writeProperties("jvmSettings", System.getProperties());
writer.writeProperties("testSystemSettings", ReflectionUtil.retrieveObjectProperties(getSysTest()));
writer.writeProperties("jmsFactorySettings", ReflectionUtil.retrieveObjectProperties(jmsConnFactory));
writer.writeProperties("jmsClientSettings", ReflectionUtil.retrieveObjectProperties(getJmsClientProperties()));
// set up performance samplers indicated by the user
List<PerformanceSampler> samplers = new ArrayList<>();
Set<String> requestedSamplers = getSysTest().getSamplersSet();
if (requestedSamplers.contains(JmsClientSystemProperties.SAMPLER_TP)) {
writer.writeProperties("tpSamplerSettings", ReflectionUtil.retrieveObjectProperties(tpSampler));
samplers.add(tpSampler);
}
if (requestedSamplers.contains(JmsClientSystemProperties.SAMPLER_CPU)) {
CpuSamplerTask cpuSampler = new CpuSamplerTask();
writer.writeProperties("cpuSamplerSettings", ReflectionUtil.retrieveObjectProperties(cpuSampler));
try {
cpuSampler.createPlugin();
samplers.add(cpuSampler);
} catch (IOException e) {
LOG.warn("Unable to start CPU sampler plugin. Reason: " + e.getMessage());
}
}
// spawn client threads
clientThreadGroup = new ThreadGroup(getSysTest().getClientPrefix() + " Thread Group");
int numClients = getSysTest().getNumClients();
final CountDownLatch clientCompletionLatch = new CountDownLatch(numClients);
for (int i = 0; i < numClients; i++) {
distributeDestinations(getSysTest().getDestDistro(), i, numClients, getSysTest().getTotalDests());
final String clientName = getSysTest().getClientPrefix() + i;
final int clientDestIndex = this.clientDestIndex;
final int clientDestCount = this.clientDestCount;
Thread t = new Thread(clientThreadGroup, new Runnable() {
@Override
public void run() {
runJmsClient(clientName, clientDestIndex, clientDestCount);
LOG.info("Client completed");
clientCompletionLatch.countDown();
}
});
t.setName(getSysTest().getClientPrefix() + i + " Thread");
t.start();
}
// start the samplers
final CountDownLatch samplerCompletionLatch = new CountDownLatch(requestedSamplers.size());
for (PerformanceSampler sampler : samplers) {
sampler.setPerfReportWriter(writer);
sampler.startSampler(samplerCompletionLatch, getClientRunBasis(), getClientRunDuration());
}
try {
// wait for the clients to finish
clientCompletionLatch.await();
LOG.debug("All clients completed");
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// if count-based, ramp-down time is not relevant, shut the samplers down
if (getClientRunBasis() == ClientRunBasis.count) {
for (PerformanceSampler sampler : samplers) {
sampler.finishSampling();
}
}
try {
LOG.debug("Waiting for samplers to shut down");
samplerCompletionLatch.await();
LOG.debug("All samplers completed");
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
writer.closeReportWriter();
}
}
}