use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testPing.
public void testPing() {
try {
/// !!! this takes a lot of time (and not fully implemtented)
if (true)
return;
ClientInfo info = manager.login(new TestClient(clientName));
try {
Thread.sleep(12000);
} catch (InterruptedException ie) {
}
manager.logout(info.getHandle());
System.out.println("logged out.");
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// no pings here
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImplTest method testLogout.
public void testLogout() {
//test invalid
try {
manager.logout(0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
//test invalid
try {
manager.logout(Integer.MAX_VALUE);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
//test invalid
try {
manager.logout(HandleConstants.CLIENT_MASK);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
//test client logout
try {
ClientInfo info = manager.login(new TestClient(clientName));
assertNotNull(info);
manager.logout(info.getHandle());
//test administrator logout
info = manager.login(new TestAdministrator(administratorName));
assertNotNull(info);
manager.logout(info.getHandle());
//test container logout
info = manager.login(new TestContainer(containerName));
assertNotNull(info);
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 testConcurrentContainersLogin.
public void testConcurrentContainersLogin() {
final Object sync = new Object();
final AtomicBoolean done = new AtomicBoolean(false);
final AtomicInteger counter = new AtomicInteger(0);
final AtomicInteger loginCounter = new AtomicInteger(0);
final int CONCURRENT_LOGINS = 100;
final CyclicBarrier barrier = new CyclicBarrier(CONCURRENT_LOGINS);
class LoginWorker implements Runnable {
public void run() {
final String containerName = "Container" + counter.incrementAndGet();
Container container = new TestContainer(containerName);
try {
barrier.await();
} catch (Throwable th) {
return;
}
ClientInfo info = null;
try {
info = manager.login(container);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
// note that if this fails, tearDown will be called (and manager shutdown)
assertTrue(containerName + " failed to login.", info != null && info.getHandle() != 0);
if (loginCounter.incrementAndGet() == CONCURRENT_LOGINS) {
synchronized (sync) {
sync.notifyAll();
}
}
}
}
synchronized (sync) {
// spawn threads
for (int i = 0; i < CONCURRENT_LOGINS; ++i) new Thread(new LoginWorker()).start();
try {
sync.wait(CONCURRENT_LOGINS * 500);
} catch (InterruptedException e) {
}
}
assertTrue("All containers failed to login successfully in time.", loginCounter.get() == CONCURRENT_LOGINS);
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerPrevaylerTest method testGetDynamicComponents.
/**
* Test getDynamicComponents.
*/
public void testGetDynamicComponents() throws Throwable {
TestContainer dynContainer = new TestDynamicContainer("DynContainer");
dynContainer.setActivationTime(COMPONENT_ACTIVATION_TIME_MS);
ClientInfo dynContainerInfo = manager.login(dynContainer);
assertNotNull(dynContainerInfo);
// wait for container to startup
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
final ArrayList<Thread> threads = new ArrayList<Thread>(CLIENTS);
final ArrayList<Integer> clientHandles = new ArrayList<Integer>(CLIENTS);
long startTime = System.currentTimeMillis();
for (int i = 0; i < CLIENTS; i++) {
final String clientName = "client" + i;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
int clientHandle = dynamicComponentClientInstance(clientName);
clientHandles.add(clientHandle);
} catch (Throwable th) {
th.printStackTrace();
}
}
}, clientName);
threads.add(thread);
}
// start all
for (Thread thread : threads) thread.start();
// wait for all to complete
for (Thread thread : threads) thread.join();
long endTime = System.currentTimeMillis() - CLIENT_START_DELAY_MS;
System.out.println((CLIENTS * COMPONENTS) + " components activated in " + (endTime - startTime) / 1000 + " seconds");
// bypass prevayler to get serialization size
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(buffer);
synchronized (prevayler) {
oos.writeObject(manager);
}
System.out.println("Manager object serialization size: " + buffer.size() + " bytes");
manager.logout(dynContainerInfo.getHandle());
// logout all the client
for (int h : clientHandles) if (h != 0)
manager.logout(h);
buffer.reset();
oos.reset();
synchronized (prevayler) {
oos.writeObject(manager);
}
System.out.println("Manager object serialization size after full deactivation: " + buffer.size() + " bytes");
}
use of com.cosylab.acs.maci.ClientInfo 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");
}
}
Aggregations