Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for CP Membership restart issues #24903

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,7 @@
package com.hazelcast.cp.internal;

import com.hazelcast.cluster.Address;
import com.hazelcast.cluster.ClusterState;
import com.hazelcast.cluster.Member;
import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
Expand Down Expand Up @@ -401,14 +402,46 @@ public void testExpandRaftGroup() throws ExecutionException, InterruptedExceptio
instances[3].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember()
.toCompletableFuture().get(30, TimeUnit.SECONDS);

CPGroupId metadataGroupId = getMetadataGroupId(instances[1]);
CPGroup group = instances[1].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME)
.toCompletableFuture().get();
checkIfInCPGroup(instances[1]);
}

@Test
public void contractAndReExpandRaftGroup_leaveTwoRunning() throws ExecutionException, InterruptedException, TimeoutException {
HazelcastInstance[] instances = newInstances(3);
instances[2].shutdown();
assertClusterSizeEventually(2, instances[0], instances[1]);
HazelcastInstance hz1 = factory.newHazelcastInstance(createConfig(3, 3));
assertClusterStateEventually(ClusterState.ACTIVE, hz1);
assertClusterSizeEventually(3, instances[0], instances[1], hz1);
hz1.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
checkIfInCPGroup(hz1);
}

@Test
public void contractAndReExpandRaftGroup_leaveOneRunning() throws ExecutionException, InterruptedException, TimeoutException {
HazelcastInstance[] instances = newInstances(3);
instances[1].shutdown();
instances[2].shutdown();
assertClusterSizeEventually(1, instances[0]);
HazelcastInstance hz1 = factory.newHazelcastInstance(createConfig(3, 3));
HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig(3, 3));
assertClusterStateEventually(ClusterState.ACTIVE, hz1, hz2);
assertClusterSizeEventually(3, instances[0], hz1, hz2);
hz1.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
hz2.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
checkIfInCPGroup(hz1);
checkIfInCPGroup(hz2);
}

private static void checkIfInCPGroup(HazelcastInstance instance) throws InterruptedException, ExecutionException {
CPGroupId metadataGroupId = getMetadataGroupId(instance);
CPGroup group = instance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME)
.toCompletableFuture().get();
assertEquals(3, group.members().size());
Collection<CPMember> members = group.members();
assertTrue(members.contains(instances[3].getCPSubsystem().getLocalCPMember()));
assertTrue(members.contains(instance.getCPSubsystem().getLocalCPMember()));

assertTrueEventually(() -> assertNotNull(getRaftNode(instances[3], metadataGroupId)));
assertTrueEventually(() -> assertNotNull(getRaftNode(instance, metadataGroupId)));
}

@Test
Expand Down
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hazelcast.cp.internal;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.test.HazelcastParallelParametersRunnerFactory;
import com.hazelcast.test.HazelcastParametrizedRunner;
import com.hazelcast.test.annotation.ParallelJVMTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.UseParametersRunnerFactory;
import java.util.UUID;

import static com.hazelcast.cp.internal.HazelcastRaftTestSupport.waitUntilCPDiscoveryCompleted;
import static org.junit.Assert.assertEquals;

@RunWith(HazelcastParametrizedRunner.class)
@UseParametersRunnerFactory(HazelcastParallelParametersRunnerFactory.class)
@Category({QuickTest.class, ParallelJVMTest.class})
public class CPMemberSplitBrainTest extends RaftSplitBrainTestSupport {
@Override
protected void onBeforeSplitBrainCreated(HazelcastInstance[] instances) {
waitUntilCPDiscoveryCompleted(instances);
assertEquals(5, instances[0].getCPSubsystem().getCPSubsystemManagementService()
.getCPMembers().toCompletableFuture().join().size());
}

@Override
protected void onAfterSplitBrainCreated(HazelcastInstance[] firstBrain, HazelcastInstance[] secondBrain) {
UUID uuid = secondBrain[0].getCPSubsystem().getLocalCPMember().getUuid();
firstBrain[0].getCPSubsystem().getCPSubsystemManagementService().removeCPMember(uuid).toCompletableFuture().join();
}

@Override
protected void onAfterSplitBrainHealed(HazelcastInstance[] instances) throws Exception {
assertEqualsEventually(() -> instances[0].getCPSubsystem().getCPSubsystemManagementService()
.getCPMembers().toCompletableFuture().join().size(), 5);
}
}