use of alma.acs.pubsubtest.config.SimpleLoggingSpecT in project ACS by ACS-Community.
the class PubSubExecutor method execute.
/**
* Run the specified pub/sub container and components.
* If this method gets called directly (and not by {@link #execute(PubSubScenario)},
* the executionTime parameter can overwrite the timeout setting from the XML, or can
* set a timeout complementary to a finite <code>PubSubSpecCommonT#numberOfEvents</code>.
*/
public void execute(PubSubScenario scenario, long executionTimeMax, TimeUnit executionTimeMaxUnit) throws Throwable {
PubSubInfrastructureSpec pubSubSpec = scenario.getSpec();
m_logger.info("Will execute test with description:\n" + pubSubSpec.getTestDescription());
SimpleLoggingSpecT loggingSpec = (pubSubSpec.getLogging() != null ? pubSubSpec.getLogging() : defaultLoggingSpec);
AcsLogLevelDefinition levelDefaultLocal = AcsLogLevelDefinition.fromInteger(loggingSpec.getDefaultLevelMinLocal());
AcsLogLevelDefinition levelDefault = AcsLogLevelDefinition.fromInteger(loggingSpec.getDefaultLevelMin());
AcsLogLevelDefinition levelJacORB = AcsLogLevelDefinition.fromInteger(loggingSpec.getJacorbLevelMin());
List<Throwable> errors = new ArrayList<Throwable>();
try {
for (ContainerSpecT containerSpec : pubSubSpec.getContainer()) {
// start containers sequentially (TODO: with thread pool)
String host = (containerSpec.getHostName() != null ? containerSpec.getHostName() : localhostName);
String containerName = containerSpec.getContainerName();
m_logger.fine("about to start container " + containerName + " on host " + (host == null ? "localhost" : host));
ContainerImplLangType implLang = ContainerImplLangType.valueOf(containerSpec.getImplLang().toString());
containerUtil.startContainer(host, implLang, containerName, null, true);
// configure container log levels
ContainerLogLevelSpec contLogLevelSpec = new ContainerLogLevelSpec(levelDefault, levelDefaultLocal);
contLogLevelSpec.addNamedLoggerSpec("jacorb@" + containerName, levelJacORB, levelJacORB);
containerUtil.setContainerLogLevels(containerName, contLogLevelSpec);
m_logger.info("started container " + containerName + " on host " + (host == null ? "localhost" : host));
}
} catch (Throwable thr) {
errors.add(thr);
}
boolean allPubSubHaveFiniteEvents = true;
ExecutorService pubSubExec = Executors.newCachedThreadPool(getContainerServices().getThreadFactory());
if (errors.isEmpty()) {
for (final SubscriberSpecT subSpec : pubSubSpec.getSubscriber()) {
boolean subIsBlocking = isBlocking(subSpec);
if (!subIsBlocking) {
allPubSubHaveFiniteEvents = false;
}
ImplLangT implLang = deriveComponentImplLang(subSpec, pubSubSpec);
// TODO: pack this into one call, now that the comp will fail on the second call !!!
if (componentAccessUtil.getCachedComponentNames().contains(subSpec.getComponentName())) {
m_logger.info("Multiple subscribers specified for component " + subSpec.getComponentName() + ". This is legal, but unusual. Some values may be overwritten.");
}
CorbaNotifyConsumerOperations subscriberComp = componentAccessUtil.getDynamicSubscriberComponent(subSpec.getComponentName(), subSpec.getContainerName(), implLang);
if (subSpec.hasLogMultiplesOfEventCount()) {
subscriberComp.setEventLogging(subSpec.getLogMultiplesOfEventCount());
}
PubSubRunner runner = new PubSubRunner(subSpec, subscriberComp, pubSubExec, m_logger) {
@Override
protected Integer callSpecific(NcEventSpec eventSpec, int numEvents) throws CouldntPerformActionEx {
logger.info("About to call subscriber#receiveEvents...");
int processingDelay = (subSpec.hasProcessingDelayMillis() ? subSpec.getProcessingDelayMillis() : -1);
return ((CorbaNotifyConsumerOperations) pubSubComp).receiveEvents(new NcEventSpec[] { eventSpec }, processingDelay, numEvents);
}
};
try {
runner.runPubSub();
} catch (Exception ex) {
errors.add(ex);
}
}
// to "ensure" that even the asynchronously called subscribers are ready before we publish events
Thread.sleep(100);
for (final PublisherSpecT pubSpec : pubSubSpec.getPublisher()) {
boolean pubIsBlocking = isBlocking(pubSpec);
if (!pubIsBlocking) {
allPubSubHaveFiniteEvents = false;
}
ImplLangT implLang = deriveComponentImplLang(pubSpec, pubSubSpec);
// (which will result in multiple NCPublisher instances created by that component).
if (componentAccessUtil.getCachedComponentNames().contains(pubSpec.getComponentName())) {
m_logger.info("Multiple publishers specified for component " + pubSpec.getComponentName() + ". This is legal, but unusual. Some values may be overwritten.");
}
CorbaNotifySupplierOperations publisherComp = componentAccessUtil.getDynamicSupplierComponent(pubSpec.getComponentName(), pubSpec.getContainerName(), implLang);
if (pubSpec.hasLogMultiplesOfEventCount()) {
publisherComp.setEventLogging(pubSpec.getLogMultiplesOfEventCount());
}
PubSubRunner runner = new PubSubRunner(pubSpec, publisherComp, pubSubExec, m_logger) {
@Override
protected Integer callSpecific(NcEventSpec eventSpec, int numEvents) throws CouldntPerformActionEx {
logger.info("About to call publisher#sendEvents...");
int eventPeriodMillis = (pubSpec.hasEventPeriodMillis() ? pubSpec.getEventPeriodMillis() : -1);
return ((CorbaNotifySupplierOperations) pubSubComp).sendEvents(new NcEventSpec[] { eventSpec }, eventPeriodMillis, numEvents);
}
};
try {
runner.runPubSub();
} catch (Exception ex) {
errors.add(ex);
}
}
}
// wait for NC scenario to execute
if (errors.isEmpty()) {
if (allPubSubHaveFiniteEvents) {
// wait for all suppliers and subscribers to finish, enforcing the timeout if applicable
// TODO: More options would be available if we stored the PubSubRunner instances in a list...
pubSubExec.shutdown();
if (executionTimeMax > 0) {
pubSubExec.awaitTermination(executionTimeMax, executionTimeMaxUnit);
} else {
// like Dornroeschen
pubSubExec.awaitTermination(100 * 365, TimeUnit.DAYS);
}
} else {
// even if some others should terminate by themselves
if (executionTimeMax > 0) {
try {
m_logger.info("Will sleep for " + executionTimeMax + " " + executionTimeMaxUnit.toString().toLowerCase() + "...");
executionTimeMaxUnit.sleep(executionTimeMax);
} catch (Exception ex) {
errors.add(ex);
}
// now also the finite suppliers/subscribers should be finished, but even if not they will get interrupted
// along with the infinite ones in the cleanup.
} else {
errors.add(new IllegalArgumentException("An execution time must be specified if some publisher or subscriber is configured with an infinite number of events. Terminating right away..."));
}
}
}
// cleanup
m_logger.info("Will clean up the pub/sub components...");
// interrupt and release all components
for (ACSComponentOperations comp : componentAccessUtil.getCachedComponents()) {
// we could avoid the casting if we keep a separate list of subscriber and supplier comps...
if (comp instanceof CorbaNotifyCompBaseOperations) {
CorbaNotifyCompBaseOperations pubSubComp = (CorbaNotifyCompBaseOperations) comp;
pubSubComp.ncDisconnect();
}
}
componentAccessUtil.releaseAllComponents(true);
// stop containers
for (ContainerSpecT containerSpec : pubSubSpec.getContainer()) {
try {
String host = (containerSpec.getHostName() != null ? containerSpec.getHostName() : localhostName);
String containerName = containerSpec.getContainerName();
m_logger.fine("about to stop container " + containerName + " on host " + (host == null ? "localhost" : host));
containerUtil.stopContainer(host, containerName);
m_logger.info("stopped container " + containerName + " on host " + (host == null ? "localhost" : host));
} catch (Throwable thr) {
errors.add(thr);
}
}
if (!errors.isEmpty()) {
m_logger.severe("There were " + errors.size() + " errors!");
throw errors.get(0);
}
}
Aggregations