Search in sources :

Example 1 with DaemonCallback

use of alma.acsdaemon.DaemonCallback in project ACS by ACS-Community.

the class ServicesDaemonTest method testStartAcsServiceIndividually.

/**
	 * Simple test that only uses the start_xxx and Stop_xxx methods of the daemon,
	 * which is one step up from the old acsStart method, but does not use the convenience
	 * of the service description. All services are started on the same host. Later they are stopped.
	 */
public void testStartAcsServiceIndividually() throws Throwable {
    DaemonCallbackImpl daemonCallbackImpl_1 = new DaemonCallbackImpl(logger);
    DaemonCallbackImpl daemonCallbackImpl_2 = new DaemonCallbackImpl(logger);
    DaemonCallbackImpl daemonCallbackImpl_3 = new DaemonCallbackImpl(logger);
    DaemonCallback dcb_1 = activateDaemonCallback(daemonCallbackImpl_1);
    DaemonCallback dcb_2 = activateDaemonCallback(daemonCallbackImpl_2);
    DaemonCallback dcb_3 = activateDaemonCallback(daemonCallbackImpl_3);
    List<Throwable> thrs = new ArrayList<Throwable>();
    try {
        // start naming service and wait till it's up
        daemonCallbackImpl_1.prepareWaitForDone("naming");
        daemon.start_naming_service(dcb_1, instanceNumber);
        assertTrue("Failed to start naming service in 10 s", daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS));
        logger.info("Got naming service");
        // start interface repository but don't wait for it yet ( start other services in parallel)
        daemonCallbackImpl_2.prepareWaitForDone("IFR");
        daemon.start_interface_repository(true, true, dcb_2, instanceNumber);
        // start CDB and wait till it's up
        daemonCallbackImpl_1.prepareWaitForDone("CDB");
        // TODO try explicit path ($ACS_CDB replacement)
        daemon.start_xml_cdb(dcb_1, instanceNumber, false, "");
        assertTrue("Failed to start CDB in 15 s", daemonCallbackImpl_1.waitForDone(15, TimeUnit.SECONDS));
        assertCDB();
        // start manager and wait till it's up
        daemonCallbackImpl_1.prepareWaitForDone("manager");
        daemon.start_manager("", dcb_1, instanceNumber, false);
        assertTrue("Failed to start the ACS manager in 10 s", daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS));
        assertManager();
        // now wait for the IR if necessary
        assertTrue("Failed to start interface repository 30 s after all other services have started", daemonCallbackImpl_2.waitForDone(30, TimeUnit.SECONDS));
        logger.info("Got the IFR");
        // start 3 of the 4 known notify services in parallel.
        // We want to call the start_notification_service method in parallel, which yields an even more parallel service start
        // than with calling this asynchronous method 3 times in a sequence.
        // @TODO Currently this test fails due to what seems a deadlock in the daemon. With just one NC factory it works, but with 3 we get a timeout.
        daemonCallbackImpl_1.prepareWaitForDone("NC factory default");
        daemonCallbackImpl_2.prepareWaitForDone("NC factory logging");
        daemonCallbackImpl_3.prepareWaitForDone("NC factory alarms");
        class NotifySrvStarter implements Callable<Void> {

            private final String srvName;

            private final DaemonCallback cb;

            NotifySrvStarter(String srvName, DaemonCallback cb) {
                this.srvName = srvName;
                this.cb = cb;
            }

            public Void call() throws Exception {
                daemon.start_notification_service(srvName, cb, instanceNumber);
                return null;
            }
        }
        ExecutorService pool = Executors.newFixedThreadPool(3, new DaemonThreadFactory());
        Future<Void> defaultNotifSrvFuture = pool.submit(new NotifySrvStarter(systemNotificationServiceDefault.value, dcb_1));
        Future<Void> loggingNotifSrvFuture = pool.submit(new NotifySrvStarter(systemNotificationServiceLogging.value, dcb_2));
        Future<Void> alarmNotifSrvFuture = pool.submit(new NotifySrvStarter(systemNotificationServiceAlarms.value, dcb_3));
        try {
            defaultNotifSrvFuture.get(20, TimeUnit.SECONDS);
            loggingNotifSrvFuture.get(20, TimeUnit.SECONDS);
            alarmNotifSrvFuture.get(20, TimeUnit.SECONDS);
        } catch (ExecutionException ex) {
            // throw the ex that came from the call() method
            throw ex.getCause();
        } catch (TimeoutException ex2) {
            fail("Failed to return from 'start_notification_service' within 20 seconds. ");
        }
        // now wait for the notification services to be actually started
        daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS);
        daemonCallbackImpl_2.waitForDone(10, TimeUnit.SECONDS);
        daemonCallbackImpl_3.waitForDone(10, TimeUnit.SECONDS);
    } catch (Throwable thr) {
        thrs.add(thr);
    } finally {
        // and then waiting for the asynch calls to finish.
        try {
            daemonCallbackImpl_1.prepareWaitForDone("stop NC factory default");
            daemon.stop_notification_service(systemNotificationServiceDefault.value, dcb_1, instanceNumber);
        } catch (Throwable thr) {
            thrs.add(thr);
        }
        try {
            daemonCallbackImpl_2.prepareWaitForDone("stop NC factory logging");
            daemon.stop_notification_service(systemNotificationServiceLogging.value, dcb_2, instanceNumber);
        } catch (Throwable thr) {
            thrs.add(thr);
        }
        try {
            daemonCallbackImpl_3.prepareWaitForDone("stop NC factory alarms");
            daemon.stop_notification_service(systemNotificationServiceAlarms.value, dcb_3, instanceNumber);
        } catch (Throwable thr) {
            thrs.add(thr);
        }
        try {
            assertTrue("Failed to stop the default NC factory in 10 s", daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS));
            assertTrue("Failed to stop the logging NC factory in 10 s", daemonCallbackImpl_2.waitForDone(10, TimeUnit.SECONDS));
            assertTrue("Failed to stop the logging NC factory in 10 s", daemonCallbackImpl_3.waitForDone(10, TimeUnit.SECONDS));
        } catch (Throwable thr) {
            thrs.add(thr);
        }
        // stop the IFR
        try {
            daemonCallbackImpl_1.prepareWaitForDone("stop IFR");
            daemon.stop_interface_repository(dcb_1, instanceNumber);
            assertTrue("Failed to stop the interface repository in 10 s", daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS));
        } catch (Throwable thr) {
            thrs.add(thr);
        }
        // stop the manager
        try {
            daemonCallbackImpl_1.prepareWaitForDone("stop manager");
            daemon.stop_manager("", dcb_1, instanceNumber);
            assertTrue("Failed to stop the manager in 10 s", daemonCallbackImpl_1.waitForDone(10, TimeUnit.SECONDS));
        } catch (Throwable thr) {
            thrs.add(thr);
        }
    }
    if (thrs.size() > 0) {
        logger.info("Failure: there were " + thrs.size() + " errors.");
        throw thrs.get(0);
    }
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) DaemonCallback(alma.acsdaemon.DaemonCallback) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with DaemonCallback

use of alma.acsdaemon.DaemonCallback in project ACS by ACS-Community.

the class ServicesDaemonTest method testStartServiceTwice.

/**
	 * Test starting service twice. It must return ServiceAlreadyRunning exception (immediately or via callback). 
	 */
public void testStartServiceTwice() throws Exception {
    DaemonCallbackImpl daemonCallbackImpl = new DaemonCallbackImpl(logger);
    DaemonCallback dcb = activateDaemonCallback(daemonCallbackImpl);
    // start naming service and wait till it's up
    daemonCallbackImpl.prepareWaitForDone("naming");
    daemon.start_naming_service(dcb, instanceNumber);
    assertTrue("Failed to start naming service in 10 s", daemonCallbackImpl.waitForDone(10, TimeUnit.SECONDS));
    assertNamingService(true);
    try {
        // now start it again
        daemonCallbackImpl.prepareWaitForDone("naming");
        daemon.start_naming_service(dcb, instanceNumber);
        assertTrue("Failed to get reply about starting of second naming service within 10 s", daemonCallbackImpl.waitForDone(10, TimeUnit.SECONDS));
        // error via callback?
        if (daemonCallbackImpl.getLastDoneCompletion().type != alma.ACSErr.acsdaemonErrType.value || daemonCallbackImpl.getLastDoneCompletion().code != alma.acsdaemonErrType.ServiceAlreadyRunning.value)
            fail("Expected ServiceAlreadyRunningEx when starting naming service twice.");
    } catch (ServiceAlreadyRunningEx ex) {
        // good
        logger.info("Got expected ServiceAlreadyRunningEx from attempting to start naming service twice.");
        assertEquals("Naming", AcsJServiceAlreadyRunningEx.fromServiceAlreadyRunningEx(ex).getService());
    } finally {
        daemonCallbackImpl.prepareWaitForDone("naming");
        daemon.stop_naming_service(dcb, instanceNumber);
        assertTrue("Failed to stop naming service in 5 s", daemonCallbackImpl.waitForDone(5, TimeUnit.SECONDS));
    }
}
Also used : DaemonCallback(alma.acsdaemon.DaemonCallback) ServiceAlreadyRunningEx(alma.acsdaemonErrType.ServiceAlreadyRunningEx) AcsJServiceAlreadyRunningEx(alma.acsdaemonErrType.wrappers.AcsJServiceAlreadyRunningEx)

Example 3 with DaemonCallback

use of alma.acsdaemon.DaemonCallback in project ACS by ACS-Community.

the class ServicesDaemonTest method testNamingSrvStartStopCheckCallback.

/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Test methods //////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/**
	 * Starts and stops the naming service via the daemon,
	 * checking the callbacks.
	 */
public void testNamingSrvStartStopCheckCallback() throws Exception {
    assertNamingService(false);
    DaemonCallbackImpl daemonCallbackImpl = new DaemonCallbackImpl(logger);
    DaemonCallback dcb = activateDaemonCallback(daemonCallbackImpl);
    // start naming service
    daemonCallbackImpl.prepareWaitForDone("naming");
    StopWatch sw = new StopWatch(logger);
    daemon.start_naming_service(dcb, instanceNumber);
    assertTrue("Failed to start naming service in 10 s", daemonCallbackImpl.waitForDone(10, TimeUnit.SECONDS));
    sw.logLapTime("call start_naming_service");
    assertFalse(AcsJCompletion.fromCorbaCompletion(daemonCallbackImpl.getLastDoneCompletion()).isError());
    assertNamingService(true);
    // stop naming service
    daemonCallbackImpl.prepareWaitForDone("naming");
    sw.reset();
    daemon.stop_naming_service(dcb, instanceNumber);
    assertTrue("Failed to stop naming service in 5 s", daemonCallbackImpl.waitForDone(5, TimeUnit.SECONDS));
    sw.logLapTime("call stop_naming_service");
}
Also used : DaemonCallback(alma.acsdaemon.DaemonCallback) StopWatch(alma.acs.util.StopWatch)

Aggregations

DaemonCallback (alma.acsdaemon.DaemonCallback)3 DaemonThreadFactory (alma.acs.concurrent.DaemonThreadFactory)1 StopWatch (alma.acs.util.StopWatch)1 ServiceAlreadyRunningEx (alma.acsdaemonErrType.ServiceAlreadyRunningEx)1 AcsJServiceAlreadyRunningEx (alma.acsdaemonErrType.wrappers.AcsJServiceAlreadyRunningEx)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1