Search in sources :

Example 56 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testRetriedWaitKeysAreExpiredTogether.

@Test(timeout = 300_000)
public void testRetriedWaitKeysAreExpiredTogether() {
    CountDownLatch releaseLatch = new CountDownLatch(1);
    spawn(() -> {
        lock.lock();
        assertOpenEventually(releaseLatch);
        lock.unlock();
    });
    assertTrueEventually(() -> assertTrue(lock.isLocked()));
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    BiTuple[] lockWaitTimeoutKeyRef = new BiTuple[1];
    InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
    LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
    assertTrueEventually(() -> {
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
        assertEquals(1, waitTimeouts.size());
        lockWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
    });
    InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        RaftService raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
        int partitionId = raftService.getCPGroupPartitionId(groupId);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        boolean[] verified = new boolean[1];
        CountDownLatch latch = new CountDownLatch(1);
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public int getPartitionId() {
                return partitionId;
            }

            @Override
            public void run() {
                Lock lock = registry.getResourceOrNull(objectName);
                Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
                verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
                latch.countDown();
            }
        });
        assertOpenEventually(latch);
        assertTrue(verified[0]);
    });
    RaftOp op = new ExpireWaitKeysOp(LockService.SERVICE_NAME, Collections.singletonList(lockWaitTimeoutKeyRef[0]));
    invocationManager.invoke(groupId, op).joinInternal();
    assertTrueEventually(() -> assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty()));
    releaseLatch.countDown();
    assertTrueEventually(() -> assertFalse(lock.isLocked()));
    long fence1 = f1.joinInternal();
    long fence2 = f2.joinInternal();
    assertInvalidFence(fence1);
    assertInvalidFence(fence2);
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftOp(com.hazelcast.cp.internal.RaftOp) CountDownLatch(java.util.concurrent.CountDownLatch) ExpireWaitKeysOp(com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Map(java.util.Map) BiTuple(com.hazelcast.internal.util.BiTuple) Test(org.junit.Test)

Example 57 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class AbstractSemaphoreAdvancedTest method testRetriedWaitKeysAreExpiredTogether.

@Test
public void testRetriedWaitKeysAreExpiredTogether() {
    semaphore.init(1);
    CountDownLatch releaseLatch = new CountDownLatch(1);
    spawn(() -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        assertOpenEventually(releaseLatch);
        semaphore.release();
    });
    assertTrueEventually(() -> assertEquals(0, semaphore.availablePermits()));
    // there is a session id now
    RaftGroupId groupId = getGroupId();
    AbstractProxySessionManager sessionManager = getSessionManager();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    UUID invUid = newUnsecureUUID();
    BiTuple[] acquireWaitTimeoutKeyRef = new BiTuple[1];
    InternalCompletableFuture<Boolean> f1 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
        assertEquals(1, waitTimeouts.size());
        acquireWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
    });
    InternalCompletableFuture<Boolean> f2 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
        int partitionId = raftService.getCPGroupPartitionId(groupId);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        boolean[] verified = new boolean[1];
        CountDownLatch latch = new CountDownLatch(1);
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public int getPartitionId() {
                return partitionId;
            }

            @Override
            public void run() {
                Semaphore semaphore = registry.getResourceOrNull(objectName);
                Map<Object, WaitKeyContainer<AcquireInvocationKey>> waitKeys = semaphore.getInternalWaitKeysMap();
                verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
                latch.countDown();
            }
        });
        assertOpenEventually(latch);
        assertTrue(verified[0]);
    });
    RaftOp op = new ExpireWaitKeysOp(SemaphoreService.SERVICE_NAME, Collections.singletonList(acquireWaitTimeoutKeyRef[0]));
    invokeRaftOp(groupId, op).joinInternal();
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
    });
    releaseLatch.countDown();
    assertTrueEventually(() -> assertEquals(1, semaphore.availablePermits()));
    assertFalse(f1.joinInternal());
    assertFalse(f2.joinInternal());
}
Also used : RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ISemaphore(com.hazelcast.cp.ISemaphore) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftOp(com.hazelcast.cp.internal.RaftOp) CountDownLatch(java.util.concurrent.CountDownLatch) ExpireWaitKeysOp(com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp) AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Map(java.util.Map) BiTuple(com.hazelcast.internal.util.BiTuple) Test(org.junit.Test)

Example 58 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class FrozenPartitionTableTest method partitionTable_shouldBeFixed_whenMemberRestarts_usingNewUuid.

@Test
public void partitionTable_shouldBeFixed_whenMemberRestarts_usingNewUuid() {
    ruleStaleJoinPreventionDuration.setOrClearProperty("5");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    HazelcastInstance hz3 = factory.newHazelcastInstance();
    assertClusterSizeEventually(3, hz2, hz3);
    warmUpPartitions(hz1, hz2, hz3);
    changeClusterStateEventually(hz3, ClusterState.FROZEN);
    int member3PartitionId = getPartitionId(hz3);
    MemberImpl member3 = getNode(hz3).getLocalMember();
    hz3.shutdown();
    assertClusterSizeEventually(2, hz1, hz2);
    hz3 = newHazelcastInstance(initOrCreateConfig(new Config()), randomName(), new StaticMemberNodeContext(factory, newUnsecureUUID(), member3.getAddress()));
    assertClusterSizeEventually(3, hz1, hz2);
    waitAllForSafeState(hz1, hz2, hz3);
    OperationServiceImpl operationService = getOperationService(hz1);
    operationService.invokeOnPartition(null, new NonRetryablePartitionOperation(), member3PartitionId).join();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) StaticMemberNodeContext(com.hazelcast.instance.StaticMemberNodeContext) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class PromoteLiteMemberTest method assertPromotionInvocationStarted.

private void assertPromotionInvocationStarted(HazelcastInstance instance) {
    OperationServiceImpl operationService = getNode(instance).getNodeEngine().getOperationService();
    InvocationRegistry invocationRegistry = operationService.getInvocationRegistry();
    assertTrueEventually(() -> {
        for (Map.Entry<Long, Invocation> entry : invocationRegistry.entrySet()) {
            if (entry.getValue().op instanceof PromoteLiteMemberOp) {
                return;
            }
        }
        fail("Cannot find PromoteLiteMemberOp invocation!");
    });
}
Also used : Invocation(com.hazelcast.spi.impl.operationservice.impl.Invocation) PromoteLiteMemberOp(com.hazelcast.internal.cluster.impl.operations.PromoteLiteMemberOp) Map(java.util.Map) IMap(com.hazelcast.map.IMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) InvocationRegistry(com.hazelcast.spi.impl.operationservice.impl.InvocationRegistry)

Example 60 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method invocationShouldComplete_whenMemberReJoins_inFrozenState.

@Test
public void invocationShouldComplete_whenMemberReJoins_inFrozenState() throws Exception {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    Address owner = getNode(hz1).getThisAddress();
    String key = generateKeyOwnedBy(hz1);
    int partitionId = hz1.getPartitionService().getPartition(key).getPartitionId();
    changeClusterStateEventually(hz2, ClusterState.FROZEN);
    terminateInstance(hz1);
    OperationServiceImpl operationService = getNode(hz3).getNodeEngine().getOperationService();
    Operation op = new AddAndGetOperation(key, 1);
    Future<Long> future = operationService.invokeOnPartition(LongRegisterService.SERVICE_NAME, op, partitionId);
    assertFalse(future.isDone());
    factory.newHazelcastInstance(owner);
    assertClusterSizeEventually(3, hz2);
    assertTrueEventually(() -> assertTrue(future.isDone()));
    // should not fail
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AddAndGetOperation(com.hazelcast.internal.longregister.operations.AddAndGetOperation) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Config(com.hazelcast.config.Config) AddAndGetOperation(com.hazelcast.internal.longregister.operations.AddAndGetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)70 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Address (com.hazelcast.cluster.Address)22 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Operation (com.hazelcast.spi.impl.operationservice.Operation)12 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)10 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 Config (com.hazelcast.config.Config)9 ExecutionException (java.util.concurrent.ExecutionException)9 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)8 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Member (com.hazelcast.cluster.Member)5 Data (com.hazelcast.internal.serialization.Data)5 MapService (com.hazelcast.map.impl.MapService)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5