Search in sources :

Example 6 with StackMaidDao

use of com.cloud.cluster.dao.StackMaidDao in project CloudStack-archive by CloudStack-extras.

the class CheckPointManagerTest method testTakeover.

public void testTakeover() throws Exception {
    ComponentLocator locator = ComponentLocator.getCurrentLocator();
    CheckPointManagerImpl taskMgr = ComponentLocator.inject(CheckPointManagerImpl.class);
    assertTrue(taskMgr.configure("TaskManager", new HashMap<String, Object>()));
    assertTrue(taskMgr.start());
    MockMaid delegate = new MockMaid();
    delegate.setValue("first");
    long taskId = taskMgr.pushCheckPoint(delegate);
    StackMaidDao maidDao = locator.getDao(StackMaidDao.class);
    CheckPointVO task = maidDao.findById(taskId);
    assertEquals(task.getDelegate(), MockMaid.class.getName());
    MockMaid retrieved = (MockMaid) SerializerHelper.fromSerializedString(task.getContext());
    assertEquals(retrieved.getValue(), delegate.getValue());
    Connection conn = Transaction.getStandaloneConnection();
    try {
        conn.setAutoCommit(true);
        PreparedStatement stmt = conn.prepareStatement("update stack_maid set msid=? where msid=?");
        stmt.setLong(1, 1234);
        stmt.setLong(2, ManagementServerNode.getManagementServerId());
        stmt.executeUpdate();
        stmt.close();
    } finally {
        conn.close();
    }
    MockClusterManager clusterMgr = (MockClusterManager) locator.getManager(ClusterManager.class);
    clusterMgr.triggerTakeover(1234);
    int i = 0;
    while (MockMaid.map.get(delegate.getSeq()) != null && i++ < 500) {
        Thread.sleep(1000);
    }
    assertNull(MockMaid.map.get(delegate.getSeq()));
}
Also used : ComponentLocator(com.cloud.utils.component.ComponentLocator) MockComponentLocator(com.cloud.utils.component.MockComponentLocator) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StackMaidDao(com.cloud.cluster.dao.StackMaidDao) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

StackMaidDao (com.cloud.cluster.dao.StackMaidDao)6 StackMaidDaoImpl (com.cloud.cluster.dao.StackMaidDaoImpl)3 ComponentLocator (com.cloud.utils.component.ComponentLocator)3 MockComponentLocator (com.cloud.utils.component.MockComponentLocator)3 Transaction (com.cloud.utils.db.Transaction)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CheckPointVO (com.cloud.cluster.CheckPointVO)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1