Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.iotdb.confignode.manager;

import java.util.Collections;
import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.path.PartialPath;
Expand All @@ -39,6 +38,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/** Manager permission read and operation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.iotdb.confignode.manager;

import java.io.IOException;
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.path.PartialPath;
Expand Down Expand Up @@ -60,6 +59,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.apache.iotdb.consensus.IConsensus;
import org.apache.iotdb.consensus.common.Peer;
import org.apache.iotdb.consensus.config.ConsensusConfig;
import org.apache.iotdb.consensus.exception.ConsensusException;
import org.apache.iotdb.consensus.exception.ConsensusGroupModifyPeerException;
import org.apache.iotdb.consensus.exception.*;
import org.apache.iotdb.consensus.iot.util.TestStateMachine;

import org.apache.ratis.util.FileUtils;
Expand All @@ -41,6 +40,8 @@
import java.io.IOException;
import java.util.Collections;

import static org.junit.Assert.assertTrue;

public class StabilityTest {

private final ConsensusGroupId dataRegionId = new DataRegionId(1);
Expand All @@ -49,7 +50,7 @@ public class StabilityTest {

private IConsensus consensusImpl;

private final int basePort = 9000;
private final int basePort = 6667;

public void constructConsensus() throws IOException {
consensusImpl =
Expand Down Expand Up @@ -84,11 +85,64 @@ public void tearDown() throws IOException {

@Test
public void allTest() throws Exception {
addConsensusGroup();
removeConsensusGroup();
peerTest();
transferLeader();
snapshotTest();
snapshotUpgradeTest();
}

public void addConsensusGroup() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put all tests in the alltest function, because frequent restarts will cause a can not bind socket error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

try {
consensusImpl.createLocalPeer(
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
Assert.fail();
}

try {
consensusImpl.createLocalPeer(
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
assertTrue(e instanceof ConsensusGroupAlreadyExistException);
}

try {
consensusImpl.createLocalPeer(dataRegionId, Collections.emptyList());
} catch (ConsensusException e) {
assertTrue(e instanceof IllegalPeerNumException);
}

try {
consensusImpl.createLocalPeer(
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.1", 6667))));
} catch (ConsensusException e) {
assertTrue(e instanceof IllegalPeerEndpointException);
}
}

public void removeConsensusGroup() throws ConsensusException {
try {
consensusImpl.deleteLocalPeer(dataRegionId);
} catch (ConsensusException e) {
assertTrue(e instanceof ConsensusGroupNotExistException);
}

try {
consensusImpl.createLocalPeer(
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
Assert.fail();
}

consensusImpl.deleteLocalPeer(dataRegionId);
}

public void peerTest() throws Exception {
consensusImpl.createLocalPeer(
dataRegionId,
Expand All @@ -106,6 +160,16 @@ public void peerTest() throws Exception {
consensusImpl.deleteLocalPeer(dataRegionId);
}

public void transferLeader() {
try {
consensusImpl.transferLeader(
dataRegionId, new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667)));
Assert.fail("Can't transfer leader in SimpleConsensus.");
} catch (ConsensusException e) {
assert true;
}
}

public void snapshotTest() throws IOException, ConsensusException {
consensusImpl.createLocalPeer(
dataRegionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.apache.iotdb.consensus.common.Peer;
import org.apache.iotdb.consensus.common.request.ByteBufferConsensusRequest;
import org.apache.iotdb.consensus.config.RatisConfig;
import org.apache.iotdb.consensus.exception.ConsensusException;
import org.apache.iotdb.consensus.exception.ConsensusGroupAlreadyExistException;
import org.apache.iotdb.consensus.exception.*;
import org.apache.iotdb.rpc.TSStatusCode;

import org.apache.ratis.util.TimeDuration;
Expand Down Expand Up @@ -135,6 +134,11 @@ public void addMemberToGroup() throws Exception {

@Test
public void removeMemberFromGroup() throws Exception {
try {
servers.get(0).deleteLocalPeer(group.getGroupId());
} catch (ConsensusException e) {
Assert.assertTrue(e instanceof ConsensusGroupNotExistException);
}
servers.get(0).createLocalPeer(group.getGroupId(), group.getPeers());
servers.get(1).createLocalPeer(group.getGroupId(), group.getPeers());
servers.get(2).createLocalPeer(group.getGroupId(), group.getPeers());
Expand All @@ -152,15 +156,35 @@ public void removeMemberFromGroup() throws Exception {

@Test
public void oneMemberGroupChange() throws Exception {
try {
servers.get(0).addRemotePeer(group.getGroupId(), peers.get(0));
} catch (ConsensusException e) {
Assert.assertTrue(e instanceof ConsensusGroupNotExistException);
}
servers.get(0).createLocalPeer(group.getGroupId(), peers.subList(0, 1));
doConsensus(servers.get(0), group.getGroupId(), 10, 10);

servers.get(1).createLocalPeer(group.getGroupId(), Collections.emptyList());
servers.get(0).addRemotePeer(group.getGroupId(), peers.get(1));
try {
servers.get(0).addRemotePeer(group.getGroupId(), peers.get(1));
} catch (ConsensusException e) {
Assert.assertTrue(e instanceof PeerAlreadyInConsensusGroupException);
}
servers.get(1).transferLeader(group.getGroupId(), peers.get(1));
servers.get(0).removeRemotePeer(group.getGroupId(), peers.get(0));
try {
servers.get(0).removeRemotePeer(group.getGroupId(), peers.get(0));
} catch (ConsensusException e) {
Assert.assertTrue(e instanceof PeerNotInConsensusGroupException);
}
Assert.assertEquals(servers.get(1).getLeader(gid).getNodeId(), peers.get(1).getNodeId());
servers.get(0).deleteLocalPeer(group.getGroupId());
try {
servers.get(0).removeRemotePeer(group.getGroupId(), peers.get(0));
} catch (ConsensusException e) {
Assert.assertTrue(e instanceof ConsensusGroupNotExistException);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void addConsensusGroup() {
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
throw new RuntimeException(e);
Assert.fail();
}

try {
Expand Down Expand Up @@ -203,7 +203,7 @@ public void addConsensusGroup() {
schemaRegionId,
Collections.singletonList(new Peer(schemaRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
throw new RuntimeException(e);
Assert.fail();
}
}

Expand All @@ -220,7 +220,7 @@ public void removeConsensusGroup() throws ConsensusException {
dataRegionId,
Collections.singletonList(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 6667))));
} catch (ConsensusException e) {
throw new RuntimeException(e);
Assert.fail();
}

consensusImpl.deleteLocalPeer(dataRegionId);
Expand Down Expand Up @@ -283,12 +283,12 @@ public void write() throws ConsensusException {
consensusImpl.createLocalPeer(
configId, Collections.singletonList(new Peer(configId, 1, new TEndPoint("0.0.0.0", 6667))));

// test new TestStateMachine(true), should return 1;
// test new TestStateMachine(false), should return -1;
TSStatus response4 = consensusImpl.write(dataRegionId, entry1);
assertNotNull(response4);
assertEquals(-1, response4.getCode());

// test new TestStateMachine(false), should return -1;
// test new TestStateMachine(true), should return 1;
TSStatus response5 = consensusImpl.write(schemaRegionId, entry1);
assertNotNull(response5);
assertEquals(1, response5.getCode());
Expand Down