Search in sources :

Example 1 with CorbaNotifySupplierOperations

use of alma.benchmark.CorbaNotifySupplierOperations in project ACS by ACS-Community.

the class LocalPubSubTest method testOneSupplierNoSubscriber.

/**
	 * Publishes 10.000 "MountStatusData" events on the NC "CONTROL_REALTIME", 
	 * using a single supplier component "JavaSupplier-1" for sequential publishing at maximum rate.
	 * The call to the supplier component is synchronous, returning when all events are published. 
	 * This allows us to measure the the publishing performance without sync'ing up through a subscriber.
	 */
@Test
public void testOneSupplierNoSubscriber() throws Exception {
    final int numEvents = 10000;
    CorbaNotifySupplierOperations supplierComp = null;
    try {
        // Create dynamic supplier component
        String componentName = "JavaSupplier-1";
        supplierComp = componentAccessUtil.getDynamicSupplierComponent(componentName, supplierContainerName, ImplLangT.JAVA);
        // supplier setup
        String[] ncNames = new String[] { CHANNELNAME_CONTROL_REALTIME.value };
        supplierComp.ncConnect(ncNames);
        m_logger.info("Connected to NC " + ncNames[0]);
        NcEventSpec[] ncEventSpecs = new NcEventSpec[] { new NcEventSpec(ncNames[0], new String[] { "MountStatusData" }, // don't care about antenna name here
        "") };
        // Let publisher component publish these events
        int callTimeInternalMillis = supplierComp.sendEvents(ncEventSpecs, -1, numEvents);
        m_logger.info("Single supplier comp '" + componentName + "' sent " + numEvents + " MountStatusData events at max speed to NC '" + ncNames[0] + "' in " + callTimeInternalMillis + " ms.");
        assertThat("Expecting at most 4 ms for publishing an event to a NotifyService.", callTimeInternalMillis, lessThanOrEqualTo(numEvents * 4));
    } finally {
        // clean up
        if (supplierComp != null)
            supplierComp.ncDisconnect();
        if (componentAccessUtil != null)
            componentAccessUtil.releaseAllComponents(true);
    }
}
Also used : CorbaNotifySupplierOperations(alma.benchmark.CorbaNotifySupplierOperations) NcEventSpec(alma.benchmark.NcEventSpec) Test(org.junit.Test)

Example 2 with CorbaNotifySupplierOperations

use of alma.benchmark.CorbaNotifySupplierOperations 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);
    }
}
Also used : CorbaNotifyConsumerOperations(alma.benchmark.CorbaNotifyConsumerOperations) ImplLangT(alma.acs.pubsubtest.config.types.ImplLangT) ACSComponentOperations(alma.ACS.ACSComponentOperations) ContainerSpecT(alma.acs.pubsubtest.config.ContainerSpecT) CorbaNotifySupplierOperations(alma.benchmark.CorbaNotifySupplierOperations) NcEventSpec(alma.benchmark.NcEventSpec) ArrayList(java.util.ArrayList) CorbaNotifyCompBaseOperations(alma.benchmark.CorbaNotifyCompBaseOperations) PubSubInfrastructureSpec(alma.acs.pubsubtest.config.PubSubInfrastructureSpec) SimpleLoggingSpecT(alma.acs.pubsubtest.config.SimpleLoggingSpecT) ContainerImplLangType(alma.maci.containerconfig.types.ContainerImplLangType) PublisherSpecT(alma.acs.pubsubtest.config.PublisherSpecT) SubscriberSpecT(alma.acs.pubsubtest.config.SubscriberSpecT) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) ExecutorService(java.util.concurrent.ExecutorService) ContainerLogLevelSpec(acs.benchmark.util.ContainerUtil.ContainerLogLevelSpec)

Example 3 with CorbaNotifySupplierOperations

use of alma.benchmark.CorbaNotifySupplierOperations in project ACS by ACS-Community.

the class LocalPubSubTest method testOneSupplierOneSubscriberMixedEvents.

/**
	 * Publishes >= 200 "MountStatusData" or "LightweightMountStatusData" events on the NC "CONTROL_REALTIME", 
	 * using a single supplier component "JavaSupplier-1" for sequential publishing at a rate of 1 events every 48 ms,
	 * and a single subscriber component "JavaSubscriber" for counting the events.
	 * The call to the supplier component is asynchronous, returning while the publisher runs in "indefinite publishing" mode. 
	 * Once the subscriber has received enough data, we terminate the supplier. 
	 */
@Test
public void testOneSupplierOneSubscriberMixedEvents() throws Throwable {
    final int numEvents = 200;
    final int eventPeriodMillis = 48;
    String[] ncNames = new String[] { CHANNELNAME_CONTROL_REALTIME.value };
    // mixed events spec
    final NcEventSpec[] ncEventSpecs = new NcEventSpec[] { new NcEventSpec(ncNames[0], new String[] { "MountStatusData", "LightweightMountStatusData" }, // don't care about antenna name here
    "") };
    // Create, configure and activate dynamic subscriber component.
    // It must be running before we publish events, to make sure we don't lose any.
    String subscriberContainerName = "localSubscriberContainer1";
    String subscriberComponentName = "JavaSubscriber-1";
    try {
        containerUtil.startContainer(localhostName, ContainerImplLangType.JAVA, subscriberContainerName, null, true);
        final CorbaNotifyConsumerOperations subscriberComp = componentAccessUtil.getDynamicSubscriberComponent(subscriberComponentName, subscriberContainerName, ImplLangT.JAVA);
        subscriberComp.ncConnect(ncNames);
        m_logger.info("Connected subscriber to NC " + ncNames[0]);
        Callable<Integer> runSubscriber = new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                m_logger.info("About to call subscriber#receiveEvents in a separate thread...");
                return subscriberComp.receiveEvents(ncEventSpecs, 0, numEvents);
            }
        };
        Future<Integer> subscriberCallFuture = singThrExec.submit(runSubscriber);
        // to "ensure" that the subscriber is ready before we publish events 
        Thread.sleep(100);
        // Create dynamic supplier component
        String componentName = "JavaSupplier-1";
        CorbaNotifySupplierOperations supplierComp = componentAccessUtil.getDynamicSupplierComponent(componentName, supplierContainerName, ImplLangT.JAVA);
        // supplier setup
        supplierComp.ncConnect(ncNames);
        m_logger.info("Connected supplier to NC " + ncNames[0] + ". Will now send ~" + numEvents + " events, one every " + eventPeriodMillis + " ms.");
        // Let publisher component publish events as long as it takes for the subscriber to get enough of them 
        supplierComp.sendEvents(ncEventSpecs, eventPeriodMillis, -1);
        int subscriberReceptionTimeMillis = subscriberCallFuture.get(60, TimeUnit.SECONDS);
        m_logger.info("Subscriber component done. It received " + numEvents + " events in " + subscriberReceptionTimeMillis + " ms.");
        int expectedReceptionTimeMillis = numEvents * eventPeriodMillis;
        assertThat("It should have taken around " + expectedReceptionTimeMillis + " ms to receive the events.", subscriberReceptionTimeMillis, is(both(greaterThan((int) (0.90 * expectedReceptionTimeMillis))).and(lessThan((int) (1.1 * expectedReceptionTimeMillis)))));
        // stop supplier (it was in 'infinite' sending mode)
        supplierComp.interrupt();
    } catch (CouldntPerformActionEx ex) {
        throw AcsJCouldntPerformActionEx.fromCouldntPerformActionEx(ex);
    } catch (ExecutionException ex) {
        Throwable ex2 = ex.getCause();
        if (ex2 instanceof CouldntPerformActionEx) {
            throw AcsJCouldntPerformActionEx.fromCouldntPerformActionEx((CouldntPerformActionEx) ex2);
        } else {
            throw ex2;
        }
    } finally {
        componentAccessUtil.releaseComponent(subscriberComponentName, true);
        containerUtil.stopContainer(localhostName, subscriberContainerName);
    // for supplier component and container we trust the tearDown method..
    }
}
Also used : CorbaNotifyConsumerOperations(alma.benchmark.CorbaNotifyConsumerOperations) CorbaNotifySupplierOperations(alma.benchmark.CorbaNotifySupplierOperations) NcEventSpec(alma.benchmark.NcEventSpec) Callable(java.util.concurrent.Callable) AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx) CouldntPerformActionEx(alma.ACSErrTypeCommon.CouldntPerformActionEx) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

CorbaNotifySupplierOperations (alma.benchmark.CorbaNotifySupplierOperations)3 NcEventSpec (alma.benchmark.NcEventSpec)3 CorbaNotifyConsumerOperations (alma.benchmark.CorbaNotifyConsumerOperations)2 Test (org.junit.Test)2 ContainerLogLevelSpec (acs.benchmark.util.ContainerUtil.ContainerLogLevelSpec)1 ACSComponentOperations (alma.ACS.ACSComponentOperations)1 CouldntPerformActionEx (alma.ACSErrTypeCommon.CouldntPerformActionEx)1 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)1 AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)1 ContainerSpecT (alma.acs.pubsubtest.config.ContainerSpecT)1 PubSubInfrastructureSpec (alma.acs.pubsubtest.config.PubSubInfrastructureSpec)1 PublisherSpecT (alma.acs.pubsubtest.config.PublisherSpecT)1 SimpleLoggingSpecT (alma.acs.pubsubtest.config.SimpleLoggingSpecT)1 SubscriberSpecT (alma.acs.pubsubtest.config.SubscriberSpecT)1 ImplLangT (alma.acs.pubsubtest.config.types.ImplLangT)1 CorbaNotifyCompBaseOperations (alma.benchmark.CorbaNotifyCompBaseOperations)1 ContainerImplLangType (alma.maci.containerconfig.types.ContainerImplLangType)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1