use of com.cosylab.acs.maci.manager.HandleDataStore in project ACS by ACS-Community.
the class ManagerImplSerializationTest method testContainerDie.
public void testContainerDie() throws Throwable {
// should be something else then deafault because
// the default is in use by the Manager
Properties table = new Properties();
table.put("OAPort", "12121");
// new ORB instance
ORB ourOrb = ORB.init(new String[0], table);
try {
POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
// activate POA
POAManager manager = rootPOA.the_POAManager();
manager.activate();
} catch (Exception e) {
e.printStackTrace();
}
ContainerProxyImpl activator = new ContainerProxyImpl(clientName);
si.ijs.maci.ClientInfo clientInfo = manager.login(activator._this(ourOrb));
if (clientInfo == null || clientInfo.h == 0)
fail("Unable to login to manager");
// just destroy its ORB
ourOrb.shutdown(true);
// get object as it is stored in recovery store
ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
HandleDataStore activators = newManager.getContainers();
// the client now is still in stored data
assertEquals(activators.first(), 1);
newManager.initialize(null, null, null, null, null);
// now wait for timer task to remove client
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
// since the client died the menager automaticaly log it out
activators = newManager.getClients();
// not any more
assertEquals(activators.first(), 0);
}
use of com.cosylab.acs.maci.manager.HandleDataStore in project ACS by ACS-Community.
the class ManagerImplSerializationTest method testClientLogin.
public void testClientLogin() {
// login a client
ClientProxyImpl client = new ClientProxyImpl(clientName, myManager.getManagerEngine().getLogger());
client.login(orb, manager);
// get object as it is stored in recovery store
ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
// since we used clean recovery store we must have our client only there
HandleDataStore clients = newManager.getClients();
assertEquals(clients.first(), 1);
com.cosylab.acs.maci.ClientInfo clientInfo = (com.cosylab.acs.maci.ClientInfo) clients.get(clients.first());
assertEquals(clientInfo.getName(), clientName);
client.logout();
// read state again
newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
clients = newManager.getClients();
assertEquals(clients.first(), 0);
}
use of com.cosylab.acs.maci.manager.HandleDataStore in project ACS by ACS-Community.
the class ManagerImplSerializationTest method testClientDie.
public void testClientDie() {
// should be something else then deafault because
// the default is in use by the Manager
Properties table = new Properties();
table.put("OAPort", "12121");
// new ORB instance
ORB ourOrb = ORB.init(new String[0], table);
try {
POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
// activate POA
POAManager manager = rootPOA.the_POAManager();
manager.activate();
} catch (Exception e) {
e.printStackTrace();
}
ClientProxyImpl client = new ClientProxyImpl(clientName, myManager.getManagerEngine().getLogger());
client.login(ourOrb, manager);
// just destroy its ORB
ourOrb.shutdown(true);
// get object as it is stored in recovery store
ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
HandleDataStore clients = newManager.getClients();
// the client now is still in stored data
assertEquals(clients.first(), 1);
newManager.initialize(null, null, null, null, null);
// now wait for timer task to remove client
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
// since the client died the menager automaticaly log it out
clients = newManager.getClients();
// not any more
assertEquals(clients.first(), 0);
}
use of com.cosylab.acs.maci.manager.HandleDataStore in project ACS by ACS-Community.
the class HandleDataStoreTest method testDefaultAllocation.
/**
*/
public void testDefaultAllocation() {
HandleDataStore hds = new HandleDataStore();
int i = 1;
for (; i <= 10000; i++) {
int handle = hds.allocate();
assertEquals(i, handle);
}
assertEquals(i - 1, hds.size());
assertEquals(i - 1, hds.last());
assertEquals(1, hds.first());
int handle = hds.first();
assertTrue(hds.isAllocated(handle));
for (i = 2; i <= 10000; i++) {
assertEquals(i, handle = hds.next(handle));
assertTrue(hds.isAllocated(handle));
}
assertEquals(0, handle = hds.next(handle));
assertTrue(!hds.isAllocated(handle));
handle = hds.last();
assertTrue(hds.isAllocated(handle));
for (i = 10000 - 1; i > 0; i--) {
assertEquals(i, handle = hds.previous(handle));
assertTrue(hds.isAllocated(handle));
}
assertEquals(0, handle = hds.previous(handle));
assertTrue(!hds.isAllocated(handle));
}
use of com.cosylab.acs.maci.manager.HandleDataStore in project ACS by ACS-Community.
the class HandleDataStoreTest method testFreeAllocation.
/**
*/
public void testFreeAllocation() {
HandleDataStore hds = new HandleDataStore();
allocate(hds, 1);
allocate(hds, 3);
allocate(hds, 2);
allocate(hds, 10);
allocate(hds, 100);
allocate(hds, 1000);
deallocate(hds, 100);
deallocate(hds, 1);
deallocate(hds, 1000);
allocate(hds, 1003);
allocate(hds, 1000);
int h = hds.preallocate();
assertEquals(0, hds.allocate(h));
hds.deallocate(h, true);
h = hds.allocate();
hds.deallocate(h);
int[] right = new int[] { 3, 2, 10, 1003, 1000 };
h = hds.first();
int pos = 0;
do {
assertEquals(right[pos++], h);
h = hds.next(h);
} while (h != 0 && pos < right.length);
assertEquals(0, h);
assertEquals(right.length, pos);
}
Aggregations