Search in sources :

Example 16 with IAtomicLong

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

the class CPMemberAddRemoveTest method testMetadataGroupReinitializationAfterLostMajority.

@Test
public void testMetadataGroupReinitializationAfterLostMajority() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    long groupIdSeed = getRaftService(instances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    IAtomicLong long1 = instances[0].getCPSubsystem().getAtomicLong("proxy");
    sleepAtLeastMillis(10);
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    assertClusterSizeEventually(2, instances[3]);
    HazelcastInstance[] newInstances = new HazelcastInstance[3];
    newInstances[0] = instances[0];
    newInstances[1] = instances[3];
    Config config = createConfig(3, 3);
    newInstances[2] = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, newInstances);
    newInstances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    waitUntilCPDiscoveryCompleted(newInstances);
    long newGroupIdSeed = getRaftService(newInstances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId newGroupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    assertThat(newGroupIdSeed, greaterThan(groupIdSeed));
    assertThat(newGroupId.getSeed(), greaterThan(groupId.getSeed()));
    try {
        long1.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    IAtomicLong long2 = newInstances[2].getCPSubsystem().getAtomicLong("proxy");
    long2.incrementAndGet();
    assertTrueEventually(() -> {
        CPGroupSummary group = queryRaftGroupLocally(newInstances[2], getMetadataGroupId(newInstances[2]));
        assertNotNull(group);
        Collection<CPMember> endpoints = group.members();
        for (HazelcastInstance instance : newInstances) {
            Member localMember = instance.getCluster().getLocalMember();
            assertThat(new CPMemberInfo(localMember), isIn(endpoints));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) IAtomicLong(com.hazelcast.cp.IAtomicLong) Member(com.hazelcast.cluster.Member) CPMember(com.hazelcast.cp.CPMember) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 17 with IAtomicLong

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

the class AtomicLongBasicTest method testCreate_withDefaultGroup.

@Test
public void testCreate_withDefaultGroup() {
    IAtomicLong atomicLong = createAtomicLong(randomName());
    assertEquals(DEFAULT_GROUP_NAME, getGroupId(atomicLong).getName());
}
Also used : IAtomicLong(com.hazelcast.cp.IAtomicLong) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with IAtomicLong

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

the class AtomicLongSplitBrainTest method onAfterSplitBrainHealed.

@Override
protected void onAfterSplitBrainHealed(HazelcastInstance[] instances) throws Exception {
    sleepSeconds(3);
    done.set(true);
    for (Future future : futures) {
        assertCompletesEventually(future);
        future.get();
    }
    IAtomicLong atomic = instances[0].getCPSubsystem().getAtomicLong(name);
    assertThat(atomic.get(), greaterThanOrEqualTo(increments.get()));
    assertThat(atomic.get(), lessThanOrEqualTo(increments.get() + indeterminate.get()));
}
Also used : Future(java.util.concurrent.Future) IAtomicLong(com.hazelcast.cp.IAtomicLong)

Example 19 with IAtomicLong

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

the class ExecutorServiceTest method testSubmitToAllMembersCallable.

@Test
public void testSubmitToAllMembersCallable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    final AtomicInteger count = new AtomicInteger(0);
    final CountDownLatch countDownLatch = new CountDownLatch(NODE_COUNT * NODE_COUNT);
    MultiExecutionCallback callback = new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            count.incrementAndGet();
            countDownLatch.countDown();
        }

        public void onComplete(Map<Member, Object> values) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersCallable");
        service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
    }
    assertOpenEventually(countDownLatch);
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersCallable");
    assertEquals(NODE_COUNT * NODE_COUNT, result.get());
    assertEquals(NODE_COUNT * NODE_COUNT, count.get());
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IAtomicLong(com.hazelcast.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with IAtomicLong

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

the class SmallClusterTest method submitToMembers_runnable.

@Test
public void submitToMembers_runnable() {
    int sum = 0;
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[0]);
    Random random = new Random();
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToMembersRunnable");
        int n = random.nextInt(instances.length) + 1;
        sum += n;
        Member[] m = new Member[n];
        System.arraycopy(members, 0, m, 0, n);
        service.submitToMembers(new IncrementAtomicLongRunnable("testSubmitToMembersRunnable"), Arrays.asList(m), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToMembersRunnable");
    assertEquals(sum, result.get());
    assertEquals(sum, callback.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.cp.IAtomicLong) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IAtomicLong (com.hazelcast.cp.IAtomicLong)25 Test (org.junit.Test)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)19 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)17 IExecutorService (com.hazelcast.core.IExecutorService)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 Random (java.util.Random)8 Member (com.hazelcast.cluster.Member)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 SlowTest (com.hazelcast.test.annotation.SlowTest)4 Config (com.hazelcast.config.Config)3 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)3 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)3 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Address (com.hazelcast.cluster.Address)1 MapConfig (com.hazelcast.config.MapConfig)1