Search in sources :

Example 6 with DummyComponent

use of alma.jconttest.DummyComponent in project ACS by ACS-Community.

the class ContainerServicesTesterImpl method testGetReferenceWithCustomClientSideTimeout.

/**
	 * @see alma.jconttest.ContainerServicesTesterOperations#testGetReferenceWithCustomClientSideTimeout(String)
	 */
public boolean testGetReferenceWithCustomClientSideTimeout() {
    boolean ret = true;
    try {
        String compName = "DefaultDummyComp";
        org.omg.CORBA.Object compObj = m_containerServices.getComponent(compName);
        DummyComponent comp = alma.jconttest.DummyComponentHelper.narrow(compObj);
        //secs. (should be at most 10 s longer than 'timeout' 
        int waitTime = 18;
        // because component deactivation blocks only 10 seconds on a still running operation. 
        // secs.
        int timeout = 10;
        // first let's try to call the IF without a timeout
        try {
            comp.callThatTakesSomeTime(waitTime * 1000);
        } catch (org.omg.CORBA.TIMEOUT e) {
            m_logger.log(Level.WARNING, "No TIMEOUT exception expected for a 20 second call, without applying a special client-side timeout.");
            ret = false;
        }
        // then we call the ContainerServices to assign a timeout of 10 seconds
        org.omg.CORBA.Object compObjWithTimeout = m_containerServices.getReferenceWithCustomClientSideTimeout(compObj, timeout);
        DummyComponent compWithTimeout = alma.jconttest.DummyComponentHelper.narrow(compObjWithTimeout);
        // we call again the IF
        StopWatch sw = new StopWatch(m_logger);
        try {
            compWithTimeout.callThatTakesSomeTime(waitTime * 1000);
            m_logger.log(Level.WARNING, "TIMEOUT exception expected after " + timeout + " seconds.");
            ret = false;
        } catch (org.omg.CORBA.TIMEOUT e) {
            m_logger.info("Good: got a TIMEOUT exception from DefaultDummyComp#callThatTakesSomeTime");
        }
        int elapsedTime = (int) sw.getLapTimeMillis() / 1000;
        if (Math.abs(elapsedTime - timeout) > 2) {
            ret = false;
            m_logger.log(Level.WARNING, "TIMEOUT exception caught as expected, but after " + elapsedTime + " seconds instead of the expected " + timeout + " seconds.");
        }
        // the release call should block for the remaining 8 s that 'callThatTakesSomeTime' keeps running after our client timeout.
        m_containerServices.releaseComponent(compName);
    } catch (Exception ex) {
        m_logger.log(Level.WARNING, "Failure in testGetReferenceWithCustomClientSideTimeout, will return 'false'.", ex);
        ret = false;
    }
    return ret;
}
Also used : DummyComponent(alma.jconttest.DummyComponent) StopWatch(alma.acs.util.StopWatch)

Aggregations

DummyComponent (alma.jconttest.DummyComponent)6 StopWatch (alma.acs.util.StopWatch)2 DummyComponentPOATie (alma.jconttest.DummyComponentPOATie)2 POA (org.omg.PortableServer.POA)2 Servant (org.omg.PortableServer.Servant)2 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)1 ComponentDescriptor (alma.acs.component.ComponentDescriptor)1 ComponentQueryDescriptor (alma.acs.component.ComponentQueryDescriptor)1 ComponentServantManager (alma.acs.container.ComponentServantManager)1 DummyComponentImpl (alma.jconttest.DummyComponentImpl.DummyComponentImpl)1 JconttestUtil (alma.jconttest.util.JconttestUtil)1 CountDownLatch (java.util.concurrent.CountDownLatch)1