Search in sources :

Example 1 with DummyComponent

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

the class ContainerServicesTesterImpl method testGetDynamicDummyComponent.

/**
	 * @see alma.jconttest.ContainerServicesTesterOperations#testGetDynamicDummyComponent(org.omg.CORBA.StringHolder)
	 */
public boolean testGetDynamicDummyComponent(StringHolder compName) {
    boolean ret = false;
    try {
        ComponentQueryDescriptor compQueryDesc = new ComponentQueryDescriptor();
        //			compQueryDesc.setComponentName(ComponentQueryDescriptor.ANY);
        compQueryDesc.setComponentType(DummyComponentHelper.DUMMYCOMPONENT_CORBATYPE);
        org.omg.CORBA.Object compObj = m_containerServices.getDynamicComponent(compQueryDesc, false);
        DummyComponent dummyComp = alma.jconttest.DummyComponentHelper.narrow(compObj);
        // return the name that was dynamically assigned
        compName.value = dummyComp.name();
        m_logger.info("received dynamic instance of " + DummyComponentHelper.DUMMYCOMPONENT_CORBATYPE);
        // now check the component descriptor
        ComponentDescriptor compDesc = m_containerServices.getComponentDescriptor(compName.value);
        m_logger.info("Component data: " + compDesc.toString());
        m_containerServices.releaseComponent(dummyComp.name());
        ret = true;
    } catch (Exception e) {
        // todo: IDL ex
        m_logger.warning(e.toString());
        // prevent CORBA marshalling ex
        compName.value = "!!!failed!!!";
    }
    return ret;
}
Also used : DummyComponent(alma.jconttest.DummyComponent) ComponentDescriptor(alma.acs.component.ComponentDescriptor) ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor)

Example 2 with DummyComponent

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

the class DummyComponentWrapperImpl method _callDummyComponentWithTime.

public boolean _callDummyComponentWithTime(int timeInMillisec, String targetComponentName) throws AcsJCouldntPerformActionEx {
    DummyComponent dummyComponent = null;
    try {
        org.omg.CORBA.Object compObj = null;
        if (targetComponentName != null) {
            compObj = m_containerServices.getComponent(targetComponentName);
        } else {
            compObj = m_containerServices.getDefaultComponent(DUMMYCOMP_TYPENAME);
        }
        dummyComponent = DummyComponentHelper.narrow(compObj);
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Failed to access target component.", e);
        throw new AcsJCouldntPerformActionEx();
    }
    targetComponentName = dummyComponent.name();
    // If the given time is less than 0, then we call "callThatTakesSomeTime" with a time larger than the ORB-level timeout.
    if (timeInMillisec < 0) {
        JconttestUtil util = new JconttestUtil(m_containerServices);
        int orbLevelTimeoutMillis = util.getSystemLevelOrbTimeoutMillis();
        timeInMillisec = orbLevelTimeoutMillis + 1000;
    }
    try {
        dummyComponent.callThatTakesSomeTime(timeInMillisec);
        m_logger.info("Did NOT get org.omg.CORBA.TIMEOUT in call " + targetComponentName + "#callThatTakesSomeTime(" + timeInMillisec + ")");
        return false;
    } catch (org.omg.CORBA.TIMEOUT e) {
        m_logger.info("Got org.omg.CORBA.TIMEOUT in call " + targetComponentName + "#callThatTakesSomeTime(" + timeInMillisec + ")");
        return true;
    }
}
Also used : DummyComponent(alma.jconttest.DummyComponent) JconttestUtil(alma.jconttest.util.JconttestUtil) AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)

Example 3 with DummyComponent

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

the class OtherComponentClient method testTimeout.

/**
    * This test will use custom client side timeout, ignoring Container Timeout. 
    * It is the client version of {@link #testGetReferenceWithCustomClientSideTimeout()}
    * where m_contSrvTesterComp will take over the role of this junit test client for testing the timeout.
    **/
public void testTimeout() throws Exception {
    try {
        org.omg.CORBA.Object compObj = getContainerServices().getComponent(DEFAULT_DUMMYCOMP_INSTANCE);
        DummyComponent comp = 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 applicable client-side timeout
        try {
            comp.callThatTakesSomeTime(waitTime * 1000);
        } catch (org.omg.CORBA.TIMEOUT e) {
            fail("It is not supposed to get a timeout before waitTime");
        }
        // then we call the ContainerServices to assign a timeout of 10 seconds
        compObj = getContainerServices().getReferenceWithCustomClientSideTimeout(compObj, timeout);
        comp = DummyComponentHelper.narrow(compObj);
        //we call again the IF
        StopWatch sw = new StopWatch(m_logger);
        try {
            comp.callThatTakesSomeTime(waitTime * 1000);
            fail("It is supposed to get a timeout before waitTime");
        } catch (org.omg.CORBA.TIMEOUT e) {
            m_logger.info("Good: Got TIMEOUT exception from calling " + DEFAULT_DUMMYCOMP_INSTANCE + "#callThatTakesSomeTime with configured client timeout = " + timeout + " seconds.");
        }
        int elapsedTime = (int) sw.getLapTimeMillis() / 1000;
        if (Math.abs(elapsedTime - timeout) > 1) {
            String msg = "TIMEOUT exception caught as expected, but after " + elapsedTime + " seconds instead of the expected " + timeout + " seconds.";
            fail(msg);
        }
    } finally {
        // the release call should block for the remaining 8 s that 'callThatTakesSomeTime' executes after our client timeout.
        getContainerServices().releaseComponent(DEFAULT_DUMMYCOMP_INSTANCE);
    }
}
Also used : DummyComponent(alma.jconttest.DummyComponent) StopWatch(alma.acs.util.StopWatch)

Example 4 with DummyComponent

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

the class SyncDummyComponentImpl method testPOAConfig.

public void testPOAConfig() throws Exception {
    final String compName = "virtualTestComp";
    POA compPOA = acsCorba.createPOAForComponent(compName);
    org.jacorb.poa.POA jacCompPOA = null;
    if (compPOA instanceof org.jacorb.poa.POA) {
        jacCompPOA = (org.jacorb.poa.POA) compPOA;
    } else {
        fail("this test is only meant for JacORB. Instead the POA impl is of type " + compPOA.getClass().getName());
    }
    //		Policy threadPolicy = jacCompPOA.getPolicy(THREAD_POLICY_ID.value);
    //		assertNotNull(threadPolicy); // currently null, which defaults to ORB_CTRL_MODEL (see POA#sSingleThreadModel())
    assertTrue(jacCompPOA.isUseServantManager());
    String theName = jacCompPOA.the_name();
    assertEquals("unexpected poa name ", "ComponentPOA_" + compName, theName);
    String qualName = jacCompPOA._getQualifiedName();
    assertEquals("unexpected qualified poa name ", "ComponentPOA/ComponentPOA_" + compName, qualName);
    String poaId = new String(jacCompPOA.getPOAId());
    assertEquals("unexpected poaId ", "StandardImplName/ComponentPOA/ComponentPOA_" + compName, poaId);
    // create a thread-aware test component servant using that POA
    DummyComponentImpl impl = new DummyComponentImpl() {

        public void dummyComponentsCanDoCloseToNothing() {
            Thread orbThread = Thread.currentThread();
            System.out.println("component called in thread " + orbThread.getName());
        }
    };
    Servant servant = new DummyComponentPOATie(impl);
    // activate the component 
    org.omg.CORBA.Object objRef = acsCorba.activateComponent(servant, compName, compPOA);
    // make CORBA calls to the component , and destroy the POA
    DummyComponent testCompRef = DummyComponentHelper.narrow(objRef);
    testCompRef.dummyComponentsCanDoCloseToNothing();
    // analyze thread structure		
    ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
    while (rootThreadGroup.getParent() != null) {
        rootThreadGroup = rootThreadGroup.getParent();
    }
    // hopefully large enough 
    ThreadGroup[] allThreadGroups = new ThreadGroup[rootThreadGroup.activeCount() * 2];
    int numThreadGroups = rootThreadGroup.enumerate(allThreadGroups, true);
    for (int i = 0; i < numThreadGroups; i++) {
        System.out.println("thread group " + allThreadGroups[i].getName() + ":");
        // hopefully large enough 
        Thread[] allThreadsInGroup = new Thread[allThreadGroups[i].activeCount() * 2];
        int numThreads = allThreadGroups[i].enumerate(allThreadsInGroup, false);
        for (int j = 0; j < numThreads; j++) {
            System.out.println("\t" + allThreadsInGroup[j].getName());
        }
    }
    compPOA.destroy(false, true);
}
Also used : POA(org.omg.PortableServer.POA) Servant(org.omg.PortableServer.Servant) DummyComponent(alma.jconttest.DummyComponent) DummyComponentImpl(alma.jconttest.DummyComponentImpl.DummyComponentImpl) DummyComponentPOATie(alma.jconttest.DummyComponentPOATie)

Example 5 with DummyComponent

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

the class SyncDummyComponentImpl method _testComponentPOALifecycle.

/**
	 * This test method can also be used to experiment with 
	 * @param destroyWhileBusy
	 * @param iterations
	 * @throws Exception
	 */
private void _testComponentPOALifecycle(boolean destroyWhileBusy, int iterations) throws Exception {
    final String compName = "virtualTestComp";
    for (int i = 0; i < iterations; i++) {
        m_logger.info("Will create and destroy component instance #" + i);
        final POA compPOA = acsCorba.createPOAForComponent(compName);
        assertNotNull(compPOA);
        // create a test component servant using that POA
        final SyncDummyComponentImpl impl = new SyncDummyComponentImpl();
        Servant servant = new DummyComponentPOATie(impl);
        final ComponentServantManager servantManager = acsCorba.setServantManagerOnComponentPOA(compPOA);
        // activate the component 
        org.omg.CORBA.Object objRef = acsCorba.activateComponent(servant, compName, compPOA);
        // make a simple CORBA call to the component, and then destroy the POA
        final DummyComponent testCompRef = DummyComponentHelper.narrow(objRef);
        testCompRef.dummyComponentsCanDoCloseToNothing();
        if (destroyWhileBusy) {
            final CountDownLatch sync = new CountDownLatch(1);
            impl.setMethodCallSync(sync);
            Runnable compMethodCallRunnable = new Runnable() {

                public void run() {
                    try {
                        testCompRef.callThatTakesSomeTime(1000);
                    } catch (Exception ex) {
                        exceptionInThread = ex;
                    }
                }
            };
            m_logger.info("Will destroy component POA while active request is still running.");
            (new Thread(compMethodCallRunnable)).start();
            boolean properSync = sync.await(10000, TimeUnit.MILLISECONDS);
            assertTrue(properSync);
        } else {
            testCompRef.callThatTakesSomeTime(0);
        }
        // timeout should be larger than pending call (callThatTakesSomeTime)
        boolean isInactive = acsCorba.deactivateComponentPOAManager(compPOA, compName, 2000);
        assertTrue(isInactive);
        // active calls are supposedly over already, so the timeout can be smaller than execution time for "callThatTakesSomeTime"
        boolean isEtherealized = acsCorba.destroyComponentPOA(compPOA, servantManager, 500);
        assertTrue("Timeout here probably means that 'deactivateComponentPOAManager' did not properly wait for active requests to finish.", isEtherealized);
        if (exceptionInThread != null) {
            fail("asynchronous component call (#callThatTakesSomeTime) failed: " + exceptionInThread.toString());
        }
    }
    m_logger.info("Done with testComponentPOALifecycle()");
}
Also used : ComponentServantManager(alma.acs.container.ComponentServantManager) POA(org.omg.PortableServer.POA) CountDownLatch(java.util.concurrent.CountDownLatch) Servant(org.omg.PortableServer.Servant) DummyComponent(alma.jconttest.DummyComponent) DummyComponentPOATie(alma.jconttest.DummyComponentPOATie)

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