use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testGetComponent.
public void testGetComponent() {
try {
try {
manager.getComponent(0, null, false, null);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
manager.getComponent(Integer.MAX_VALUE, null, false, null);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
StatusHolder status = null;
manager.getComponent(dummyHandle, dummyURI, false, status);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
StatusHolder status = new StatusHolder();
manager.getComponent(dummyHandle, null, false, status);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
// get unexistant
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), dummyURI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component does not exist " + e.toString());
} catch (Exception ex) {
fail();
}
// test no activation
URI mount = null;
try {
mount = new URI("MOUNT1");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, false, status);
} catch (AcsJCannotGetComponentEx e) {
fail();
} catch (Exception ex) {
fail();
}
// test activation w/o container
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component not activated " + e.toString());
} catch (Exception ex) {
fail();
}
// there should be only no Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", null);
supportedComponents.put("MOUNT3", new TestComponent("MOUNT3", true, false));
Component mount4COB = new TestComponent("MOUNT4", false, true);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
// test ordinary activation
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// test failed activation
try {
StatusHolder status;
Component ref;
URI mount2 = null;
mount2 = new URI("MOUNT2");
status = new StatusHolder();
ref = manager.getComponent(info.getHandle(), mount2, true, status);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (URISyntaxException e1) {
fail();
}
// client should be owner of only one component
ClientInfo[] ci = manager.getClientInfo(info.getHandle(), new int[] { info.getHandle() }, null);
assertNotNull(ci);
assertEquals(1, ci.length);
// only mount 1
assertEquals(1, ci[0].getComponents().size());
// test failed activation (construct failure)
URI mount3 = null;
try {
mount3 = new URI("MOUNT3");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount3, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component not activated " + e.toString());
} catch (Exception ex) {
fail();
}
// test no activation w/ activated component
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, false, status);
assertTrue(ref != null);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// test failed destruction
// test will be affected in client logout
URI mount4 = null;
try {
mount4 = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount4, true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be only two Components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals(mount.toString(), infos[0].getName());
// manager and client
assertEquals(2, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(info.getHandle()));
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
assertTrue(mount4.toString().equals(infos[1].getName()));
// client
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
// test unavailable and startup
manager.logout(containerInfo.getHandle());
containerInfo = manager.login(container);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components after activation
// there should be only two Components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals(mount.toString(), infos[0].getName());
// manager and client
assertEquals(2, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(info.getHandle()));
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
assertTrue(mount4.toString().equals(infos[1].getName()));
// client
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
// client logout
manager.logout(info.getHandle());
client = new TestAdministrator(administratorName);
info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be only one component activated (MOUNT1)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(1, infos.length);
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
manager.logout(containerInfo.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be no components activated
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
//
// test wrong Container-Component ImplLang
//
TestContainer pycontainer = new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.py, false);
Map pysupportedComponents = new HashMap();
Component cppOnPy = new TestComponent("CPP_ON_PY");
pysupportedComponents.put("CPP_ON_PY", cppOnPy);
pycontainer.setSupportedComponents(pysupportedComponents);
manager.login(pycontainer);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
StatusHolder status = new StatusHolder();
URI cppOnPyURI = new URI("CPP_ON_PY");
manager.getComponent(info.getHandle(), cppOnPyURI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (URISyntaxException e1) {
fail();
}
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("CPP_ON_PY", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), false);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e1) {
fail();
} catch (AcsJIncompleteComponentSpecEx ex) {
fail();
} catch (AcsJInvalidComponentSpecEx ex) {
fail();
}
// client logout
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method internalTestGetHierarchicalComponentPassingComponentHandle.
public void internalTestGetHierarchicalComponentPassingComponentHandle(boolean activateOnActivation) {
try {
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestContainer container2 = new TestContainer("Container2");
Map supportedComponents2 = new HashMap();
TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT2", mount2HierCOB);
supportedComponents.put("MOUNT3", mount3HierCOB);
supportedComponents2.put("MOUNT5", mount4COB);
container.setSupportedComponents(supportedComponents);
container2.setSupportedComponents(supportedComponents2);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
ClientInfo containerInfo2 = manager.login(container2);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// test ordinary activation
URI mount2URI;
try {
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be all three Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(3, infos.length);
// container logout and login
manager.logout(containerInfo.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be no Components activated on "Container"
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(1, infos.length);
manager.login(container);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be all three Components activated
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(3, infos.length);
// test ordinary deactivation
try {
mount2URI = new URI("MOUNT2");
int owners = manager.releaseComponent(info.getHandle(), mount2URI);
assertEquals(0, owners);
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be no Components activated (hierarchical deactivation)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
// test ordinary activation again
try {
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// logout container2
manager.logout(containerInfo2.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// logout client
manager.logout(info.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfoTopologicalSort.
public void testComponentInfoTopologicalSort() {
try {
boolean activateOnActivation = true;
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestContainer container2 = new TestContainer("Container2");
Map supportedComponents2 = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5", "PBEND_B_01" }, true, activateOnActivation);
Component mount5COB = new TestComponent("MOUNT5");
TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("HierarchicalCOB4", manager, new String[] { "MOUNT2" }, true, activateOnActivation);
TestHierarchicalComponent psHierCOB = new TestHierarchicalComponent("HierarchicalPSCOB", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", mount2HierCOB);
supportedComponents.put("MOUNT3", mount3HierCOB);
supportedComponents2.put("MOUNT5", mount5COB);
supportedComponents.put("MOUNT4", mount4HierCOB);
supportedComponents.put("PBEND_B_01", psHierCOB);
container.setSupportedComponents(supportedComponents);
container2.setSupportedComponents(supportedComponents2);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
ClientInfo containerInfo2 = manager.login(container2);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// activate hier. components
URI mount2URI;
try {
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// activate orphan component
URI mount1URI;
try {
mount1URI = new URI("MOUNT1");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// activate mount4
URI mount4URI;
try {
mount4URI = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount4URI, true, status);
assertEquals(mount4HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be all three Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(6, infos.length);
// topological sort
ArrayList solution = new ArrayList(6);
solution.add(mount4HierCOB);
solution.add(mount2HierCOB);
solution.add(mount3HierCOB);
solution.add(psHierCOB);
solution.add(mount5COB);
solution.add(mount1COB);
List list = ComponentInfoTopologicalSort.sort(manager.getComponents());
assertEquals(solution.size(), list.size());
int len = solution.size();
for (int i = 0; i < len; i++) assertEquals(solution.get(i), ((ComponentInfo) list.get(i)).getComponent());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testExpiredHandle.
public void testExpiredHandle() {
// test client login
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
// duplicate logout
try {
manager.logout(info.getHandle());
fail("No permission exception was not thrown");
} catch (AcsJNoPermissionEx e) {
// this should provide nice error message
System.out.println("This is OK: " + e);
}
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfo.
public void testComponentInfo() {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (false) {
try {
//TODO get ComponentInfo
manager.getComponentInfo(0, null, null, null, false);
manager.getComponentInfo(Integer.MAX_VALUE, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, "non-null", null, true);
manager.getComponentInfo(dummyHandle, null, null, "non-null", true);
manager.getComponentInfo(dummyHandle, new int[0], null, null, false);
manager.getComponentInfo(dummyHandle, new int[0], "non-null", null, true);
manager.getComponentInfo(dummyHandle, new int[0], null, "non-null", false);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
manager.getComponentInfo(info.getHandle(), new int[0], "*MOUNT*", "*", false);
manager.logout(info.getHandle());
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = null;
try {
containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e1) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT1", "*", false);
assertEquals(1, infos.length);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
manager.logout(containerInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
Aggregations