use of com.hazelcast.cp.ISemaphore in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testAcquireOnMultipleProxies.
@Test
public void testAcquireOnMultipleProxies() {
HazelcastInstance otherInstance = instances[0] == proxyInstance ? instances[1] : instances[0];
ISemaphore semaphore2 = otherInstance.getCPSubsystem().getSemaphore(semaphore.getName());
semaphore.init(1);
semaphore.tryAcquire(1);
assertFalse(semaphore2.tryAcquire());
}
use of com.hazelcast.cp.ISemaphore in project hazelcast by hazelcast.
the class SemaphoreLongAwaitTest method testLongAwait.
private void testLongAwait(HazelcastInstance instance) throws ExecutionException, InterruptedException {
ISemaphore semaphore = instance.getCPSubsystem().getSemaphore(proxyName);
Future<Object> f1 = spawn(() -> {
if (!semaphore.tryAcquire(1, 5, TimeUnit.MINUTES)) {
throw new IllegalStateException();
}
semaphore.release();
return null;
});
Future<Object> f2 = spawn(() -> {
semaphore.acquire();
semaphore.release();
return null;
});
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(instance).getService(SemaphoreService.SERVICE_NAME);
assertEquals(2, service.getLiveOperations(groupId).size());
});
assertTrueAllTheTime(() -> {
SemaphoreService service = getNodeEngineImpl(instance).getService(SemaphoreService.SERVICE_NAME);
assertEquals(2, service.getLiveOperations(groupId).size());
}, callTimeoutSeconds + 5);
semaphore.increasePermits(1);
assertCompletesEventually(f1);
assertCompletesEventually(f2);
f1.get();
f2.get();
}
use of com.hazelcast.cp.ISemaphore in project hazelcast by hazelcast.
the class HazelcastOSGiInstanceTest method getSemaphoreCalledSuccessfullyOverOSGiInstance.
@Test
public void getSemaphoreCalledSuccessfullyOverOSGiInstance() {
ISemaphore mockSemaphore = mock(ISemaphore.class);
HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
HazelcastOSGiInstance hazelcastOSGiInstance = createHazelcastOSGiInstance(mockHazelcastInstance);
CPSubsystem cpSubsystem = mock(CPSubsystem.class);
when(mockHazelcastInstance.getCPSubsystem()).thenReturn(cpSubsystem);
when(cpSubsystem.getSemaphore("my-semaphore")).thenReturn(mockSemaphore);
assertEquals(mockSemaphore, hazelcastOSGiInstance.getCPSubsystem().getSemaphore("my-semaphore"));
verify(cpSubsystem).getSemaphore("my-semaphore");
}
Aggregations