[ISSUE #3741] Use wait-until-${async-complete}-reaches DSL instead of sleep(n) to to reduce invalid wait time. (#3829)

This commit is contained in:
Hongjian Fei
2022-02-09 11:20:50 +08:00
committed by GitHub
parent 0b4adb49b4
commit 631405e2fb
@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -39,6 +40,9 @@ import org.apache.rocketmq.store.PutMessageStatus;
import org.junit.Assert;
import org.junit.Test;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
public class DLedgerCommitlogTest extends MessageStoreTestBase {
@@ -330,10 +334,9 @@ public class DLedgerCommitlogTest extends MessageStoreTestBase {
DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group, "n1", peers, "n0", false, 0);
Thread.sleep(10000);
await().atMost(10, SECONDS).until(followerCatchesUp(followerStore, topic));
Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);
@@ -364,10 +367,9 @@ public class DLedgerCommitlogTest extends MessageStoreTestBase {
DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group, "n1", peers, "n0", false, 0);
Thread.sleep(10000);
await().atMost(10, SECONDS).until(followerCatchesUp(followerStore, topic));
Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);
@@ -378,5 +380,7 @@ public class DLedgerCommitlogTest extends MessageStoreTestBase {
followerStore.shutdown();
}
private Callable<Boolean> followerCatchesUp(DefaultMessageStore followerStore, String topic) {
return () -> followerStore.getMaxOffsetInQueue(topic, 0) == 1;
}
}