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));
}
});
}
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());
}
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()));
}
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());
}
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());
}
Aggregations