mirror of https://github.com/apache/cloudstack.git
bug 10322: better mannered merovingians
This commit is contained in:
parent
2219269e83
commit
e16a013335
|
|
@ -19,37 +19,29 @@ package com.cloud.cluster;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.utils.db.Merovingian2;
|
||||
|
||||
public class LockTableListener implements ClusterManagerListener {
|
||||
Merovingian2 _lockMaster;
|
||||
|
||||
public LockTableListener() {
|
||||
|
||||
_lockMaster = Merovingian2.createLockMaster(ManagementServerNode.getManagementServerId());
|
||||
_lockMaster.clear();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.cluster.ClusterManagerListener#onManagementNodeJoined(java.util.List, long)
|
||||
*/
|
||||
@Override
|
||||
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.cluster.ClusterManagerListener#onManagementNodeLeft(java.util.List, long)
|
||||
*/
|
||||
@Override
|
||||
public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
for (ManagementServerHostVO node : nodeList) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.cluster.ClusterManagerListener#onManagementNodeIsolated()
|
||||
*/
|
||||
@Override
|
||||
public void onManagementNodeIsolated() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,7 +218,27 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
|
|||
}
|
||||
|
||||
public void clear() {
|
||||
clear(_msId);
|
||||
}
|
||||
|
||||
public void clear(long msId) {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = Transaction.getStandaloneConnectionWithException();
|
||||
clear(conn, msId);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to clear the locks", e);
|
||||
} finally {
|
||||
try {
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void clear(Connection conn, long msId) {
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
conn = Transaction.getStandaloneConnectionWithException();
|
||||
|
|
@ -232,9 +252,6 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
|
|||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,64 +17,62 @@
|
|||
*/
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Merovingian2Test extends TestCase {
|
||||
static final Logger s_logger = Logger.getLogger(Merovingian2Test.class);
|
||||
Merovingian2 _lockMaster = Merovingian2.createLockMaster(1234);
|
||||
|
||||
@Override
|
||||
@Override @Before
|
||||
protected void setUp() throws Exception {
|
||||
Connection conn = Transaction.getStandaloneConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM op_lock");
|
||||
pstmt.executeUpdate();
|
||||
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
_lockMaster.clear();
|
||||
}
|
||||
|
||||
@Override @After
|
||||
protected void tearDown() throws Exception {
|
||||
_lockMaster.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockAndRelease() {
|
||||
Merovingian2 m = Merovingian2.createLockMaster(1234);
|
||||
|
||||
s_logger.info("Testing first acquire");
|
||||
boolean result = m.acquire("first"+1234, 5);
|
||||
boolean result = _lockMaster.acquire("first"+1234, 5);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
s_logger.info("Testing acquire of different lock");
|
||||
result = m.acquire("second"+1234, 5);
|
||||
result = _lockMaster.acquire("second"+1234, 5);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
s_logger.info("Testing reacquire of the same lock");
|
||||
result = m.acquire("first"+1234, 5);
|
||||
result = _lockMaster.acquire("first"+1234, 5);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
int count = m.owns("first"+1234);
|
||||
int count = _lockMaster.owns("first"+1234);
|
||||
Assert.assertEquals(count, 2);
|
||||
|
||||
count = m.owns("second"+1234);
|
||||
count = _lockMaster.owns("second"+1234);
|
||||
Assert.assertEquals(count, 1);
|
||||
|
||||
s_logger.info("Testing release of the first lock");
|
||||
result = m.release("first"+1234);
|
||||
result = _lockMaster.release("first"+1234);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
count = m.owns("first"+1234);
|
||||
count = _lockMaster.owns("first"+1234);
|
||||
Assert.assertEquals(count, 1);
|
||||
|
||||
s_logger.info("Testing release of the second lock");
|
||||
result = m.release("second"+1234);
|
||||
result = _lockMaster.release("second"+1234);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
result = m.release("first"+1234);
|
||||
result = _lockMaster.release("first"+1234);
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue