use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testManagerToContainerStateTransferComponents.
public void testManagerToContainerStateTransferComponents() {
TestComponent mount1COB = new TestComponent("MOUNT1");
TestComponent mount2COB = new TestComponent("MOUNT2");
Map supportedComponents = new HashMap();
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", mount2COB);
TestContainer container = new TestContainer("Container");
container.setSupportedComponents(supportedComponents);
// recovery mode
TestContainer container2 = new TestContainer("Container", ClientType.CONTAINER, true);
container2.setSupportedComponents(supportedComponents);
try {
// container login
ClientInfo containerInfo = manager.login(container);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// activate MOUNT2
//
URI mount1URI;
URI mount2URI;
try {
mount1URI = new URI("MOUNT1");
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
manager.logout(containerInfo.getHandle());
// now do the trick, make container2 to login
// this will assime container is down
ClientInfo containerInfo2 = manager.login(container2);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be 2 Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals("MOUNT1", infos[0].getName());
assertEquals("MOUNT2", infos[1].getName());
// container2 took over
assertEquals(containerInfo2.getHandle(), infos[0].getContainer());
assertEquals(containerInfo2.getHandle(), infos[1].getContainer());
// manager and client
assertEquals(2, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(info.getHandle()));
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
// client only
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testOnDemandContainer.
public void testOnDemandContainer() throws Throwable {
TestDaemon daemon = new TestDaemon(manager, false);
transport.registerDeamon("test", daemon);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
URI curl = null;
// test on-demand activation
curl = new URI("DEMANDER");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), curl, true, status);
assertNotNull(ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
// check if container is logged in
ContainerInfo[] infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
assertNotNull(infos);
assertEquals(1, infos.length);
// release component
manager.releaseComponent(info.getHandle(), curl);
Thread.sleep(SLEEP_TIME_MS);
// there should be no container
infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
assertNotNull(infos);
assertEquals(0, infos.length);
// now fail to start container
daemon = new TestDaemon(manager, true);
transport.registerDeamon("test", daemon);
try {
status = new StatusHolder();
ref = manager.getComponent(info.getHandle(), curl, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: " + e.toString());
}
// no daemon case
transport.registerDeamon("test", null);
try {
status = new StatusHolder();
ref = manager.getComponent(info.getHandle(), curl, true, status);
fail("Expected AcsJCannotGetComponentEx");
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: " + e.toString());
} catch (AcsJNoPermissionEx e) {
fail();
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class TestContainer method activate_component.
/**
* @see com.cosylab.acs.maci.Container#activate_COB(int, long executionId, java.lang.String, java.lang.String, java.lang.String)
*/
public ComponentInfo activate_component(int handle, long executionId, String name, String exe, String type) throws RemoteException {
if (supportedComponents.containsKey(name)) {
// simulate activation
try {
Thread.sleep(activationTime);
} catch (InterruptedException ie) {
}
Component cob = (Component) supportedComponents.get(name);
if (cob instanceof TestComponent) {
TestComponent tc = (TestComponent) cob;
tc.setHandle(handle);
try {
tc.activate();
} catch (Exception ex) {
throw new RemoteException("Failed to construct(), error: " + ex.toString(), ex);
}
}
ComponentInfo cobInfo = new ComponentInfo(handle, name, type, exe, cob);
cobInfo.setContainer(this.handle);
cobInfo.setContainerName(this.name);
if (cob != null)
cobInfo.setInterfaces(new String[] { cob.getClass().getName() });
synchronized (activatedComponents) {
activatedComponents.put(new Integer(handle), cobInfo);
}
return cobInfo;
} else
return null;
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testGetCyclicHierachicalComponent.
/*
This test was disabled, since construct() is not yet implemented as it should be,
now it activation (named) lock is aquired also when construct() method is called!
public void testGetCyclicHierachicalComponentConstructCase()
{
// activation of subcomponents is requested in construct() method
testGetCyclicHierachicalComponent(false);
}
*/
private void testGetCyclicHierachicalComponent(boolean constructCase) {
try {
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
// MOUNT2 -> MOUNT2 cycle
TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("CyclicHierarchical", manager, new String[] { "MOUNT2" }, true, constructCase);
supportedComponents.put("MOUNT2", mount2HierCOB);
// MOUNT3 -> MOUNT5 -> PBEND_B_01 -> MOUNT3 cycle
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("MOUNT3", manager, new String[] { "MOUNT4" }, true, constructCase);
supportedComponents.put("MOUNT3", mount3HierCOB);
TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("MOUNT4", manager, new String[] { "PBEND_B_01" }, true, constructCase);
supportedComponents.put("MOUNT4", mount4HierCOB);
TestHierarchicalComponent pbendHierCOB = new TestHierarchicalComponent("PBEND_B_01", manager, new String[] { "MOUNT3" }, true, constructCase);
supportedComponents.put("PBEND_B_01", pbendHierCOB);
container.setSupportedComponents(supportedComponents);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
long startTime = System.currentTimeMillis();
// this will cause cyclic depedency...
try {
StatusHolder status;
Component ref;
URI mount2URI = new URI("MOUNT2");
status = new StatusHolder();
ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: cyclic dependency " + e.toString());
} catch (Exception ex) {
fail();
}
long stopTime = System.currentTimeMillis();
// cyclic dependency should be detected, not deadlock detected
if (stopTime - startTime > 30000)
fail("Cyclic dependency detection is too slow.");
startTime = System.currentTimeMillis();
// this will cause cyclic depedency...
try {
URI mount3URI = new URI("MOUNT3");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount3URI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: cyclic dependency " + e.toString());
} catch (Exception ex) {
fail();
}
stopTime = System.currentTimeMillis();
// cyclic dependency should be detected, not deadlock detected
if (stopTime - startTime > 30000)
fail("Cyclic dependency detection is too slow.");
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testGetDefaultComponent.
/**
* Test getDefaultComponent.
*/
public void testGetDefaultComponent() {
try {
try {
manager.getDefaultComponent(0, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(Integer.MAX_VALUE, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(dummyHandle, "dummyType");
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.getDefaultComponent(info.getHandle(), null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(info.getHandle(), "invalid");
fail();
} catch (NoDefaultComponentException ndce) {
System.out.println("This is OK: " + ndce.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount3COB = new TestComponent("MOUNT3");
supportedComponents.put("MOUNT3", mount3COB);
container.setSupportedComponents(supportedComponents);
/*ClientInfo containerInfo = */
manager.login(container);
try {
ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
assertTrue(componentInfo != null);
assertEquals(componentInfo.getComponent(), mount3COB);
} catch (NoDefaultComponentException ndce) {
fail();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
} catch (NoDefaultComponentException e) {
fail();
}
}
Aggregations