Search in sources :

Example 76 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromLeader_withLeaderLocalPolicy_thenReadLatestValue.

@Test
public void when_queryLocalFromLeader_withLeaderLocalPolicy_thenReadLatestValue() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    String value = "value";
    invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
    HazelcastInstance leader = getLeaderInstance(instances, groupId);
    Future<Object> future = getRaftInvocationManager(leader).queryLocally(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
    assertEquals(value, future.get());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 77 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromFollower_withoutAnyCommit_thenReturnDefaultValue.

@Test
public void when_queryLocalFromFollower_withoutAnyCommit_thenReturnDefaultValue() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
    Future<Object> future = getRaftInvocationManager(follower).query(groupId, new RaftTestQueryOp(), ANY_LOCAL);
    assertNull(future.get());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 78 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromLeader_withoutAnyCommit_thenReturnDefaultValue.

@Test
public void when_queryLocalFromLeader_withoutAnyCommit_thenReturnDefaultValue() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    Future<Object> future = invocationService.query(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
    assertNull(future.get());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 79 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationFailureTest method test_invocationFailsWithStaleAppendRequestException_when_thereAreRetryableExceptionsAfterwards.

@Test
public void test_invocationFailsWithStaleAppendRequestException_when_thereAreRetryableExceptionsAfterwards() throws ExecutionException, InterruptedException {
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup(groupName).get();
    waitAllForLeaderElection(instances, groupId);
    HazelcastInstance leader = getLeaderInstance(instances, groupId);
    Future f = new RaftInvocation(getOperationService(leader).invocationContext, getRaftInvocationManager(leader).getRaftInvocationContext(), groupId, new DefaultRaftReplicateOp(groupId, new CustomResponseOp3()), 100, 500, 60000).invoke();
    try {
        f.get(60, TimeUnit.SECONDS);
        fail();
    } catch (Exception e) {
        assertInstanceOf(IndeterminateOperationStateException.class, e.getCause());
    }
    assertTrue(COMMIT_COUNT.get() > groupSize);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) DefaultRaftReplicateOp(com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp) StaleAppendRequestException(com.hazelcast.cp.exception.StaleAppendRequestException) CallerNotMemberException(com.hazelcast.spi.exception.CallerNotMemberException) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationFailureTest method test_invocationFailsOnMemberLeftException.

@Test
public void test_invocationFailsOnMemberLeftException() throws ExecutionException, InterruptedException {
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup(groupName).get();
    waitAllForLeaderElection(instances, groupId);
    HazelcastInstance leader = getLeaderInstance(instances, groupId);
    Future f = new RaftInvocation(getOperationService(leader).invocationContext, getRaftInvocationManager(leader).getRaftInvocationContext(), groupId, new DefaultRaftReplicateOp(groupId, new CustomResponseOp()), 10, 50, 60000).invoke();
    try {
        f.get(60, TimeUnit.SECONDS);
        fail();
    } catch (Exception e) {
        assertInstanceOf(IndeterminateOperationStateException.class, e.getCause());
    }
    assertTrue(COMMIT_COUNT.get() <= groupSize);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) DefaultRaftReplicateOp(com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp) StaleAppendRequestException(com.hazelcast.cp.exception.StaleAppendRequestException) CallerNotMemberException(com.hazelcast.spi.exception.CallerNotMemberException) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5