use of com.hazelcast.cp.lock.FencedLock in project hazelcast by hazelcast.
the class UnsafeFencedLockMigrationTest method whenLockIsBlocked_thenBackupIsReplicated.
@Test
public void whenLockIsBlocked_thenBackupIsReplicated() {
Config config = new Config();
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
FencedLock lock = hz2.getCPSubsystem().getLock("lock@" + generateKeyOwnedBy(hz1));
CountDownLatch latch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
latch.countDown();
// wait until other thread blocks
LockService lockService = getNodeEngineImpl(hz1).getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = lockService.getRegistryOrNull(lock.getGroupId());
assertThat(registry.getLiveOperations(), hasSize(1));
});
lock.unlock();
});
assertOpenEventually(latch);
lock.lock();
waitAllForSafeState(hz1, hz2);
hz1.getLifecycleService().terminate();
lock.unlock();
}
use of com.hazelcast.cp.lock.FencedLock in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method test_sessionClosedOnCPSubsystemReset.
@Test
public void test_sessionClosedOnCPSubsystemReset() throws Exception {
HazelcastInstance[] instances = newInstances(3, 3, 1);
instances[0].getCPSubsystem().getAtomicLong("long1").set(1);
instances[0].getCPSubsystem().getAtomicLong("long1@custom").set(2);
FencedLock lock = instances[3].getCPSubsystem().getLock("lock");
lock.lock();
instances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
assertTrueEventually(() -> {
ProxySessionManagerService service = getNodeEngineImpl(instances[3]).getService(ProxySessionManagerService.SERVICE_NAME);
assertEquals(NO_SESSION_ID, service.getSession((RaftGroupId) lock.getGroupId()));
});
}
use of com.hazelcast.cp.lock.FencedLock in project hazelcast by hazelcast.
the class AbstractFencedLockAdvancedTest method testActiveSessionIsNotClosedWhenPendingWaitKey.
@Test
public void testActiveSessionIsNotClosedWhenPendingWaitKey() {
FencedLock other = null;
for (HazelcastInstance instance : instances) {
if (instance != proxyInstance) {
other = instance.getCPSubsystem().getLock(lock.getName());
break;
}
}
assertNotNull(other);
// lock from another instance
other.lock();
spawn(() -> {
lock.tryLock(30, TimeUnit.MINUTES);
});
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
assertEquals(2, sessionService.getAllSessions(lock.getGroupId()).get().size());
}
});
assertTrueAllTheTime(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
assertEquals(2, sessionService.getAllSessions(lock.getGroupId()).get().size());
}
}, 20);
}
Aggregations