Search in sources :

Example 16 with ClientInfo

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");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 17 with ClientInfo

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");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 18 with ClientInfo

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);
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 19 with ClientInfo

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");
}
Also used : ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 20 with ClientInfo

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");
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) Client(com.cosylab.acs.maci.Client)

Aggregations

ClientInfo (com.cosylab.acs.maci.ClientInfo)56 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)39 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)23 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)21 HashMap (java.util.HashMap)21 Map (java.util.Map)21 Component (com.cosylab.acs.maci.Component)18 RemoteException (com.cosylab.acs.maci.RemoteException)18 URI (java.net.URI)18 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)17 URISyntaxException (java.net.URISyntaxException)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)16 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)7 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)7 ArrayList (java.util.ArrayList)7 Client (com.cosylab.acs.maci.Client)6 Administrator (com.cosylab.acs.maci.Administrator)5