use of org.apache.geode.distributed.internal.locks.DLockRequestProcessor.DLockResponseMessage in project geode by apache.
the class DistributedLockServiceDUnitTest method testDestroyLockServiceAfterGrantResponse.
@Test
public void testDestroyLockServiceAfterGrantResponse() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
final String serviceName = getUniqueName();
vm0.invoke(new SerializableRunnable("Create the grantor") {
public void run() {
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof DLockResponseMessage) {
DistributedLockService.destroy(serviceName);
}
}
});
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
try {
service.lock("obj", -1, -1);
fail("The lock service should have been destroyed");
} catch (LockServiceDestroyedException expected) {
// Do nothing
}
vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {
public void run() {
final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
}
Aggregations