use of org.apache.geode.distributed.internal.locks.DLockGrantor in project geode by apache.
the class DistributedLockServiceDUnitTest method testSuspendLockingProhibitsLocking.
/**
* Test that exlusive locking prohibits locking activity
*/
@Test
public void testSuspendLockingProhibitsLocking() {
final String name = getUniqueName();
distributedCreateService(2, name);
DistributedLockService service = DistributedLockService.getServiceNamed(name);
// Should be able to lock from other VM
VM vm1 = Host.getHost(0).getVM(1);
assertTrue(vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock(name)));
assertTrue(service.suspendLocking(1000));
// vm1 is the grantor... use debugHandleSuspendTimeouts
vm1.invoke(new SerializableRunnable("setDebugHandleSuspendTimeouts") {
public void run() {
DLockService dls = (DLockService) DistributedLockService.getServiceNamed(name);
assertTrue(dls.isLockGrantor());
DLockGrantor grantor = dls.getGrantorWithNoSync();
grantor.setDebugHandleSuspendTimeouts(5000);
}
});
// Shouldn't be able to lock a name from another VM
assertTrue(!vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock(name)));
service.resumeLocking();
vm1.invoke(new SerializableRunnable("unsetDebugHandleSuspendTimeouts") {
public void run() {
DLockService dls = (DLockService) DistributedLockService.getServiceNamed(name);
assertTrue(dls.isLockGrantor());
DLockGrantor grantor = dls.getGrantorWithNoSync();
grantor.setDebugHandleSuspendTimeouts(0);
}
});
// Should be able to lock again
assertTrue(vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock(name)));
}
use of org.apache.geode.distributed.internal.locks.DLockGrantor in project geode by apache.
the class DistributedLockServiceDUnitTest method testGrantTokenCleanup.
// static volatile boolean startedThreadVM2_testTokenCleanup;
// static volatile boolean finishedThreadVM2_testTokenCleanup;
// static volatile DLockToken grantorDLockToken_testTokenCleanup;
@Test
public void testGrantTokenCleanup() throws Exception {
final String dlsName = getUniqueName();
final VM vmGrantor = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
// final VM vm2 = Host.getHost(0).getVM(2);
final String key1 = "key1";
// vmGrantor creates grantor
vmGrantor.invoke(new SerializableRunnable() {
public void run() {
LogWriterUtils.getLogWriter().info("[testGrantTokenCleanup] vmGrantor creates grantor");
connectDistributedSystem();
DistributedLockService dls = DistributedLockService.create(dlsName, getSystem());
assertTrue(dls.lock(key1, -1, -1));
assertTrue(dls.isLockGrantor());
DLockGrantor grantor = ((DLockService) dls).getGrantor();
assertNotNull(grantor);
DLockGrantor.DLockGrantToken grantToken = grantor.getGrantToken(key1);
assertNotNull(grantToken);
LogWriterUtils.getLogWriter().info("[testGrantTokenCleanup] vmGrantor unlocks key1");
dls.unlock(key1);
assertNull(grantor.getGrantToken(key1));
}
});
if (true)
// TODO: remove early-out and complete this test
return;
// vm1 locks and frees key1
vm1.invoke(new SerializableRunnable() {
public void run() {
LogWriterUtils.getLogWriter().info("[testTokenCleanup] vm1 locks key1");
connectDistributedSystem();
DLockService dls = (DLockService) DistributedLockService.create(dlsName, getSystem());
assertTrue(dls.lock(key1, -1, -1));
LogWriterUtils.getLogWriter().info("[testTokenCleanup] vm1 frees key1");
dls.unlock(key1);
// token for key1 still exists until freeResources is called
assertNotNull(dls.getToken(key1));
dls.freeResources(key1);
// make sure token for key1 is gone
DLockToken token = dls.getToken(key1);
assertNull("Failed with bug 38180: " + token, token);
// make sure there are NO tokens at all
Collection tokens = dls.getTokens();
assertEquals("Failed with bug 38180: tokens=" + tokens, 0, tokens.size());
}
});
// vmGrantor frees key1
vmGrantor.invoke(new SerializableRunnable() {
public void run() {
LogWriterUtils.getLogWriter().info("[testTokenCleanup] vmGrantor frees key1");
DLockService dls = (DLockService) DistributedLockService.getServiceNamed(dlsName);
if (true)
// TODO: remove this when 38180/38179 are fixed
return;
// check for bug 38180...
// make sure token for key1 is gone
DLockToken token = dls.getToken(key1);
assertNull("Failed with bug 38180: " + token, token);
// make sure there are NO tokens at all
Collection tokens = dls.getTokens();
assertEquals("Failed with bug 38180: tokens=" + tokens, 0, tokens.size());
// check for bug 38179...
// make sure there are NO grant tokens at all
DLockGrantor grantor = dls.getGrantor();
Collection grantTokens = grantor.getGrantTokens();
assertEquals("Failed with bug 38179: grantTokens=" + grantTokens, 0, grantTokens.size());
// dls.freeResources(key1);
// TODO: assert that DLockGrantToken for key1 is gone
}
});
}
use of org.apache.geode.distributed.internal.locks.DLockGrantor in project geode by apache.
the class TXLockUpdateParticipantsMessage method updateParticipants.
/**
* Update the Grantor with a new set of Participants. This method is meant to be used in a local
* context (does <b>NOT</b> involve any messaging)
*/
public static void updateParticipants(DLockService svc, TXLockId txLockId, Set updatedParticipants) {
DLockGrantor grantor = null;
try {
grantor = DLockGrantor.waitForGrantor(svc);
if (grantor != null) {
try {
TXLockBatch txb = (TXLockBatch) grantor.getLockBatch(txLockId);
if (txb == null) {
// fixes bug 42656
return;
}
txb.setParticipants(updatedParticipants);
grantor.updateLockBatch(txLockId, txb);
} catch (LockGrantorDestroyedException ignoreit) {
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Aggregations