use of com.cosylab.acs.maci.Client 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.Client in project ACS by ACS-Community.
the class ManagerImplTest method testContainerShutdown.
public void testContainerShutdown() {
try {
manager.shutdownContainer(0, null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(0, "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail();
}
try {
manager.shutdownContainer(info.getHandle(), "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Administrator admin = new TestAdministrator("shutdownAdmin");
ClientInfo info2 = null;
try {
info2 = manager.login(admin);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.shutdownContainer(info2.getHandle(), null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(info2.getHandle(), "invalid", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (NoResourcesException nre) {
System.out.println("This is OK: " + nre.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestComponent mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
container.setSupportedComponents(supportedComponents);
try {
ClientInfo containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
ComponentInfo[] infos = null;
try {
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(1, infos.length);
try {
manager.shutdownContainer(info.getHandle(), "Container", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
try {
manager.shutdownContainer(info2.getHandle(), "Container", 1);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(0, container.getActivatedComponents().size());
}
use of com.cosylab.acs.maci.Client in project ACS by ACS-Community.
the class ManagerImplTest method testBadAdministratorNotifications.
// first two callback blocks
// this means that third should not happen before first two
// and all calls should be done from the same thread
public void testBadAdministratorNotifications() {
try {
final long BLOCK_TIMEOUT_MS = 3000;
TestAdministrator admin = new TestAdministrator("admin", true) {
private AtomicInteger counter = new AtomicInteger(0);
private AtomicLong threadId = new AtomicLong(-1);
public void clientLoggedIn(ClientInfo info, long timeStamp, long executionId) {
// same as last thread check (transitive)
// positive
long thisThreadId = Thread.currentThread().getId();
long previousId = threadId.getAndSet(thisThreadId);
if (previousId != thisThreadId && previousId >= 0)
fail("notification called from other thread");
// only first two block for a while
if (counter.incrementAndGet() < 3) {
try {
Thread.sleep(BLOCK_TIMEOUT_MS);
} catch (InterruptedException e) {
// noop
}
}
super.clientLoggedIn(info, timeStamp, executionId);
}
};
ClientInfo adminInfo = manager.login(admin);
assertNotNull(adminInfo);
// now we login 3 clients
Client client1 = new TestClient("client1");
Client client2 = new TestClient("client2");
Client client3 = new TestClient("client3");
// even if admin is blocking, this should not block this
// notification are async (not a SyncAdmin)
long startTS = System.currentTimeMillis();
ClientInfo clientInfo1 = manager.login(client1);
assertNotNull(clientInfo1);
ClientInfo clientInfo2 = manager.login(client2);
assertNotNull(clientInfo2);
ClientInfo clientInfo3 = manager.login(client3);
assertNotNull(clientInfo3);
long stopTS = System.currentTimeMillis();
assertTrue((stopTS - startTS) < BLOCK_TIMEOUT_MS);
ArrayList notifications = admin.getClientLoggedInNotifications();
synchronized (notifications) {
int count = 0;
while (notifications.size() < 3) {
// wait max up to 3*BLOCK_TIMEOUT_MS (must be careful about spurious wakeups)
if ((System.currentTimeMillis() - stopTS) > 3 * BLOCK_TIMEOUT_MS) {
fail("expected 3 notifications, got " + notifications.size());
}
try {
notifications.wait(3 * BLOCK_TIMEOUT_MS);
} catch (InterruptedException e) {
/* noop */
}
}
assertEquals(3, notifications.size());
assertEquals(clientInfo1, notifications.get(0));
assertEquals(clientInfo2, notifications.get(1));
assertEquals(clientInfo3, notifications.get(2));
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Client in project ACS by ACS-Community.
the class ManagerImplTest method testAdministratorNotifications.
public void testAdministratorNotifications() {
try {
TestAdministrator admin = new TestAdministrator("admin", true);
ClientInfo adminInfo = manager.login(admin);
assertNotNull(adminInfo);
TestAdministrator admin2 = new TestAdministrator("admin2", true);
ClientInfo adminInfo2 = manager.login(admin2);
assertNotNull(adminInfo2);
checkForNotification(admin.getClientLoggedInNotifications(), adminInfo2);
TestAdministrator admin3 = new TestAdministrator("admin3", true);
ClientInfo adminInfo3 = manager.login(admin3);
assertNotNull(adminInfo3);
checkForNotification(admin.getClientLoggedInNotifications(), adminInfo3);
checkForNotification(admin2.getClientLoggedInNotifications(), adminInfo3);
// test client login notification
Client client = new TestClient("client");
ClientInfo clientInfo = manager.login(client);
assertNotNull(clientInfo);
checkForNotification(admin.getClientLoggedInNotifications(), clientInfo);
checkForNotification(admin2.getClientLoggedInNotifications(), clientInfo);
checkForNotification(admin3.getClientLoggedInNotifications(), clientInfo);
// test container login notification
Container container = new TestContainer("Container");
ClientInfo containerInfo = manager.login(container);
assertNotNull(containerInfo);
Integer h = new Integer(containerInfo.getHandle());
checkForNotification(admin.getContainerLoggedInNotifications(), h);
checkForNotification(admin2.getContainerLoggedInNotifications(), h);
checkForNotification(admin3.getContainerLoggedInNotifications(), h);
manager.logout(containerInfo.getHandle());
checkForNotification(admin.getContainerLoggedOutNotifications(), h);
checkForNotification(admin2.getContainerLoggedOutNotifications(), h);
checkForNotification(admin3.getContainerLoggedOutNotifications(), h);
manager.logout(clientInfo.getHandle());
h = new Integer(clientInfo.getHandle());
checkForNotification(admin.getClientLoggedOutNotifications(), h);
checkForNotification(admin2.getClientLoggedOutNotifications(), h);
checkForNotification(admin3.getClientLoggedOutNotifications(), h);
manager.logout(adminInfo3.getHandle());
h = new Integer(adminInfo3.getHandle());
checkForNotification(admin.getClientLoggedOutNotifications(), h);
checkForNotification(admin2.getClientLoggedOutNotifications(), h);
manager.logout(adminInfo2.getHandle());
h = new Integer(adminInfo2.getHandle());
checkForNotification(admin.getClientLoggedOutNotifications(), h);
manager.logout(adminInfo.getHandle());
// test
assertEquals(0, admin.getClientLoggedInNotifications().size());
assertEquals(0, admin.getClientLoggedOutNotifications().size());
assertEquals(0, admin.getContainerLoggedInNotifications().size());
assertEquals(0, admin.getContainerLoggedOutNotifications().size());
assertEquals(0, admin2.getClientLoggedInNotifications().size());
assertEquals(0, admin2.getClientLoggedOutNotifications().size());
assertEquals(0, admin2.getContainerLoggedInNotifications().size());
assertEquals(0, admin2.getContainerLoggedOutNotifications().size());
assertEquals(0, admin3.getClientLoggedInNotifications().size());
assertEquals(0, admin3.getClientLoggedOutNotifications().size());
assertEquals(0, admin3.getContainerLoggedInNotifications().size());
assertEquals(0, admin3.getContainerLoggedOutNotifications().size());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Client in project ACS by ACS-Community.
the class ManagerImplTest method testShutdown.
/**
*
* Test of ManagerImpl shutdown.
*
*/
public void testShutdown() {
try {
manager.shutdown(0, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.shutdown(info.getHandle(), 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Administrator admin = new TestAdministrator("shutdownAdmin");
ClientInfo info2 = null;
try {
info2 = manager.login(admin);
manager.shutdown(info2.getHandle(), 0);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
// already shutdown
try {
manager.shutdown(info2.getHandle(), 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
// already shutdown returns without exception
try {
manager.logout(info.getHandle());
System.out.println("This is OK");
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is NOT OK: " + npe.toString());
npe.printStackTrace();
}
// already shutdown
try {
manager.login(client);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
// tearDown should not shutdown
manager = null;
}
Aggregations