Search in sources :

Example 1 with Client

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

Example 2 with Client

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());
}
Also used : HashMap(java.util.HashMap) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Client(com.cosylab.acs.maci.Client) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Client

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

Example 4 with Client

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");
    }
}
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)

Example 5 with Client

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

Aggregations

Client (com.cosylab.acs.maci.Client)9 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)6 ClientInfo (com.cosylab.acs.maci.ClientInfo)6 Administrator (com.cosylab.acs.maci.Administrator)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BadParametersException (com.cosylab.acs.maci.BadParametersException)2 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)2 AlarmSourceImpl (alma.acs.alarmsystem.source.AlarmSourceImpl)1 DaemonThreadFactory (alma.acs.concurrent.DaemonThreadFactory)1 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)1 Container (com.cosylab.acs.maci.Container)1 Manager (com.cosylab.acs.maci.Manager)1 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)1 AdministratorCommandDeallocate (com.cosylab.acs.maci.manager.recovery.AdministratorCommandDeallocate)1 ClientCommandDeallocate (com.cosylab.acs.maci.manager.recovery.ClientCommandDeallocate)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1