Search in sources :

Example 16 with StopWatch

use of alma.acs.util.StopWatch in project ACS by ACS-Community.

the class ClearCacheTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // ACSPorts.getCDBPort() + "/CDB";
    String rdbIOR = "corbaloc::" + ACSPorts.getIP() + ":" + "3012/CDB";
    // ACSPorts.getCDBPort() + "/CDB";
    String xmlIOR = "corbaloc::" + ACSPorts.getIP() + ":" + "3013/CDB";
    String[] args = {};
    logger = Logger.getAnonymousLogger();
    Properties props = new Properties();
    props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
    props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
    orb = ORB.init(args, props);
    rdbDAL = JDALHelper.narrow(orb.string_to_object(rdbIOR));
    rdbAccess = new CDBAccess(orb, logger);
    rdbAccess.setDAL(rdbDAL);
    xmlDAL = JDALHelper.narrow(orb.string_to_object(xmlIOR));
    xmlAccess = new CDBAccess(orb, logger);
    xmlAccess.setDAL(xmlDAL);
    after = new String[] { "fubar", "snafu" };
    String[] rdbNodes = rdbDAL.list_nodes("MACI/Managers").split(" ");
    if (rdbNodes.length == 0)
        fail("No Manager nodes present.");
    firstNode = "MACI/Managers/" + rdbNodes[0];
    rdbDao = rdbDAL.get_DAO_Servant(firstNode);
    xmlDao = xmlDAL.get_DAO_Servant(firstNode);
    sw = new StopWatch(logger);
    before = rdbDao.get_string_seq("Startup");
    xbefore = xmlDao.get_string_seq("Startup");
    wdal = WDALHelper.narrow(rdbDAL);
    wdao = wdal.get_WDAO_Servant(firstNode);
    xmlWdal = WDALHelper.narrow(xmlDAL);
    xmlWdao = xmlWdal.get_WDAO_Servant(firstNode);
}
Also used : CDBAccess(com.cosylab.cdb.client.CDBAccess) Properties(java.util.Properties) StopWatch(alma.acs.util.StopWatch)

Example 17 with StopWatch

use of alma.acs.util.StopWatch in project ACS by ACS-Community.

the class CorbaNotifySupplierImpl method sendEvents.

@Override
public int sendEvents(NcEventSpec[] ncEventSpecs, int eventPeriodMillis, int numberOfEvents) throws CouldntPerformActionEx {
    if (cancel) {
        AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx("Method sendEvents cannot be called after interrupt / ncDisconnect.");
        throw ex.toCouldntPerformActionEx();
    }
    StopWatch sw = null;
    ScheduledThreadPoolExecutor runner = null;
    // Set up the runnables for all NCs
    try {
        for (NcEventSpec ncEventSpec : ncEventSpecs) {
            PublishEventRunnable runnable = new PublishEventRunnable(ncEventSpec, this.subsOrPubs.get(ncEventSpec.ncName), numberOfEvents);
            runnables.add(runnable);
        }
        // multithreaded executor
        runner = new ScheduledThreadPoolExecutor(// thread per NC
        ncEventSpecs.length, m_containerServices.getThreadFactory(), //RejectedExecutionException
        new AbortPolicy());
        sw = new StopWatch();
        // run the NC suppliers
        for (PublishEventRunnable runnable : runnables) {
            ScheduledFuture<?> future = null;
            if (eventPeriodMillis > 0) {
                // publish at fixed rate
                future = runner.scheduleAtFixedRate(runnable, 0, eventPeriodMillis, TimeUnit.MILLISECONDS);
            } else {
                // run continuously 
                // delay must be > 0, otherwise IllegalArgumentException
                future = runner.scheduleWithFixedDelay(runnable, 0, 1, TimeUnit.NANOSECONDS);
            }
            runnable.setScheduledFuture(future);
        }
    } catch (Exception ex) {
        m_logger.log(AcsLogLevel.SEVERE, "sendEvents call failed", ex);
        throw new AcsJCouldntPerformActionEx(ex).toCouldntPerformActionEx();
    }
    String msgBase = "Started publishing events on " + ncEventSpecs.length + " NC(s), sending events " + (eventPeriodMillis > 0 ? "every " + eventPeriodMillis + " ms. " : "as fast as possible. ");
    if (numberOfEvents > 0) {
        m_logger.info(msgBase + "Will now wait until " + numberOfEvents + " have been published on every NC...");
        // block until all events are sent
        runner.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
        runner.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
        runner.shutdown();
        try {
            // 10 min timeout, just to clean up resources eventually.
            // TODO: Offer a workaround for special long-running tests
            boolean cleanTermination = runner.awaitTermination(10, TimeUnit.MINUTES);
            if (!cleanTermination) {
                m_logger.warning("Unforeseen termination of event suppliers after 10 min (timeout).");
                cancel = true;
            }
        } catch (InterruptedException ex) {
            cancel = true;
        }
    } else {
        runnersToInterrupt.add(runner);
        m_logger.info(msgBase + "Will return and asynchronously continue publishing events, until interrupt() gets called.");
    }
    if (cancel) {
        throw new AcsJCouldntPerformActionEx("Event sending was interrupted or failed otherwise.").toCouldntPerformActionEx();
    }
    return (int) sw.getLapTimeMillis();
}
Also used : AbortPolicy(java.util.concurrent.ThreadPoolExecutor.AbortPolicy) AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NcEventSpec(alma.benchmark.NcEventSpec) AcsJException(alma.acs.exceptions.AcsJException) StopWatch(alma.acs.util.StopWatch)

Example 18 with StopWatch

use of alma.acs.util.StopWatch in project ACS by ACS-Community.

the class ContainerLoggingAlarmTest method testLogOverflowNoThrottle.

/**
	 */
@Test
public void testLogOverflowNoThrottle() throws Exception {
    String compName = "TestcompJavaUnthrottled";
    int numLogs = 10000;
    // The level must be INFO or higher so that it gets dropped only when the queue is 100% full.
    // DEBUG and below levels get dropped already at 70% full.
    AcsLogLevelDefinition level = AcsLogLevelDefinition.INFO;
    AlarmTestComponent comp = AlarmTestComponentHelper.narrow(getContainerServices().getComponent(compName));
    StopWatch sw = new StopWatch(m_logger);
    comp.logBurst((short) level.value, numLogs);
    sw.logLapTime("send " + numLogs + " " + level.name() + " logs from component " + compName, AcsLogLevel.INFO);
    // now send Debug logs at max speed, to check how they get dropped in the log queue
    numLogs = 1000;
    level = AcsLogLevelDefinition.DEBUG;
    comp.logBurst((short) level.value, numLogs);
    sw.logLapTime("send " + numLogs + " " + level.name() + " logs from component " + compName, AcsLogLevel.INFO);
    // sleep a bit so that the log queue can drain. This gives a chance to see the "no longer dropping" kind of message
    Thread.sleep(2000);
    comp.logBurst((short) level.value, numLogs);
    sw.logLapTime("send " + numLogs + " " + level.name() + " logs from component " + compName, AcsLogLevel.INFO);
    getContainerServices().releaseComponent(compName);
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) AlarmTestComponent(alma.alarmContainerTest.AlarmTestComponent) StopWatch(alma.acs.util.StopWatch) Test(org.junit.Test)

Example 19 with StopWatch

use of alma.acs.util.StopWatch in project ACS by ACS-Community.

the class ContainerLoggingAlarmTest method testLogThrottleAlarm.

@Test
public void testLogThrottleAlarm() throws Exception {
    int numLogs = 1000;
    AcsLogLevelDefinition level = AcsLogLevelDefinition.DEBUG;
    String compName = "TestcompJavaThrottled";
    AlarmTestComponent comp = AlarmTestComponentHelper.narrow(getContainerServices().getComponent(compName));
    StopWatch sw = new StopWatch(m_logger);
    comp.logBurst((short) level.value, numLogs);
    sw.logLapTime("send " + numLogs + " " + level.name() + " logs from component " + compName, AcsLogLevel.INFO);
    getContainerServices().releaseComponent(compName);
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) AlarmTestComponent(alma.alarmContainerTest.AlarmTestComponent) StopWatch(alma.acs.util.StopWatch) Test(org.junit.Test)

Example 20 with StopWatch

use of alma.acs.util.StopWatch in project ACS by ACS-Community.

the class EventSubscriberSmEngineTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    configureLogging(AcsLogLevelDefinition.INFO);
    StopWatch sw = new StopWatch();
    // we use empty handlers, except for environmentActionHandler
    actionHandler = new MyActionHandler();
    engine = new EventSubscriberStateMachine(logger, new EventSubscriberActionDispatcher(actionHandler, logger));
    // usually it's quite a bit faster, but for some reason the NRI test on te48 takes ~1.2 seconds
    assertThat("SM creation should take less than a 1.4 second.", sw.getLapTimeMillis(), lessThan(1400L));
}
Also used : EventSubscriberActionDispatcher(alma.acs.nc.sm.generated.EventSubscriberActionDispatcher) StopWatch(alma.acs.util.StopWatch) Before(org.junit.Before)

Aggregations

StopWatch (alma.acs.util.StopWatch)40 ArrayList (java.util.ArrayList)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AcsJException (alma.acs.exceptions.AcsJException)4 Test (org.junit.Test)4 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)3 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 HashMap (java.util.HashMap)3 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)2 AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)2 AlarmTestComponent (alma.alarmContainerTest.AlarmTestComponent)2 NcEventSpec (alma.benchmark.NcEventSpec)2 DummyComponent (alma.jconttest.DummyComponent)2 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)2 EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)2 TDEM_TOPICS.actuatorSpace (tdem.TDEM_TOPICS.actuatorSpace)2 TDEM_TOPICS.pttDataEvent (tdem.TDEM_TOPICS.pttDataEvent)2 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)1