Search in sources :

Example 51 with NodeEngineImpl

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);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with NodeEngineImpl

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());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CallsPerMember(com.hazelcast.spi.CallsPerMember) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 53 with NodeEngineImpl

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());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 54 with NodeEngineImpl

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());
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) ExecutionException(java.util.concurrent.ExecutionException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with NodeEngineImpl

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());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CallsPerMember(com.hazelcast.spi.CallsPerMember) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)112 HazelcastInstance (com.hazelcast.core.HazelcastInstance)39 Test (org.junit.Test)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)31 QuickTest (com.hazelcast.test.annotation.QuickTest)31 Node (com.hazelcast.instance.Node)21 MapService (com.hazelcast.map.impl.MapService)20 Config (com.hazelcast.config.Config)19 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)16 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)14 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)14 ILogger (com.hazelcast.logging.ILogger)11 AssertTask (com.hazelcast.test.AssertTask)11 Invalidator (com.hazelcast.internal.nearcache.impl.invalidation.Invalidator)10 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)10 Address (com.hazelcast.nio.Address)10 Data (com.hazelcast.nio.serialization.Data)10 Before (org.junit.Before)10 Operation (com.hazelcast.spi.Operation)9