You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/09/29 09:22:09 UTC
[rocketmq] branch develop updated: [ISSUE #5221] Enable checkstyle for test code (rocketmq-store) (#5222)
This is an automated email from the ASF dual-hosted git repository.
lizhanhui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new b0d0deca0 [ISSUE #5221] Enable checkstyle for test code (rocketmq-store) (#5222)
b0d0deca0 is described below
commit b0d0deca0be9848cf35561010fb90d5edff8a8d2
Author: Nowinkey <no...@tom.com>
AuthorDate: Thu Sep 29 17:22:01 2022 +0800
[ISSUE #5221] Enable checkstyle for test code (rocketmq-store) (#5222)
* style(store):Enable checkstyle for test code
* style(store):Enable checkstyle for test code (supplement)
---
store/pom.xml | 24 +++++++
.../apache/rocketmq/store/ConsumeQueueExtTest.java | 66 ++++++++---------
.../apache/rocketmq/store/ConsumeQueueTest.java | 84 +++++++++++-----------
.../apache/rocketmq/store/MappedFileQueueTest.java | 4 +-
.../apache/rocketmq/store/MultiDispatchTest.java | 2 +-
.../rocketmq/store/StoreStatsServiceTest.java | 2 -
.../org/apache/rocketmq/store/StoreTestBase.java | 32 ++++-----
.../org/apache/rocketmq/store/StoreTestUtil.java | 4 +-
.../org/apache/rocketmq/store/ha/HAClientTest.java | 2 -
.../store/ha/autoswitch/AutoSwitchHATest.java | 31 ++++----
.../apache/rocketmq/store/index/IndexFileTest.java | 4 +-
.../store/queue/BatchConsumeMessageTest.java | 2 +-
.../apache/rocketmq/store/queue/QueueTestBase.java | 4 +-
.../store/stats/BrokerStatsManagerTest.java | 8 +--
.../apache/rocketmq/store/timer/TimerLogTest.java | 4 +-
.../store/timer/TimerMessageStoreTest.java | 9 ++-
.../rocketmq/store/timer/TimerMetricsTest.java | 31 ++++----
17 files changed, 169 insertions(+), 144 deletions(-)
diff --git a/store/pom.xml b/store/pom.xml
index d0ea8bef5..0ccdce2d0 100644
--- a/store/pom.xml
+++ b/store/pom.xml
@@ -64,4 +64,28 @@
<artifactId>guava</artifactId>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${maven-checkstyle-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>validate</id>
+ <phase>validate</phase>
+ <configuration>
+ <configLocation>${project.parent.basedir}/style/rmq_checkstyle.xml</configLocation>
+ <inputEncoding>UTF-8</inputEncoding>
+ <consoleOutput>true</consoleOutput>
+ <failsOnError>true</failsOnError>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ </configuration>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java
index 1af6f8922..b1ec617ec 100644
--- a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java
@@ -27,17 +27,17 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ConsumeQueueExtTest {
- private static final String topic = "abc";
- private static final int queueId = 0;
- private static final String storePath = System.getProperty("java.io.tmpdir") + File.separator + "unit_test_store";
- private static final int bitMapLength = 64;
- private static final int unitSizeWithBitMap = ConsumeQueueExt.CqExtUnit.MIN_EXT_UNIT_SIZE + bitMapLength / Byte.SIZE;
- private static final int cqExtFileSize = 10 * unitSizeWithBitMap;
- private static final int unitCount = 20;
+ private static final String TOPIC = "abc";
+ private static final int QUEUE_ID = 0;
+ private static final String STORE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "unit_test_store";
+ private static final int BIT_MAP_LENGTH = 64;
+ private static final int UNIT_SIZE_WITH_BIT_MAP = ConsumeQueueExt.CqExtUnit.MIN_EXT_UNIT_SIZE + BIT_MAP_LENGTH / Byte.SIZE;
+ private static final int CQ_EXT_FILE_SIZE = 10 * UNIT_SIZE_WITH_BIT_MAP;
+ private static final int UNIT_COUNT = 20;
protected ConsumeQueueExt genExt() {
return new ConsumeQueueExt(
- topic, queueId, storePath, cqExtFileSize, bitMapLength
+ TOPIC, QUEUE_ID, STORE_PATH, CQ_EXT_FILE_SIZE, BIT_MAP_LENGTH
);
}
@@ -56,7 +56,7 @@ public class ConsumeQueueExtTest {
cqExtUnit.setTagsCode(Math.abs((new Random(System.currentTimeMillis())).nextInt()));
cqExtUnit.setMsgStoreTime(System.currentTimeMillis());
if (hasBitMap) {
- cqExtUnit.setFilterBitMap(genBitMap(bitMapLength));
+ cqExtUnit.setFilterBitMap(genBitMap(BIT_MAP_LENGTH));
}
return cqExtUnit;
@@ -92,10 +92,10 @@ public class ConsumeQueueExtTest {
ConsumeQueueExt consumeQueueExt = genExt();
try {
- putSth(consumeQueueExt, true, false, unitCount);
+ putSth(consumeQueueExt, true, false, UNIT_COUNT);
} finally {
consumeQueueExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -103,7 +103,7 @@ public class ConsumeQueueExtTest {
public void testGet() {
ConsumeQueueExt consumeQueueExt = genExt();
- putSth(consumeQueueExt, false, false, unitCount);
+ putSth(consumeQueueExt, false, false, UNIT_COUNT);
try {
// from start.
@@ -123,7 +123,7 @@ public class ConsumeQueueExtTest {
}
} finally {
consumeQueueExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -131,21 +131,21 @@ public class ConsumeQueueExtTest {
public void testGet_invalidAddress() {
ConsumeQueueExt consumeQueueExt = genExt();
- putSth(consumeQueueExt, false, true, unitCount);
+ putSth(consumeQueueExt, false, true, UNIT_COUNT);
try {
ConsumeQueueExt.CqExtUnit unit = consumeQueueExt.get(0);
assertThat(unit).isNull();
- long addr = (cqExtFileSize / unitSizeWithBitMap) * unitSizeWithBitMap;
- addr += unitSizeWithBitMap;
+ long addr = (CQ_EXT_FILE_SIZE / UNIT_SIZE_WITH_BIT_MAP) * UNIT_SIZE_WITH_BIT_MAP;
+ addr += UNIT_SIZE_WITH_BIT_MAP;
unit = consumeQueueExt.get(addr);
assertThat(unit).isNull();
} finally {
consumeQueueExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -153,7 +153,7 @@ public class ConsumeQueueExtTest {
public void testRecovery() {
ConsumeQueueExt putCqExt = genExt();
- putSth(putCqExt, false, true, unitCount);
+ putSth(putCqExt, false, true, UNIT_COUNT);
ConsumeQueueExt loadCqExt = genExt();
@@ -165,25 +165,25 @@ public class ConsumeQueueExtTest {
assertThat(loadCqExt.getMinAddress()).isEqualTo(Long.MIN_VALUE);
// same unit size.
- int countPerFile = (cqExtFileSize - ConsumeQueueExt.END_BLANK_DATA_LENGTH) / unitSizeWithBitMap;
+ int countPerFile = (CQ_EXT_FILE_SIZE - ConsumeQueueExt.END_BLANK_DATA_LENGTH) / UNIT_SIZE_WITH_BIT_MAP;
- int lastFileUnitCount = unitCount % countPerFile;
+ int lastFileUnitCount = UNIT_COUNT % countPerFile;
- int fileCount = unitCount / countPerFile + 1;
+ int fileCount = UNIT_COUNT / countPerFile + 1;
if (lastFileUnitCount == 0) {
fileCount -= 1;
}
if (lastFileUnitCount == 0) {
- assertThat(loadCqExt.unDecorate(loadCqExt.getMaxAddress()) % cqExtFileSize).isEqualTo(0);
+ assertThat(loadCqExt.unDecorate(loadCqExt.getMaxAddress()) % CQ_EXT_FILE_SIZE).isEqualTo(0);
} else {
assertThat(loadCqExt.unDecorate(loadCqExt.getMaxAddress()))
- .isEqualTo(lastFileUnitCount * unitSizeWithBitMap + (fileCount - 1) * cqExtFileSize);
+ .isEqualTo(lastFileUnitCount * UNIT_SIZE_WITH_BIT_MAP + (fileCount - 1) * CQ_EXT_FILE_SIZE);
}
} finally {
putCqExt.destroy();
loadCqExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -191,13 +191,13 @@ public class ConsumeQueueExtTest {
public void testTruncateByMinOffset() {
ConsumeQueueExt consumeQueueExt = genExt();
- putSth(consumeQueueExt, false, true, unitCount * 2);
+ putSth(consumeQueueExt, false, true, UNIT_COUNT * 2);
try {
// truncate first one file.
- long address = consumeQueueExt.decorate((long) (cqExtFileSize * 1.5));
+ long address = consumeQueueExt.decorate((long) (CQ_EXT_FILE_SIZE * 1.5));
- long expectMinAddress = consumeQueueExt.decorate(cqExtFileSize);
+ long expectMinAddress = consumeQueueExt.decorate(CQ_EXT_FILE_SIZE);
consumeQueueExt.truncateByMinAddress(address);
@@ -206,7 +206,7 @@ public class ConsumeQueueExtTest {
assertThat(expectMinAddress).isEqualTo(minAddress);
} finally {
consumeQueueExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -214,13 +214,13 @@ public class ConsumeQueueExtTest {
public void testTruncateByMaxOffset() {
ConsumeQueueExt consumeQueueExt = genExt();
- putSth(consumeQueueExt, false, true, unitCount * 2);
+ putSth(consumeQueueExt, false, true, UNIT_COUNT * 2);
try {
// truncate, only first 3 files exist.
- long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);
+ long address = consumeQueueExt.decorate(CQ_EXT_FILE_SIZE * 2 + UNIT_SIZE_WITH_BIT_MAP);
- long expectMaxAddress = address + unitSizeWithBitMap;
+ long expectMaxAddress = address + UNIT_SIZE_WITH_BIT_MAP;
consumeQueueExt.truncateByMaxAddress(address);
@@ -229,12 +229,12 @@ public class ConsumeQueueExtTest {
assertThat(expectMaxAddress).isEqualTo(maxAddress);
} finally {
consumeQueueExt.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@After
public void destroy() {
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
index c281cecc0..c805f078b 100644
--- a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java
@@ -45,28 +45,28 @@ import static org.awaitility.Awaitility.await;
public class ConsumeQueueTest {
- private static final String msg = "Once, there was a chance for me!";
- private static final byte[] msgBody = msg.getBytes();
+ private static final String MSG = "Once, there was a chance for me!";
+ private static final byte[] MSG_BODY = MSG.getBytes();
- private static final String topic = "abc";
- private static final int queueId = 0;
- private static final String storePath = System.getProperty("java.io.tmpdir") + File.separator + "unit_test_store";
- private static final int commitLogFileSize = 1024 * 8;
- private static final int cqFileSize = 10 * 20;
- private static final int cqExtFileSize = 10 * (ConsumeQueueExt.CqExtUnit.MIN_EXT_UNIT_SIZE + 64);
+ private static final String TOPIC = "abc";
+ private static final int QUEUE_ID = 0;
+ private static final String STORE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "unit_test_store";
+ private static final int COMMIT_LOG_FILE_SIZE = 1024 * 8;
+ private static final int CQ_FILE_SIZE = 10 * 20;
+ private static final int CQ_EXT_FILE_SIZE = 10 * (ConsumeQueueExt.CqExtUnit.MIN_EXT_UNIT_SIZE + 64);
- private static SocketAddress BornHost;
+ private static SocketAddress bornHost;
- private static SocketAddress StoreHost;
+ private static SocketAddress storeHost;
static {
try {
- StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
+ storeHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
} catch (UnknownHostException e) {
e.printStackTrace();
}
try {
- BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
+ bornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
} catch (UnknownHostException e) {
e.printStackTrace();
}
@@ -74,16 +74,16 @@ public class ConsumeQueueTest {
public MessageExtBrokerInner buildMessage() {
MessageExtBrokerInner msg = new MessageExtBrokerInner();
- msg.setTopic(topic);
+ msg.setTopic(TOPIC);
msg.setTags("TAG1");
msg.setKeys("Hello");
- msg.setBody(msgBody);
+ msg.setBody(MSG_BODY);
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(queueId);
+ msg.setQueueId(QUEUE_ID);
msg.setSysFlag(0);
msg.setBornTimestamp(System.currentTimeMillis());
- msg.setStoreHost(StoreHost);
- msg.setBornHost(BornHost);
+ msg.setStoreHost(storeHost);
+ msg.setBornHost(bornHost);
for (int i = 0; i < 1; i++) {
msg.putUserProperty(String.valueOf(i), "imagoodperson" + i);
}
@@ -94,13 +94,13 @@ public class ConsumeQueueTest {
public MessageExtBrokerInner buildIPv6HostMessage() {
MessageExtBrokerInner msg = new MessageExtBrokerInner();
- msg.setTopic(topic);
+ msg.setTopic(TOPIC);
msg.setTags("TAG1");
msg.setKeys("Hello");
- msg.setBody(msgBody);
+ msg.setBody(MSG_BODY);
msg.setMsgId("24084004018081003FAA1DDE2B3F898A00002A9F0000000000000CA0");
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(queueId);
+ msg.setQueueId(QUEUE_ID);
msg.setSysFlag(0);
msg.setBornHostV6Flag();
msg.setStoreHostAddressV6Flag();
@@ -124,15 +124,15 @@ public class ConsumeQueueTest {
messageStoreConfig.setMessageIndexEnable(false);
messageStoreConfig.setEnableConsumeQueueExt(enableCqExt);
messageStoreConfig.setHaListenPort(0);
- messageStoreConfig.setStorePathRootDir(storePath);
- messageStoreConfig.setStorePathCommitLog(storePath + File.separator + "commitlog");
+ messageStoreConfig.setStorePathRootDir(STORE_PATH);
+ messageStoreConfig.setStorePathCommitLog(STORE_PATH + File.separator + "commitlog");
return messageStoreConfig;
}
protected DefaultMessageStore gen() throws Exception {
MessageStoreConfig messageStoreConfig = buildStoreConfig(
- commitLogFileSize, cqFileSize, true, cqExtFileSize
+ COMMIT_LOG_FILE_SIZE, CQ_FILE_SIZE, true, CQ_EXT_FILE_SIZE
);
BrokerConfig brokerConfig = new BrokerConfig();
@@ -157,7 +157,7 @@ public class ConsumeQueueTest {
protected DefaultMessageStore genForMultiQueue() throws Exception {
MessageStoreConfig messageStoreConfig = buildStoreConfig(
- commitLogFileSize, cqFileSize, true, cqExtFileSize
+ COMMIT_LOG_FILE_SIZE, CQ_FILE_SIZE, true, CQ_EXT_FILE_SIZE
);
messageStoreConfig.setEnableLmq(true);
@@ -203,16 +203,16 @@ public class ConsumeQueueTest {
private MessageExtBrokerInner buildMessageMultiQueue() {
MessageExtBrokerInner msg = new MessageExtBrokerInner();
- msg.setTopic(topic);
+ msg.setTopic(TOPIC);
msg.setTags("TAG1");
msg.setKeys("Hello");
- msg.setBody(msgBody);
+ msg.setBody(MSG_BODY);
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(queueId);
+ msg.setQueueId(QUEUE_ID);
msg.setSysFlag(0);
msg.setBornTimestamp(System.currentTimeMillis());
- msg.setStoreHost(StoreHost);
- msg.setBornHost(BornHost);
+ msg.setStoreHost(storeHost);
+ msg.setBornHost(bornHost);
for (int i = 0; i < 1; i++) {
msg.putUserProperty(MessageConst.PROPERTY_INNER_MULTI_DISPATCH, "%LMQ%123,%LMQ%456");
msg.putUserProperty(String.valueOf(i), "imagoodperson" + i);
@@ -252,7 +252,7 @@ public class ConsumeQueueTest {
}
Thread.sleep(5);
- ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(topic).get(queueId);
+ ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(TOPIC).get(QUEUE_ID);
Method method = cq.getClass().getDeclaredMethod("putMessagePositionInfo", long.class, int.class, long.class, long.class);
assertThat(method).isNotNull();
@@ -276,7 +276,7 @@ public class ConsumeQueueTest {
messageStore.shutdown();
messageStore.destroy();
}
- deleteDirectory(storePath);
+ deleteDirectory(STORE_PATH);
}
}
@@ -294,7 +294,7 @@ public class ConsumeQueueTest {
}
Thread.sleep(5);
- ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(topic).get(queueId);
+ ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(TOPIC).get(QUEUE_ID);
Method method = ((ConsumeQueue) cq).getClass().getDeclaredMethod("putMessagePositionInfoWrapper", DispatchRequest.class);
assertThat(method).isNotNull();
@@ -323,7 +323,7 @@ public class ConsumeQueueTest {
messageStore.shutdown();
messageStore.destroy();
}
- deleteDirectory(storePath);
+ deleteDirectory(STORE_PATH);
}
}
@@ -342,7 +342,7 @@ public class ConsumeQueueTest {
}
Thread.sleep(5);
- ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(topic).get(queueId);
+ ConsumeQueueInterface cq = messageStore.getConsumeQueueTable().get(TOPIC).get(QUEUE_ID);
ConsumeQueueInterface lmqCq1 = messageStore.getConsumeQueueTable().get("%LMQ%123").get(0);
@@ -359,7 +359,7 @@ public class ConsumeQueueTest {
messageStore.shutdown();
messageStore.destroy();
}
- deleteDirectory(storePath);
+ deleteDirectory(STORE_PATH);
}
}
@@ -388,11 +388,11 @@ public class ConsumeQueueTest {
putMsg(master);
final DefaultMessageStore master1 = master;
ConsumeQueueInterface cq = await().atMost(3, SECONDS).until(() -> {
- ConcurrentMap<Integer, ConsumeQueueInterface> map = master1.getConsumeQueueTable().get(topic);
+ ConcurrentMap<Integer, ConsumeQueueInterface> map = master1.getConsumeQueueTable().get(TOPIC);
if (map == null) {
return null;
}
- ConsumeQueueInterface anInterface = map.get(queueId);
+ ConsumeQueueInterface anInterface = map.get(QUEUE_ID);
return anInterface;
}, item -> null != item);
@@ -431,7 +431,7 @@ public class ConsumeQueueTest {
} finally {
master.shutdown();
master.destroy();
- UtilAll.deleteFile(new File(storePath));
+ UtilAll.deleteFile(new File(STORE_PATH));
}
}
@@ -457,9 +457,9 @@ public class ConsumeQueueTest {
storeConfig.getMappedFileSizeConsumeQueue(), messageStore);
int max = 10000;
- int message_size = 100;
+ int messageSize = 100;
for (int i = 0; i < max; ++i) {
- DispatchRequest dispatchRequest = new DispatchRequest(topic, queueId, message_size * i, message_size, 0, 0, i, null, null, 0, 0, null);
+ DispatchRequest dispatchRequest = new DispatchRequest(topic, queueId, messageSize * i, messageSize, 0, 0, i, null, null, 0, 0, null);
consumeQueue.putMessagePositionInfoWrapper(dispatchRequest);
}
@@ -472,11 +472,11 @@ public class ConsumeQueueTest {
Assert.assertEquals(20, consumeQueue.getMinOffsetInQueue());
consumeQueue.setMinLogicOffset((max - 1) * ConsumeQueue.CQ_STORE_UNIT_SIZE);
- consumeQueue.correctMinOffset(max * message_size);
+ consumeQueue.correctMinOffset(max * messageSize);
Assert.assertEquals(max * ConsumeQueue.CQ_STORE_UNIT_SIZE, consumeQueue.getMinLogicOffset());
consumeQueue.setMinLogicOffset(max * ConsumeQueue.CQ_STORE_UNIT_SIZE);
- consumeQueue.correctMinOffset(max * message_size);
+ consumeQueue.correctMinOffset(max * messageSize);
Assert.assertEquals(max * ConsumeQueue.CQ_STORE_UNIT_SIZE, consumeQueue.getMinLogicOffset());
consumeQueue.destroy();
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
index 1f8d2e5ba..be4b8623d 100644
--- a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
@@ -315,7 +315,7 @@ public class MappedFileQueueTest {
}
assertThat(mappedFile != null).isTrue();
retryTime = 0;
- int pos = ((i * fixedMsg.getBytes().length) % mappedFileSize);
+ int pos = (i * fixedMsg.getBytes().length) % mappedFileSize;
while ((pos + fixedMsg.getBytes().length) > mappedFile.getReadPosition() && retryTime < 10000) {
retryTime++;
if ((pos + fixedMsg.getBytes().length) > mappedFile.getReadPosition()) {
@@ -373,7 +373,7 @@ public class MappedFileQueueTest {
}
} catch (Exception e) {
hasException.set(true);
- }finally {
+ } finally {
downLatch.countDown();
}
});
diff --git a/store/src/test/java/org/apache/rocketmq/store/MultiDispatchTest.java b/store/src/test/java/org/apache/rocketmq/store/MultiDispatchTest.java
index 92eae4be1..daa17eef8 100644
--- a/store/src/test/java/org/apache/rocketmq/store/MultiDispatchTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/MultiDispatchTest.java
@@ -78,7 +78,7 @@ public class MultiDispatchTest {
@Test
public void wrapMultiDispatch() {
MessageExtBrokerInner messageExtBrokerInner = buildMessageMultiQueue();
- messageStore.assignOffset( messageExtBrokerInner, (short) 1);
+ messageStore.assignOffset(messageExtBrokerInner, (short) 1);
assertEquals(messageExtBrokerInner.getProperty(MessageConst.PROPERTY_INNER_MULTI_QUEUE_OFFSET), "0,0");
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java b/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java
index 8fee578b5..afecbb243 100644
--- a/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java
@@ -101,8 +101,6 @@ public class StoreStatsServiceTest {
Method method = StoreStatsService.class.getDeclaredMethod("resetPutMessageTimeBuckets");
method.setAccessible(true);
method.invoke(storeStatsService);
- System.out.println(storeStatsService.findPutMessageEntireTimePX(0.99));
- System.out.println(storeStatsService.findPutMessageEntireTimePX(0.999));
}
}
\ No newline at end of file
diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreTestBase.java b/store/src/test/java/org/apache/rocketmq/store/StoreTestBase.java
index 3f2abf3ae..ae0841b8b 100644
--- a/store/src/test/java/org/apache/rocketmq/store/StoreTestBase.java
+++ b/store/src/test/java/org/apache/rocketmq/store/StoreTestBase.java
@@ -37,11 +37,11 @@ import java.util.concurrent.atomic.AtomicInteger;
public class StoreTestBase {
- private int QUEUE_TOTAL = 100;
- private AtomicInteger QueueId = new AtomicInteger(0);
- protected SocketAddress BornHost = new InetSocketAddress("127.0.0.1", 8123);
- protected SocketAddress StoreHost = BornHost;
- private byte[] MessageBody = new byte[1024];
+ private static final int QUEUE_TOTAL = 100;
+ private AtomicInteger queueId = new AtomicInteger(0);
+ protected SocketAddress bornHost = new InetSocketAddress("127.0.0.1", 8123);
+ protected SocketAddress storeHost = bornHost;
+ private byte[] messageBody = new byte[1024];
protected Set<String> baseDirs = new HashSet<>();
@@ -56,12 +56,12 @@ public class StoreTestBase {
messageExtBatch.setTopic("StoreTest");
messageExtBatch.setTags("TAG1");
messageExtBatch.setKeys("Hello");
- messageExtBatch.setQueueId(Math.abs(QueueId.getAndIncrement()) % QUEUE_TOTAL);
+ messageExtBatch.setQueueId(Math.abs(queueId.getAndIncrement()) % QUEUE_TOTAL);
messageExtBatch.setSysFlag(0);
messageExtBatch.setBornTimestamp(System.currentTimeMillis());
- messageExtBatch.setBornHost(BornHost);
- messageExtBatch.setStoreHost(StoreHost);
+ messageExtBatch.setBornHost(bornHost);
+ messageExtBatch.setStoreHost(storeHost);
List<Message> messageList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
@@ -78,13 +78,13 @@ public class StoreTestBase {
msg.setTopic("StoreTest");
msg.setTags("TAG1");
msg.setKeys("Hello");
- msg.setBody(MessageBody);
+ msg.setBody(messageBody);
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(Math.abs(QueueId.getAndIncrement()) % QUEUE_TOTAL);
+ msg.setQueueId(Math.abs(queueId.getAndIncrement()) % QUEUE_TOTAL);
msg.setSysFlag(0);
msg.setBornTimestamp(System.currentTimeMillis());
- msg.setStoreHost(StoreHost);
- msg.setBornHost(BornHost);
+ msg.setStoreHost(storeHost);
+ msg.setBornHost(bornHost);
return msg;
}
@@ -93,10 +93,10 @@ public class StoreTestBase {
messageExtBatch.setTopic("StoreTest");
messageExtBatch.setTags("TAG1");
messageExtBatch.setKeys("Hello");
- messageExtBatch.setBody(MessageBody);
+ messageExtBatch.setBody(messageBody);
messageExtBatch.setMsgId("24084004018081003FAA1DDE2B3F898A00002A9F0000000000000CA0");
messageExtBatch.setKeys(String.valueOf(System.currentTimeMillis()));
- messageExtBatch.setQueueId(Math.abs(QueueId.getAndIncrement()) % QUEUE_TOTAL);
+ messageExtBatch.setQueueId(Math.abs(queueId.getAndIncrement()) % QUEUE_TOTAL);
messageExtBatch.setSysFlag(0);
messageExtBatch.setBornHostV6Flag();
messageExtBatch.setStoreHostAddressV6Flag();
@@ -127,10 +127,10 @@ public class StoreTestBase {
msg.setTopic("StoreTest");
msg.setTags("TAG1");
msg.setKeys("Hello");
- msg.setBody(MessageBody);
+ msg.setBody(messageBody);
msg.setMsgId("24084004018081003FAA1DDE2B3F898A00002A9F0000000000000CA0");
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(Math.abs(QueueId.getAndIncrement()) % QUEUE_TOTAL);
+ msg.setQueueId(Math.abs(queueId.getAndIncrement()) % QUEUE_TOTAL);
msg.setSysFlag(0);
msg.setBornHostV6Flag();
msg.setStoreHostAddressV6Flag();
diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreTestUtil.java b/store/src/test/java/org/apache/rocketmq/store/StoreTestUtil.java
index 12ca49fcd..0196c6d6d 100644
--- a/store/src/test/java/org/apache/rocketmq/store/StoreTestUtil.java
+++ b/store/src/test/java/org/apache/rocketmq/store/StoreTestUtil.java
@@ -57,10 +57,10 @@ public class StoreTestUtil {
field.setAccessible(true);
DefaultMessageStore.FlushConsumeQueueService flushService = (DefaultMessageStore.FlushConsumeQueueService) field.get(store);
- final int RETRY_TIMES_OVER = 3;
+ final int retryTimesOver = 3;
Method method = DefaultMessageStore.FlushConsumeQueueService.class.getDeclaredMethod("doFlush", int.class);
method.setAccessible(true);
- method.invoke(flushService, RETRY_TIMES_OVER);
+ method.invoke(flushService, retryTimesOver);
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/ha/HAClientTest.java b/store/src/test/java/org/apache/rocketmq/store/ha/HAClientTest.java
index 450aac17a..33b3c541d 100644
--- a/store/src/test/java/org/apache/rocketmq/store/ha/HAClientTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/ha/HAClientTest.java
@@ -19,8 +19,6 @@ package org.apache.rocketmq.store.ha;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.store.DefaultMessageStore;
-import org.apache.rocketmq.store.ha.DefaultHAClient;
-import org.apache.rocketmq.store.ha.HAClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
diff --git a/store/src/test/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHATest.java b/store/src/test/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHATest.java
index 99b02e4e6..d74f1f3f2 100644
--- a/store/src/test/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHATest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHATest.java
@@ -57,10 +57,10 @@ public class AutoSwitchHATest {
private final String storeMessage = "Once, there was a chance for me!";
private final int defaultMappedFileSize = 1024 * 1024;
private int queueTotal = 100;
- private AtomicInteger QueueId = new AtomicInteger(0);
- private SocketAddress BornHost;
- private SocketAddress StoreHost;
- private byte[] MessageBody;
+ private AtomicInteger queueId = new AtomicInteger(0);
+ private SocketAddress bornHost;
+ private SocketAddress storeHost;
+ private byte[] messageBody;
private DefaultMessageStore messageStore1;
private DefaultMessageStore messageStore2;
@@ -78,9 +78,9 @@ public class AutoSwitchHATest {
public void init(int mappedFileSize) throws Exception {
queueTotal = 1;
- MessageBody = storeMessage.getBytes();
- StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
- BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
+ messageBody = storeMessage.getBytes();
+ storeHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
+ bornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
storeConfig1 = new MessageStoreConfig();
storeConfig1.setBrokerRole(BrokerRole.SYNC_MASTER);
storeConfig1.setHaSendHeartbeatInterval(1000);
@@ -133,9 +133,9 @@ public class AutoSwitchHATest {
public void init(int mappedFileSize, boolean allAckInSyncStateSet) throws Exception {
queueTotal = 1;
- MessageBody = storeMessage.getBytes();
- StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
- BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
+ messageBody = storeMessage.getBytes();
+ storeHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
+ bornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
storeConfig1 = new MessageStoreConfig();
storeConfig1.setBrokerRole(BrokerRole.SYNC_MASTER);
storeConfig1.setStorePathRootDir(storePathRootDir + File.separator + "broker1");
@@ -274,8 +274,7 @@ public class AutoSwitchHATest {
init(defaultMappedFileSize, true);
AtomicReference<Set<String>> syncStateSet = new AtomicReference<>();
((AutoSwitchHAService) this.messageStore1.getHaService()).setSyncStateSet(new HashSet<>(Collections.singletonList("127.0.0.1:8000")));
- ((AutoSwitchHAService) this.messageStore1.getHaService()).registerSyncStateSetChangedListener((newSyncStateSet) -> {
- System.out.println("Get newSyncStateSet:" + newSyncStateSet);
+ ((AutoSwitchHAService) this.messageStore1.getHaService()).registerSyncStateSetChangedListener(newSyncStateSet -> {
syncStateSet.set(newSyncStateSet);
});
@@ -481,13 +480,13 @@ public class AutoSwitchHATest {
MessageExtBrokerInner msg = new MessageExtBrokerInner();
msg.setTopic("FooBar");
msg.setTags("TAG1");
- msg.setBody(MessageBody);
+ msg.setBody(messageBody);
msg.setKeys(String.valueOf(System.currentTimeMillis()));
- msg.setQueueId(Math.abs(QueueId.getAndIncrement()) % queueTotal);
+ msg.setQueueId(Math.abs(queueId.getAndIncrement()) % queueTotal);
msg.setSysFlag(0);
msg.setBornTimestamp(System.currentTimeMillis());
- msg.setStoreHost(StoreHost);
- msg.setBornHost(BornHost);
+ msg.setStoreHost(storeHost);
+ msg.setBornHost(bornHost);
msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
return msg;
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java
index 5ef8dce11..99493724f 100644
--- a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java
@@ -30,8 +30,8 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class IndexFileTest {
- private final int HASH_SLOT_NUM = 100;
- private final int INDEX_NUM = 400;
+ private static final int HASH_SLOT_NUM = 100;
+ private static final int INDEX_NUM = 400;
@Test
public void testPutKey() throws Exception {
diff --git a/store/src/test/java/org/apache/rocketmq/store/queue/BatchConsumeMessageTest.java b/store/src/test/java/org/apache/rocketmq/store/queue/BatchConsumeMessageTest.java
index f70485d1b..2485ec670 100644
--- a/store/src/test/java/org/apache/rocketmq/store/queue/BatchConsumeMessageTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/queue/BatchConsumeMessageTest.java
@@ -213,7 +213,7 @@ public class BatchConsumeMessageTest extends QueueTestBase {
Assert.assertEquals(80, messageStore.getOffsetInQueueByTime(topic, 0, timeMid));
// can set periodic interval for executing DefaultMessageStore.this.cleanFilesPeriodically() method, we can execute following code.
- // default periodic interval is 60s, This code snippet will take 60 seconds。
+ // default periodic interval is 60s, This code snippet will take 60 seconds.
/*final long a = timeMid;
await().atMost(Duration.ofMinutes(2)).until(()->{
long time = messageStore.getOffsetInQueueByTime(topic, 0, a);
diff --git a/store/src/test/java/org/apache/rocketmq/store/queue/QueueTestBase.java b/store/src/test/java/org/apache/rocketmq/store/queue/QueueTestBase.java
index 88e3c86ee..a1e1cc1f5 100644
--- a/store/src/test/java/org/apache/rocketmq/store/queue/QueueTestBase.java
+++ b/store/src/test/java/org/apache/rocketmq/store/queue/QueueTestBase.java
@@ -99,8 +99,8 @@ public class QueueTestBase extends StoreTestBase {
msg.setQueueId(0);
msg.setSysFlag(0);
msg.setBornTimestamp(System.currentTimeMillis());
- msg.setStoreHost(StoreHost);
- msg.setBornHost(StoreHost);
+ msg.setStoreHost(storeHost);
+ msg.setBornHost(storeHost);
MessageAccessor.putProperty(msg, MessageConst.PROPERTY_INNER_NUM, String.valueOf(batchNum));
msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
if (batchNum > 1) {
diff --git a/store/src/test/java/org/apache/rocketmq/store/stats/BrokerStatsManagerTest.java b/store/src/test/java/org/apache/rocketmq/store/stats/BrokerStatsManagerTest.java
index 6dcdfc2e9..8dc86dbee 100644
--- a/store/src/test/java/org/apache/rocketmq/store/stats/BrokerStatsManagerTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/stats/BrokerStatsManagerTest.java
@@ -40,9 +40,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BrokerStatsManagerTest {
private BrokerStatsManager brokerStatsManager;
- private String TOPIC = "TOPIC_TEST";
- private Integer QUEUE_ID = 0;
- private String GROUP_NAME = "GROUP_TEST";
+ private static final String TOPIC = "TOPIC_TEST";
+ private static final Integer QUEUE_ID = 0;
+ private static final String GROUP_NAME = "GROUP_TEST";
@Before
public void init() {
@@ -163,7 +163,7 @@ public class BrokerStatsManagerTest {
}
@Test
- public void testOnGroupDeleted(){
+ public void testOnGroupDeleted() {
brokerStatsManager.incGroupGetNums(GROUP_NAME, TOPIC, 1);
brokerStatsManager.incGroupGetSize(GROUP_NAME, TOPIC, 100);
brokerStatsManager.incQueueGetNums(GROUP_NAME, TOPIC, QUEUE_ID, 1);
diff --git a/store/src/test/java/org/apache/rocketmq/store/timer/TimerLogTest.java b/store/src/test/java/org/apache/rocketmq/store/timer/TimerLogTest.java
index 657da3ac8..112c3ad46 100644
--- a/store/src/test/java/org/apache/rocketmq/store/timer/TimerLogTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/timer/TimerLogTest.java
@@ -26,7 +26,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
public class TimerLogTest {
diff --git a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
index 926e7de00..9a2fa7d5c 100644
--- a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
@@ -49,7 +49,6 @@ import org.apache.rocketmq.store.PutMessageResult;
import org.apache.rocketmq.store.PutMessageStatus;
import org.apache.rocketmq.store.config.FlushDiskType;
import org.apache.rocketmq.store.config.MessageStoreConfig;
-import org.apache.rocketmq.store.hook.PutMessageHook;
import org.apache.rocketmq.store.stats.BrokerStatsManager;
import org.junit.After;
import org.junit.Assert;
@@ -231,10 +230,10 @@ public class TimerMessageStoreTest {
MessageExtBrokerInner inner = buildMessage(delayMs, topic, false);
PutMessageResult putMessageResult = transformTimerMessage(timerMessageStore,inner);
- if (putMessageResult==null || !putMessageResult.getPutMessageStatus().equals(PutMessageStatus.WHEEL_TIMER_FLOW_CONTROL)) {
+ if (putMessageResult == null || !putMessageResult.getPutMessageStatus().equals(PutMessageStatus.WHEEL_TIMER_FLOW_CONTROL)) {
putMessageResult = messageStore.putMessage(inner);
}
- else{
+ else {
putMessageResult = new PutMessageResult(PutMessageStatus.WHEEL_TIMER_FLOW_CONTROL,null);
}
@@ -378,7 +377,7 @@ public class TimerMessageStoreTest {
MessageExtBrokerInner inner = buildMessage((i % 2 == 0) ? 5000 : delayMs, topic, i % 2 == 0);
transformTimerMessage(first,inner);
PutMessageResult putMessageResult = messageStore.putMessage(inner);
- long CQOffset = first.getCommitQueueOffset();
+ long cqOffset = first.getCommitQueueOffset();
assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus());
}
@@ -387,7 +386,7 @@ public class TimerMessageStoreTest {
@Override
public Boolean call() {
long curr = System.currentTimeMillis() / precisionMs * precisionMs;
- long CQOffset = first.getCommitQueueOffset();
+ long cqOffset = first.getCommitQueueOffset();
return first.getCommitQueueOffset() == msgNum
&& (first.getCurrReadTimeMs() == curr || first.getCurrReadTimeMs() == curr + precisionMs);
}
diff --git a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMetricsTest.java b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMetricsTest.java
index 4a0a40da0..b7392cc45 100644
--- a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMetricsTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMetricsTest.java
@@ -51,26 +51,31 @@ public class TimerMetricsTest {
}
@Test
- public void testTimingDistribution(){
+ public void testTimingDistribution() {
String baseDir = StoreTestUtils.createBaseDir();
TimerMetrics first = new TimerMetrics(baseDir);
- List<Integer> timerDist = new ArrayList<Integer>(){{
- add(5);add(60);add(300); // 5s, 1min, 5min
- add(900);add(3600);add(14400); // 15min, 1h, 4h
- add(28800);add(86400); // 8h, 24h
- }};
- for(int period:timerDist){
- first.updateDistPair(period,period);
+ List<Integer> timerDist = new ArrayList<Integer>() {{
+ add(5);
+ add(60);
+ add(300); // 5s, 1min, 5min
+ add(900);
+ add(3600);
+ add(14400); // 15min, 1h, 4h
+ add(28800);
+ add(86400); // 8h, 24h
+ }};
+ for (int period : timerDist) {
+ first.updateDistPair(period, period);
}
int temp = 0;
- for(int j=0;j<50;j++){
- for(int period:timerDist){
- Assert.assertEquals(first.getDistPair(period).getCount().get(),period+temp);
- first.updateDistPair(period,j);
+ for (int j = 0; j < 50; j++) {
+ for (int period : timerDist) {
+ Assert.assertEquals(first.getDistPair(period).getCount().get(),period + temp);
+ first.updateDistPair(period, j);
}
- temp+=j;
+ temp += j;
}
StoreTestUtils.deleteFile(baseDir);