code.onehippo.org is currently readonly. We are migrating to code.bloomreach.com, please continue working there on Monday 14/12. See: https://docs.bloomreach.com/display/engineering/GitLab

Commit c2284223 authored by Ard Schrijvers's avatar Ard Schrijvers

REPO-1811 Tests to confirm lock expiration

Integration tests that confirm the correct working of the
DbResetExpiredLocksJanitor
parent a3bc5d1f
......@@ -156,7 +156,9 @@
<exclude>**/SchedulerTest.java</exclude>
<exclude>**/MonkeyTest.java</exclude>
<exclude>**/LockTest.java</exclude>
<exclude>**/LockManagerTest.java</exclude>
<exclude>**/LockManagerAbortTest.java</exclude>
<exclude>**/LockManagerBasicTest.java</exclude>
<exclude>**/LockManagerRefreshTest.java</exclude>
</excludes>
</configuration>
</plugin>
......@@ -197,7 +199,9 @@
<include>**/SchedulerTest.java</include>
<include>**/MonkeyTest.java</include>
<include>**/LockTest.java</include>
<include>**/LockManagerTest.java</include>
<include>**/LockManagerAbortTest.java</include>
<include>**/LockManagerBasicTest.java</include>
<include>**/LockManagerRefreshTest.java</include>
</includes>
</configuration>
</execution>
......
......@@ -139,4 +139,20 @@ public abstract class AbstractLockManagerTest extends RepositoryTestCase {
}
protected void insertDataRowLock(final String key, final String clusterId, final String threadName,
final long expirationTime) throws SQLException {
final long lockTime = System.currentTimeMillis();
try (Connection connection = dataSource.getConnection()){
final PreparedStatement createStatement = connection.prepareStatement(CREATE_STATEMENT);
createStatement.setString(1, key);
createStatement.setString(2, clusterId);
createStatement.setString(3, threadName);
createStatement.setLong(4, lockTime);
createStatement.setInt(5, 60);
createStatement.setLong(6, expirationTime);
createStatement.execute();
}
}
}
/*
* Copyright 2017 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.repository.lock;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.Test;
import org.onehippo.cms7.services.lock.LockException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.onehippo.repository.lock.db.DbLockManager.ABORT_STATEMENT;
public class LockManagerExpiresTest extends AbstractLockManagerTest {
@Test
public void an_expired_lock_gets_freed() throws Exception {
if (dataSource == null) {
// in memory test
return;
}
long expirationTime = System.currentTimeMillis() + 6000;
insertDataRowLock("123", "otherClusterNode", "otherThread", expirationTime);
// Since the lock is of another cluster node which is not live, the lock does not get refreshed meaning it
// will be freed after expiration time
// within 15 seconds the lock should for sure be freed
while (System.currentTimeMillis() < expirationTime + 15000) {
try {
dbRowAssertion("123", "FREE");
break;
} catch (AssertionError e) {
// status not yet free, retry
}
}
// the lock should be free
dbRowAssertion("123", "FREE");
}
}
......@@ -147,21 +147,6 @@ public class LockManagerRefreshTest extends AbstractLockManagerTest {
}
}
private void insertDataRowLock(final String key, final String clusterId, final String threadName,
final long expirationTime) throws SQLException {
final long lockTime = System.currentTimeMillis();
try (Connection connection = dataSource.getConnection()){
final PreparedStatement createStatement = connection.prepareStatement(CREATE_STATEMENT);
createStatement.setString(1, key);
createStatement.setString(2, clusterId);
createStatement.setString(3, threadName);
createStatement.setLong(4, lockTime);
createStatement.setInt(5, 60);
createStatement.setLong(6, expirationTime);
createStatement.execute();
}
}
protected class LockRunnable implements Runnable {
private String key;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment