use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.
the class OperationParkerImplTest method testAwaitQueueCount_shouldNotExceedBlockedThreadCount.
@Test
public void testAwaitQueueCount_shouldNotExceedBlockedThreadCount() {
final HazelcastInstance hz = createHazelcastInstance();
NodeEngineImpl nodeEngine = getNode(hz).nodeEngine;
OperationParkerImpl waitNotifyService = (OperationParkerImpl) nodeEngine.getOperationParker();
final int keyCount = 1000;
int nThreads = 4;
CountDownLatch latch = new CountDownLatch(nThreads);
for (int i = 0; i < nThreads; i++) {
new Thread(new LockWaitAndUnlockTask(hz, keyCount, latch)).start();
}
while (latch.getCount() > 0) {
LockSupport.parkNanos(1);
int awaitQueueCount = waitNotifyService.getParkQueueCount();
Assert.assertTrue("Await queue count should be smaller than total number of threads: " + awaitQueueCount + " VS " + nThreads, awaitQueueCount < nThreads);
}
}
use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.
the class OperationParkerImpl_populateTest method populateRemoteCall.
@Test
public void populateRemoteCall() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance();
HazelcastInstance remote = factory.newHazelcastInstance();
NodeEngineImpl nodeEngine = getNode(local).nodeEngine;
OperationParkerImpl operationParker = (OperationParkerImpl) nodeEngine.getOperationParker();
Address thisAddress = getNode(local).nodeEngine.getThisAddress();
Address thatAddress = getNode(remote).nodeEngine.getThisAddress();
DummyBlockingOperation blockingOperation = new DummyBlockingOperation(new WaitNotifyKeyImpl());
setCallerAddress(blockingOperation, thatAddress);
setCallId(blockingOperation, 100);
operationParker.park(blockingOperation);
CallsPerMember callsPerMember = new CallsPerMember(thisAddress);
operationParker.populate(callsPerMember);
assertEquals(singleton(thatAddress), callsPerMember.addresses());
assertArrayEquals(new long[] { 100 }, callsPerMember.toOpControl(thatAddress).runningOperations());
}
use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.
the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.
private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
Config config = createConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
HazelcastInstance hz3 = factory.newHazelcastInstance(config);
Node node1 = TestUtil.getNode(hz1);
Node node2 = TestUtil.getNode(hz2);
Node node3 = TestUtil.getNode(hz3);
warmUpPartitions(hz1, hz2, hz3);
int partitionId = getPartitionId(hz2);
NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
OperationService operationService3 = nodeEngine3.getOperationService();
Operation op = new AlwaysBlockingOperation();
Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
// just wait a little to make sure
// operation is landed on wait-queue
sleepSeconds(1);
// execute the given split action
splitAction.run(node1, node2, node3);
// Let node3 detect the split and merge it back to other two.
ClusterServiceImpl clusterService3 = node3.getClusterService();
clusterService3.merge(node1.address);
assertClusterSizeEventually(3, hz1);
assertClusterSizeEventually(3, hz2);
assertClusterSizeEventually(3, hz3);
try {
future.get(1, TimeUnit.MINUTES);
fail("Future.get() should fail with a MemberLeftException!");
} catch (MemberLeftException e) {
// expected
EmptyStatement.ignore(e);
} catch (Exception e) {
fail(e.getClass().getName() + ": " + e.getMessage());
}
}
use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.
the class Invocation_RetryTest method invocationShouldComplete_whenOperationsPending_DuringShutdown.
@Test
public void invocationShouldComplete_whenOperationsPending_DuringShutdown() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance hz = factory.newHazelcastInstance();
NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
InternalOperationService operationService = nodeEngine.getOperationService();
operationService.invokeOnPartition(new SleepingOperation(Long.MAX_VALUE).setPartitionId(0));
sleepSeconds(1);
Future[] futures = new Future[NUMBER_OF_INVOCATIONS];
for (int i = 0; i < NUMBER_OF_INVOCATIONS; i++) {
futures[i] = operationService.createInvocationBuilder(null, new RetryingOperation(), 0).setTryCount(Integer.MAX_VALUE).setCallTimeout(Long.MAX_VALUE).invoke();
}
hz.getLifecycleService().terminate();
for (Future future : futures) {
try {
future.get(2, TimeUnit.MINUTES);
} catch (ExecutionException ignored) {
} catch (TimeoutException e) {
fail(e.getMessage());
}
}
}
use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.
the class OperationParkerImpl_populateTest method populateLocalCall.
@Test
public void populateLocalCall() {
HazelcastInstance hz = createHazelcastInstance();
NodeEngineImpl nodeEngine = getNode(hz).nodeEngine;
OperationParkerImpl operationParker = (OperationParkerImpl) nodeEngine.getOperationParker();
Address thisAddress = nodeEngine.getThisAddress();
DummyBlockingOperation blockingOperation = new DummyBlockingOperation(new WaitNotifyKeyImpl());
setCallId(blockingOperation, 100);
operationParker.park(blockingOperation);
CallsPerMember callsPerMember = new CallsPerMember(thisAddress);
operationParker.populate(callsPerMember);
assertEquals(singleton(thisAddress), callsPerMember.addresses());
assertArrayEquals(new long[] { 100 }, callsPerMember.toOpControl(thisAddress).runningOperations());
}
Aggregations