use of alma.jconttest.DummyComponentPOATie 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);
}
use of alma.jconttest.DummyComponentPOATie 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()");
}
Aggregations