@Test
public void testLockWithProperAuth()
throws InterruptedException,
IOException {
final LockingManagement memoryLockManager = new MemoryLockManager(
"default");
final Transaction t1 = Transaction.AUTO_COMMIT;
final DefaultTransaction t2 = new DefaultTransaction();
t2.addAuthorization("auth1");
FeatureLock lock = new FeatureLock(
"auth1",
1 /* minute */);
memoryLockManager.lockFeatureID(
"sometime",
"f1",
t1,
lock);
Thread commiter = new Thread(
new Runnable() {
@Override
public void run() {
try {
Thread.sleep(4000);
memoryLockManager.release(
"auth1",
t1);
}
catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(
e);
}
catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(
e);
}
}
});
long currentTime = System.currentTimeMillis();
commiter.start();
memoryLockManager.lock(
t2,
"f1");
assertTrue((System.currentTimeMillis() - currentTime) < 4000);
commiter.join();
}