From 27622c58250dbf33f4fcd281cba3758a9c22eac4 Mon Sep 17 00:00:00 2001 From: a51764579 Date: Sat, 2 Mar 2019 09:54:59 +0800 Subject: [PATCH] [RIP-10]HA test case optimization and reduce the time spent (#931) [RIP-10]HA test case optimization and reduce the time spent --- .../org/apache/rocketmq/store/HATest.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/store/src/test/java/org/apache/rocketmq/store/HATest.java b/store/src/test/java/org/apache/rocketmq/store/HATest.java index 0a166d95..83efcc19 100644 --- a/store/src/test/java/org/apache/rocketmq/store/HATest.java +++ b/store/src/test/java/org/apache/rocketmq/store/HATest.java @@ -29,6 +29,9 @@ import org.junit.Before; import org.junit.Test; import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -90,7 +93,7 @@ public class HATest { } @Test - public void testHandleHA() throws Exception{ + public void testHandleHA() { long totalMsgs = 10; QUEUE_TOTAL = 1; MessageBody = StoreMessage.getBytes(); @@ -98,7 +101,20 @@ public class HATest { messageStore.putMessage(buildMessage()); } - Thread.sleep(1000L);//sleep 1000 ms + for (int i = 0; i < 100 && isCommitLogAvailable((DefaultMessageStore) messageStore); i++) { + try { + Thread.sleep(100); + } catch (InterruptedException ignored) { + } + } + + for (int i = 0; i < 100 && isCommitLogAvailable((DefaultMessageStore) slaveMessageStore); i++) { + try { + Thread.sleep(100); + } catch (InterruptedException ignored) { + } + } + for (long i = 0; i < totalMsgs; i++) { GetMessageResult result = slaveMessageStore.getMessage("GROUP_A", "FooBar", 0, i, 1024 * 1024, null); assertThat(result).isNotNull(); @@ -147,4 +163,20 @@ public class HATest { return msg; } + private boolean isCommitLogAvailable(DefaultMessageStore store) { + try { + + Field serviceField = store.getClass().getDeclaredField("reputMessageService"); + serviceField.setAccessible(true); + DefaultMessageStore.ReputMessageService reputService = + (DefaultMessageStore.ReputMessageService) serviceField.get(store); + + Method method = DefaultMessageStore.ReputMessageService.class.getDeclaredMethod("isCommitLogAvailable"); + method.setAccessible(true); + return (boolean) method.invoke(reputService); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e ) { + throw new RuntimeException(e); + } + } + } -- GitLab