Skip to content

Commit

Permalink
Added another unit test and removed EXTRACT
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Dec 20, 2007
1 parent 7b76809 commit 03f8f2b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
Expand Up @@ -127,7 +127,7 @@ private boolean lock(final LockAction action, final String id)
{
if (isClusteringEnabled(action))
{
final Date timeout = DateUtils.add(new Date(), Calendar.MILLISECOND, (int) lockTimeoutInMilliseconds);
final Date timeout = DateUtils.add(new Date(), Calendar.MILLISECOND, (int) -lockTimeoutInMilliseconds);
return jdbcTemplate.update(aquireLockSql, new Object[] {getLockingServerId(), id, action.name(), timeout}) == 1;
}
else
Expand Down
2 changes: 1 addition & 1 deletion symmetric/src/main/resources/symmetric-services.xml
Expand Up @@ -631,7 +631,7 @@
<property name="lockDuringSyncTriggers" value="${symmetric.runtime.cluster.lock.during.sync.triggers}" />
<property name="aquireLockSql">
<value>
update ${sync.table.prefix}_lock set locking_server_id=?, lock_time=current_timestamp where lock_id=? and lock_action=? and (lock_time is null or lock_time &gt; ?)
update ${sync.table.prefix}_lock set locking_server_id=?, lock_time=current_timestamp where lock_id=? and lock_action=? and (lock_time is null or lock_time &lt; ?)
</value>
</property>
<property name="releaseLockSql">
Expand Down
@@ -1,27 +1,54 @@

package org.jumpmind.symmetric.service.impl;

import org.jumpmind.symmetric.AbstractDatabaseTest;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.service.IClusterService;
import org.jumpmind.symmetric.service.LockAction;
import org.testng.Assert;
import org.testng.annotations.Test;

public class ClusterServiceTest extends AbstractDatabaseTest {
public class ClusterServiceTest extends AbstractDatabaseTest
{

@Test(groups = "continuous")
public void testLock() throws Exception {
IClusterService service = (IClusterService) getBeanFactory().getBean(Constants.CLUSTER_SERVICE);
public void testLock() throws Exception
{
final IClusterService service = (IClusterService) getBeanFactory().getBean(Constants.CLUSTER_SERVICE);
Assert.assertTrue(service.lock(LockAction.PURGE), "Could not lock for PURGE");
Assert.assertEquals(countActivePurgeLocks(), 1, "Could not find the lock in the database.");
Assert.assertFalse(service.lock(LockAction.PURGE), "Should not have been able to lock for PURGE");
service.unlock(LockAction.PURGE);
Assert.assertEquals(countActivePurgeLocks(), 0, "Could not find the lock in the database.");
}

private int countActivePurgeLocks() {
@Test(groups = "continuous")
public void testOtherNodeLock() throws Exception
{
final String ID_ONE = "00020";
final String ID_TWO = "00010";
final Node nodeOne = new Node();
nodeOne.setNodeId(ID_ONE);

final Node nodeTwo = new Node();
nodeTwo.setNodeId(ID_TWO);

final IClusterService service = (IClusterService) getBeanFactory().getBean(Constants.CLUSTER_SERVICE);
service.initLockTable(LockAction.OTHER, ID_ONE);
service.initLockTable(LockAction.OTHER, ID_TWO);
Assert.assertTrue(service.lock(LockAction.OTHER, nodeOne), "Could not lock for OTHER " + ID_ONE);
Assert.assertFalse(service.lock(LockAction.OTHER, nodeOne), "Should not have been able to lock for OTHER "
+ ID_ONE);
Assert.assertTrue(service.lock(LockAction.OTHER, nodeTwo), "Could not lock for OTHER " + ID_TWO);
service.unlock(LockAction.OTHER, nodeOne);
Assert.assertTrue(service.lock(LockAction.OTHER, nodeOne), "Could not lock for OTHER " + ID_ONE);
}

private int countActivePurgeLocks()
{
return getJdbcTemplate().queryForInt(
"select count(*) from sym_lock where lock_id=? and lock_action=? and lock_time is not null",
new Object[] { ClusterService.COMMON_LOCK_ID, LockAction.PURGE.name() });
"select count(*) from sym_lock where lock_id=? and lock_action=? and lock_time is not null",
new Object[] {ClusterService.COMMON_LOCK_ID, LockAction.PURGE.name()});
}
}

0 comments on commit 03f8f2b

Please sign in to comment.