Search in sources :

Example 76 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LeadershipTransferTest method testFollowerCannotTransferLeadership.

@Test
public void testFollowerCannotTransferLeadership() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl follower = group.getNodesExcept(leader.getLocalMember())[0];
    InternalCompletableFuture f = follower.transferLeadership(leader.getLocalMember());
    exceptionRule.expect(IllegalStateException.class);
    f.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 77 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LeadershipTransferTest method testTransferLeadershipTimesOutWhenTargetCannotCatchupInTime.

@Test
public void testTransferLeadershipTimesOutWhenTargetCannotCatchupInTime() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl follower = group.getNodesExcept(leader.getLocalMember())[0];
    group.dropMessagesToMember(leader.getLocalMember(), follower.getLocalMember(), AppendRequest.class);
    leader.replicate(new NopEntry()).get();
    InternalCompletableFuture f = leader.transferLeadership(follower.getLocalMember());
    exceptionRule.expect(IllegalStateException.class);
    f.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) NopEntry(com.hazelcast.cp.internal.raft.impl.testing.NopEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 78 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LeadershipTransferTest method testAnotherTransferLeadershipRequestFailsDuringOngoingLeadershipTransfer.

@Test
public void testAnotherTransferLeadershipRequestFailsDuringOngoingLeadershipTransfer() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    RaftNodeImpl follower1 = followers[0];
    RaftNodeImpl follower2 = followers[1];
    group.dropMessagesToMember(leader.getLocalMember(), follower1.getLocalMember(), AppendRequest.class);
    leader.replicate(new NopEntry()).get();
    leader.transferLeadership(follower1.getLocalMember());
    InternalCompletableFuture f = leader.transferLeadership(follower2.getLocalMember());
    exceptionRule.expect(IllegalStateException.class);
    f.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) NopEntry(com.hazelcast.cp.internal.raft.impl.testing.NopEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 79 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LeadershipTransferTest method testCannotTransferLeadershipToNull.

@Test
public void testCannotTransferLeadershipToNull() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    InternalCompletableFuture future = leader.transferLeadership(null);
    exceptionRule.expect(IllegalArgumentException.class);
    future.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class MapRemoveFailingBackupTest method testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled.

@Test
public void testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final String mapName = randomMapName();
    final String key = "2";
    final String value = "value2";
    Config config = getConfig();
    config.getSerializationConfig().addDataSerializableFactory(100, new Factory());
    config.setProperty(ClusterProperty.PARTITION_BACKUP_SYNC_INTERVAL.getName(), "5");
    config.getMapConfig(mapName).setReadBackupData(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    final NodeEngine nodeEngine = getNodeEngineImpl(hz1);
    final IMap<Object, Object> map1 = hz1.getMap(mapName);
    final IMap<Object, Object> map2 = hz2.getMap(mapName);
    MapProxyImpl<Object, Object> mock1 = (MapProxyImpl<Object, Object>) spy(map1);
    when(mock1.remove(anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object object = invocation.getArguments()[0];
            final Data key = nodeEngine.toData(object);
            RemoveOperation operation = new RemoveOperation(mapName, key);
            int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
            operation.setThreadId(ThreadUtil.getThreadId());
            OperationService operationService = nodeEngine.getOperationService();
            InternalCompletableFuture<Data> f = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).invoke();
            Data result = f.get();
            return nodeEngine.toObject(result);
        }
    });
    mock1.put(key, value);
    mock1.remove(key);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertNull(map1.get(key));
            assertNull(map2.get(key));
        }
    }, 30);
}
Also used : Config(com.hazelcast.config.Config) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) BaseRemoveOperation(com.hazelcast.map.impl.operation.BaseRemoveOperation) Data(com.hazelcast.internal.serialization.Data) Matchers.anyString(org.mockito.Matchers.anyString) NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6