This is an automated email from the ASF dual-hosted git repository. tanxinyu pushed a commit to branch jira6061_cp in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit e1f2e80f1a29e752211caa3bae031dcf2c0c56b4 Author: OneSizeFitQuorum <[email protected]> AuthorDate: Tue Aug 29 18:31:27 2023 +0800 fix Signed-off-by: OneSizeFitQuorum <[email protected]> --- .../apache/iotdb/consensus/iot/ReplicateTest.java | 118 +++++++++++---------- 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java index 39eab9c5dd7..2c202324b2a 100644 --- a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java +++ b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java @@ -53,6 +53,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; public class ReplicateTest { + private static final long CHECK_POINT_GAP = 500; private final Logger logger = LoggerFactory.getLogger(ReplicateTest.class); @@ -201,34 +202,39 @@ public class ReplicateTest { Assert.assertEquals(stateMachines.get(0).getData(), stateMachines.get(1).getData()); Assert.assertEquals(stateMachines.get(2).getData(), stateMachines.get(1).getData()); - stopServer(); - initServer(); - - Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration()); - Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration()); - Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration()); - - Assert.assertEquals(CHECK_POINT_GAP, servers.get(0).getImpl(gid).getSearchIndex()); - Assert.assertEquals(CHECK_POINT_GAP, servers.get(1).getImpl(gid).getSearchIndex()); - Assert.assertEquals(CHECK_POINT_GAP, servers.get(2).getImpl(gid).getSearchIndex()); - - for (int i = 0; i < 3; i++) { - long start = System.currentTimeMillis(); - while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() < CHECK_POINT_GAP) { - long current = System.currentTimeMillis(); - if ((current - start) > 60 * 1000) { - Assert.fail("Unable to recover entries"); + try { + stopServer(); + initServer(); + + Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration()); + Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration()); + Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration()); + + Assert.assertEquals(CHECK_POINT_GAP, servers.get(0).getImpl(gid).getSearchIndex()); + Assert.assertEquals(CHECK_POINT_GAP, servers.get(1).getImpl(gid).getSearchIndex()); + Assert.assertEquals(CHECK_POINT_GAP, servers.get(2).getImpl(gid).getSearchIndex()); + + for (int i = 0; i < 3; i++) { + long start = System.currentTimeMillis(); + while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() < CHECK_POINT_GAP) { + long current = System.currentTimeMillis(); + if ((current - start) > 60 * 1000) { + Assert.fail("Unable to recover entries"); + } + Thread.sleep(100); } - Thread.sleep(100); } - } - Assert.assertEquals( - CHECK_POINT_GAP, servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); - Assert.assertEquals( - CHECK_POINT_GAP, servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); - Assert.assertEquals( - CHECK_POINT_GAP, servers.get(2).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); + Assert.assertEquals( + CHECK_POINT_GAP, servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); + Assert.assertEquals( + CHECK_POINT_GAP, servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); + Assert.assertEquals( + CHECK_POINT_GAP, servers.get(2).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); + + } catch (IOException e) { + logger.info("can not start IoTConsensus because", e); + } } /** @@ -255,39 +261,43 @@ public class ReplicateTest { Assert.assertEquals(0, servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); Assert.assertEquals(0, servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); - stopServer(); - initServer(); - - servers.get(2).createLocalPeer(group.getGroupId(), group.getPeers()); - - Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration()); - Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration()); - Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration()); - - Assert.assertEquals(CHECK_POINT_GAP, servers.get(0).getImpl(gid).getSearchIndex()); - Assert.assertEquals(CHECK_POINT_GAP, servers.get(1).getImpl(gid).getSearchIndex()); - Assert.assertEquals(0, servers.get(2).getImpl(gid).getSearchIndex()); - - for (int i = 0; i < 2; i++) { - long start = System.currentTimeMillis(); - // should be [CHECK_POINT_GAP, CHECK_POINT_GAP * 2 - 1] after - // replicating all entries - while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() < CHECK_POINT_GAP) { - long current = System.currentTimeMillis(); - if ((current - start) > 60 * 1000) { - logger.error("{}", servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); - Assert.fail("Unable to replicate entries"); + try { + stopServer(); + initServer(); + + servers.get(2).createLocalPeer(group.getGroupId(), group.getPeers()); + + Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration()); + Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration()); + Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration()); + + Assert.assertEquals(CHECK_POINT_GAP, servers.get(0).getImpl(gid).getSearchIndex()); + Assert.assertEquals(CHECK_POINT_GAP, servers.get(1).getImpl(gid).getSearchIndex()); + Assert.assertEquals(0, servers.get(2).getImpl(gid).getSearchIndex()); + + for (int i = 0; i < 2; i++) { + long start = System.currentTimeMillis(); + // should be [CHECK_POINT_GAP, CHECK_POINT_GAP * 2 - 1] after + // replicating all entries + while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() < CHECK_POINT_GAP) { + long current = System.currentTimeMillis(); + if ((current - start) > 60 * 1000) { + logger.error("{}", servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex()); + Assert.fail("Unable to replicate entries"); + } + Thread.sleep(100); } - Thread.sleep(100); } - } - Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(0).getRequestSet().size()); - Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(1).getRequestSet().size()); - Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(2).getRequestSet().size()); + Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(0).getRequestSet().size()); + Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(1).getRequestSet().size()); + Assert.assertEquals(CHECK_POINT_GAP * 2, stateMachines.get(2).getRequestSet().size()); - Assert.assertEquals(stateMachines.get(0).getData(), stateMachines.get(1).getData()); - Assert.assertEquals(stateMachines.get(2).getData(), stateMachines.get(1).getData()); + Assert.assertEquals(stateMachines.get(0).getData(), stateMachines.get(1).getData()); + Assert.assertEquals(stateMachines.get(2).getData(), stateMachines.get(1).getData()); + } catch (IOException e) { + logger.info("can not start IoTConsensus because", e); + } } private void findPortAvailable(int i) {
