diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java index 90ef2104ed2ebfd7789e62ea51654eb7ddc46012..797e0d882a2600d436a38a2f6c5ba9c40e3fc31b 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java @@ -37,16 +37,14 @@ public class BrokerControllerTest { */ @Test public void testBrokerRestart() throws Exception { - for (int i = 0; i < 2; i++) { - BrokerController brokerController = new BrokerController( - new BrokerConfig(), - new NettyServerConfig(), - new NettyClientConfig(), - new MessageStoreConfig()); - assertThat(brokerController.initialize()); - brokerController.start(); - brokerController.shutdown(); - } + BrokerController brokerController = new BrokerController( + new BrokerConfig(), + new NettyServerConfig(), + new NettyClientConfig(), + new MessageStoreConfig()); + assertThat(brokerController.initialize()); + brokerController.start(); + brokerController.shutdown(); } @After diff --git a/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java b/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java index d3c973a1bc1f7d9c8efd976eb0c647c5742552c0..7978942e5bbdd5f9cbd32176153d0819da221518 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java @@ -33,6 +33,8 @@ import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.apache.rocketmq.store.stats.BrokerStatsManager; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.io.File; @@ -63,6 +65,14 @@ public class MessageStoreWithFilterTest { private static SocketAddress StoreHost; + private DefaultMessageStore master; + + private ConsumerFilterManager filterManager; + + private int topicCount = 3; + + private int msgPerTopic = 30; + static { try { StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123); @@ -76,6 +86,24 @@ public class MessageStoreWithFilterTest { } } + @Before + public void init() { + filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); + try { + master = gen(filterManager); + } catch (Exception e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } + } + + @After + public void destroy() { + master.shutdown(); + master.destroy(); + UtilAll.deleteFile(new File(storePath)); + } + public MessageExtBrokerInner buildMessage() { MessageExtBrokerInner msg = new MessageExtBrokerInner(); msg.setTopic(topic); @@ -202,177 +230,143 @@ public class MessageStoreWithFilterTest { @Test public void testGetMessage_withFilterBitMapAndConsumerChanged() { - int topicCount = 10, msgPerTopic = 10; - ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); - - DefaultMessageStore master = null; + List msgs = null; try { - master = gen(filterManager); + msgs = putMsg(master, topicCount, msgPerTopic); } catch (Exception e) { e.printStackTrace(); assertThat(true).isFalse(); } + // sleep to wait for consume queue has been constructed. try { - List msgs = null; - try { - msgs = putMsg(master, topicCount, msgPerTopic); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } - - // sleep to wait for consume queue has been constructed. - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } - // reset consumer; - String topic = "topic" + 0; - String resetGroup = "CID_" + 2; - String normalGroup = "CID_" + 3; + // reset consumer; + String topic = "topic" + 0; + String resetGroup = "CID_" + 2; + String normalGroup = "CID_" + 3; - { - // reset CID_2@topic0 to get all messages. - SubscriptionData resetSubData = new SubscriptionData(); - resetSubData.setExpressionType(ExpressionType.SQL92); - resetSubData.setTopic(topic); - resetSubData.setClassFilterMode(false); - resetSubData.setSubString("a is not null OR a is null"); + { + // reset CID_2@topic0 to get all messages. + SubscriptionData resetSubData = new SubscriptionData(); + resetSubData.setExpressionType(ExpressionType.SQL92); + resetSubData.setTopic(topic); + resetSubData.setClassFilterMode(false); + resetSubData.setSubString("a is not null OR a is null"); - ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, - resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), - System.currentTimeMillis()); + ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, + resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), + System.currentTimeMillis()); - GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, - new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager)); + GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, + new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager)); - try { - assertThat(resetGetResult).isNotNull(); + try { + assertThat(resetGetResult).isNotNull(); - List filteredMsgs = filtered(msgs, resetFilterData); + List filteredMsgs = filtered(msgs, resetFilterData); - assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - } finally { - resetGetResult.release(); - } + assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + } finally { + resetGetResult.release(); } + } - { - ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup); - assertThat(normalFilterData).isNotNull(); - assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis()); + { + ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup); + assertThat(normalFilterData).isNotNull(); + assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis()); - SubscriptionData normalSubData = new SubscriptionData(); - normalSubData.setExpressionType(normalFilterData.getExpressionType()); - normalSubData.setTopic(topic); - normalSubData.setClassFilterMode(false); - normalSubData.setSubString(normalFilterData.getExpression()); + SubscriptionData normalSubData = new SubscriptionData(); + normalSubData.setExpressionType(normalFilterData.getExpressionType()); + normalSubData.setTopic(topic); + normalSubData.setClassFilterMode(false); + normalSubData.setSubString(normalFilterData.getExpression()); - List filteredMsgs = filtered(msgs, normalFilterData); + List filteredMsgs = filtered(msgs, normalFilterData); - GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, - new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager)); + GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, + new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager)); - try { - assertThat(normalGetResult).isNotNull(); - assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - } finally { - normalGetResult.release(); - } + try { + assertThat(normalGetResult).isNotNull(); + assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + } finally { + normalGetResult.release(); } - } finally { - master.shutdown(); - master.destroy(); - UtilAll.deleteFile(new File(storePath)); } } @Test public void testGetMessage_withFilterBitMap() { - int topicCount = 10, msgPerTopic = 500; - ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); - - DefaultMessageStore master = null; + List msgs = null; try { - master = gen(filterManager); + msgs = putMsg(master, topicCount, msgPerTopic); + // sleep to wait for consume queue has been constructed. + Thread.sleep(200); } catch (Exception e) { e.printStackTrace(); assertThat(true).isFalse(); } - try { - List msgs = null; - try { - msgs = putMsg(master, topicCount, msgPerTopic); - // sleep to wait for consume queue has been constructed. - Thread.sleep(1000); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + for (int i = 0; i < topicCount; i++) { + String realTopic = topic + i; - for (int i = 0; i < topicCount; i++) { - String realTopic = topic + i; - - for (int j = 0; j < msgPerTopic; j++) { - String group = "CID_" + j; - - ConsumerFilterData filterData = filterManager.get(realTopic, group); - assertThat(filterData).isNotNull(); - - List filteredMsgs = filtered(msgs, filterData); - - SubscriptionData subscriptionData = new SubscriptionData(); - subscriptionData.setExpressionType(filterData.getExpressionType()); - subscriptionData.setTopic(filterData.getTopic()); - subscriptionData.setClassFilterMode(false); - subscriptionData.setSubString(filterData.getExpression()); - - GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, - new ExpressionMessageFilter(subscriptionData, filterData, filterManager)); - String assertMsg = group + "-" + realTopic; - try { - assertThat(getMessageResult).isNotNull(); - assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus()); - assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty(); - assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - - for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) { - MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false); - assertThat(messageExt).isNotNull(); - - Object evlRet = null; - try { - evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties())); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + for (int j = 0; j < msgPerTopic; j++) { + String group = "CID_" + j; - assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE); + ConsumerFilterData filterData = filterManager.get(realTopic, group); + assertThat(filterData).isNotNull(); - // check - boolean find = false; - for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) { - if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) { - find = true; - } + List filteredMsgs = filtered(msgs, filterData); + + SubscriptionData subscriptionData = new SubscriptionData(); + subscriptionData.setExpressionType(filterData.getExpressionType()); + subscriptionData.setTopic(filterData.getTopic()); + subscriptionData.setClassFilterMode(false); + subscriptionData.setSubString(filterData.getExpression()); + + GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, + new ExpressionMessageFilter(subscriptionData, filterData, filterManager)); + String assertMsg = group + "-" + realTopic; + try { + assertThat(getMessageResult).isNotNull(); + assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus()); + assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty(); + assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + + for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) { + MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false); + assertThat(messageExt).isNotNull(); + + Object evlRet = null; + try { + evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties())); + } catch (Exception e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } + + assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE); + + // check + boolean find = false; + for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) { + if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) { + find = true; } - assertThat(find).isTrue(); } - } finally { - getMessageResult.release(); + assertThat(find).isTrue(); } + } finally { + getMessageResult.release(); } } - } finally { - master.shutdown(); - master.destroy(); - UtilAll.deleteFile(new File(storePath)); } } } diff --git a/broker/src/test/resources/logback-test.xml b/broker/src/test/resources/logback-test.xml index 908373e86b7817fe17e9dcb13720f6b7efe0b727..1978b73ae07ef26b2a0d8f6d46cd0e7ad13b8404 100644 --- a/broker/src/test/resources/logback-test.xml +++ b/broker/src/test/resources/logback-test.xml @@ -19,7 +19,6 @@ - true %d{yyy-MM-dd HH\:mm\:ss,GMT+8} %p %t - %m%n UTF-8 diff --git a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java index 356cda3178d203eee9e953f9e47235bf9cd60257..e84a069d0060ddb61cd8fc05550e6afd6d50b552 100644 --- a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java +++ b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java @@ -16,14 +16,14 @@ */ package org.apache.rocketmq.client.log; -import java.lang.reflect.Method; -import java.net.URL; - import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Method; +import java.net.URL; + public class ClientLogger { public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; public static final String CLIENT_LOG_MAXINDEX = "rocketmq.client.logFileMaxIndex"; @@ -31,25 +31,21 @@ public class ClientLogger { private static Logger log; - private static Class logClass = null; - private static Logger createLogger(final String loggerName) { - String logConfigFilePath = - System.getProperty("rocketmq.client.log.configFile", - System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); + String logConfigFilePath = System.getProperty("rocketmq.client.log.configFile", System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); Boolean isloadconfig = - Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); + Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); final String log4JResourceFile = - System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); + System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); final String logbackResourceFile = - System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); + System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); final String log4J2ResourceFile = - System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml"); + System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml"); - String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); + String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs"); System.setProperty("client.logRoot", clientLogRoot); String clientLogLevel = System.getProperty(CLIENT_LOG_LEVEL, "INFO"); System.setProperty("client.logLevel", clientLogLevel); @@ -85,11 +81,11 @@ public class ClientLogger { if (null == logConfigFilePath) { URL url = ClientLogger.class.getClassLoader().getResource(logbackResourceFile); Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); doConfigure.invoke(joranConfiguratoroObj, url); } else { Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath); } @@ -102,7 +98,7 @@ public class ClientLogger { initialize.invoke(joranConfigurator, "log4j2", logConfigFilePath); } } - logClass = classType; + //logClass = classType; } catch (Exception e) { System.err.println(e); } diff --git a/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java index 8d091e5e7df3671510db28c781194843a014237a..3a581e131002d5b9f803712c7c1ff5d636d7b417 100644 --- a/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java @@ -92,9 +92,9 @@ public class AllocateMessageQueueConsitentHashTest { @Test public void testRun100RandomCase() { - for (int i = 0; i < 100; i++) { - int consumerSize = new Random().nextInt(200) + 1;//1-200 - int queueSize = new Random().nextInt(100) + 1;//1-100 + for (int i = 0; i < 10; i++) { + int consumerSize = new Random().nextInt(20) + 1;//1-20 + int queueSize = new Random().nextInt(20) + 1;//1-20 testAllocate(queueSize, consumerSize); try { Thread.sleep(1); diff --git a/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java b/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java deleted file mode 100644 index d7b619f51bf2c79a7474f871599c84eb777c3958..0000000000000000000000000000000000000000 --- a/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.client.log; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.*; -import java.lang.reflect.Field; -import java.util.Date; - -public class ClientLogTest { - - public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; - public static final String LOG_DIR; - - static { - LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); - } - - // FIXME: Workarond for concret implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1 - @Test - public void testLog4j2() throws IOException, NoSuchFieldException, IllegalAccessException { - ClientLogger.getLog(); - long seek = 0; - boolean result = false; - File file = new File(LOG_DIR + File.separator + "rocketmq_client.log"); - if (file.exists()) { - seek = file.length(); - } - Field logClassField = ClientLogger.class.getDeclaredField("logClass"); - logClassField.setAccessible(true); - Class logClass = (Class) logClassField.get(ClientLogger.class); - Assert.assertEquals("org.apache.logging.slf4j.Log4jLoggerFactory", logClass.getName()); - for (int i = 0; i < 10; i++) { - ClientLogger.getLog().info("testcase testLog4j2 " + new Date()); - } - - RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); - randomAccessFile.seek(seek); - String line = randomAccessFile.readLine(); - int idx = 1; - while (line != null) { - if (line.contains("testLog4j2")) { - result = true; - break; - } - line = randomAccessFile.readLine(); - idx++; - if (idx > 20) { - break; - } - } - randomAccessFile.close(); - Assert.assertTrue(result); - } -} diff --git a/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java b/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0559e0d80de50369e857b842956973bedccfffab --- /dev/null +++ b/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.client.log; + +import org.apache.rocketmq.common.UtilAll; +import org.junit.After; +import org.junit.Test; +import org.slf4j.Logger; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class ClientLoggerTest { + + public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; + public static final String LOG_DIR; + + static { + LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs"); + } + + + @After + public void cleanFiles() { + UtilAll.deleteFile(new File(LOG_DIR)); + } + + // FIXME: Workaround for concrete implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1 + @Test + public void testLog4j() throws Exception { + Logger logger = ClientLogger.getLog(); + + assertEquals("org.apache.logging.slf4j.Log4jLogger", logger.getClass().getName()); + } +} diff --git a/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java b/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java index 0ee81c98a2d973cdc84b6bfdec9c8cd1f8e619f7..7fb606ac13bd57fcbe06b4b4db9a2ff4cff658cc 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java @@ -47,7 +47,7 @@ public class ExpressionTest { private static String stringHasString = "TAGS is not null and TAGS='''''tag'''''"; @Test - public void testEvaluate_stringHasString() { + public void testEvaluate_stringHasString() throws Exception { Expression expr = genExp(stringHasString); EvaluationContext context = genContext( @@ -58,7 +58,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_now() { + public void testEvaluate_now() throws Exception { EvaluationContext context = genContext( KeyValue.c("a", System.currentTimeMillis()) ); @@ -72,8 +72,8 @@ public class ExpressionTest { eval(expression, context, Boolean.TRUE); } - @Test - public void testEvaluate_stringCompare() { + @Test(expected = RuntimeException.class) + public void testEvaluate_stringCompare() throws Exception { Expression expression = genExp("a between up and low"); EvaluationContext context = genContext( @@ -147,7 +147,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_exponent() { + public void testEvaluate_exponent() throws Exception { Expression expression = genExp("a > 3.1E10"); EvaluationContext context = genContext( @@ -158,7 +158,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_floatNumber() { + public void testEvaluate_floatNumber() throws Exception { Expression expression = genExp("a > 3.14"); EvaluationContext context = genContext( @@ -169,7 +169,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_twoVariable() { + public void testEvaluate_twoVariable() throws Exception { Expression expression = genExp("a > b"); EvaluationContext context = genContext( @@ -178,8 +178,12 @@ public class ExpressionTest { ); eval(expression, context, Boolean.FALSE); + } - context = genContext( + @Test + public void testEvaluate_twoVariableGt() throws Exception { + Expression expression = genExp("a > b"); + EvaluationContext context = genContext( KeyValue.c("b", String.valueOf(10)), KeyValue.c("a", String.valueOf(20)) ); @@ -188,7 +192,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_nullOr() { + public void testEvaluate_nullOr() throws Exception { Expression expression = genExp(nullOrExpression); EvaluationContext context = genContext( @@ -210,7 +214,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_boolean() { + public void testEvaluate_boolean() throws Exception { Expression expression = genExp(booleanExpression); EvaluationContext context = genContext( @@ -229,7 +233,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_equal() { + public void testEvaluate_equal() throws Exception { Expression expression = genExp(equalExpression); EvaluationContext context = genContext( @@ -245,7 +249,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_andTrue() { + public void testEvaluate_andTrue() throws Exception { Expression expression = genExp(andExpression); EvaluationContext context = genContext( @@ -278,7 +282,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_andFalse() { + public void testEvaluate_andFalse() throws Exception { Expression expression = genExp(andExpression); EvaluationContext context = genContext( @@ -302,7 +306,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_orTrue() { + public void testEvaluate_orTrue() throws Exception { Expression expression = genExp(orExpression); // first @@ -337,7 +341,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_orFalse() { + public void testEvaluate_orFalse() throws Exception { Expression expression = genExp(orExpression); // forth EvaluationContext context = genContext( @@ -350,7 +354,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_inTrue() { + public void testEvaluate_inTrue() throws Exception { Expression expression = genExp(inExpression); EvaluationContext context = genContext( @@ -370,7 +374,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_inFalse() { + public void testEvaluate_inFalse() throws Exception { Expression expression = genExp(inExpression); EvaluationContext context = genContext( @@ -380,7 +384,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notInTrue() { + public void testEvaluate_notInTrue() throws Exception { Expression expression = genExp(notInExpression); EvaluationContext context = genContext( @@ -390,7 +394,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notInFalse() { + public void testEvaluate_notInFalse() throws Exception { Expression expression = genExp(notInExpression); EvaluationContext context = genContext( @@ -410,7 +414,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_betweenTrue() { + public void testEvaluate_betweenTrue() throws Exception { Expression expression = genExp(betweenExpression); EvaluationContext context = genContext( @@ -430,7 +434,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_betweenFalse() { + public void testEvaluate_betweenFalse() throws Exception { Expression expression = genExp(betweenExpression); EvaluationContext context = genContext( @@ -445,7 +449,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notBetweenTrue() { + public void testEvaluate_notBetweenTrue() throws Exception { Expression expression = genExp(notBetweenExpression); EvaluationContext context = genContext( @@ -460,7 +464,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notBetweenFalse() { + public void testEvaluate_notBetweenFalse() throws Exception { Expression expression = genExp(notBetweenExpression); EvaluationContext context = genContext( @@ -480,7 +484,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNullTrue() { + public void testEvaluate_isNullTrue() throws Exception { Expression expression = genExp(isNullExpression); EvaluationContext context = genContext( @@ -490,7 +494,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNullFalse() { + public void testEvaluate_isNullFalse() throws Exception { Expression expression = genExp(isNullExpression); EvaluationContext context = genContext( @@ -500,7 +504,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNotNullTrue() { + public void testEvaluate_isNotNullTrue() throws Exception { Expression expression = genExp(isNotNullExpression); EvaluationContext context = genContext( @@ -510,7 +514,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNotNullFalse() { + public void testEvaluate_isNotNullFalse() throws Exception { Expression expression = genExp(isNotNullExpression); EvaluationContext context = genContext( @@ -519,14 +523,8 @@ public class ExpressionTest { eval(expression, context, Boolean.FALSE); } - protected void eval(Expression expression, EvaluationContext context, Boolean result) { - Object ret = null; - try { - ret = expression.evaluate(context); - } catch (Throwable e) { - e.printStackTrace(); - } - + protected void eval(Expression expression, EvaluationContext context, Boolean result) throws Exception { + Object ret = expression.evaluate(context); if (ret == null || !(ret instanceof Boolean)) { assertThat(result).isFalse(); } else { diff --git a/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java b/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java deleted file mode 100644 index 3db042291075a9c8671891b0d1a70c157c8a6e65..0000000000000000000000000000000000000000 --- a/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.namesrv; - -import org.apache.rocketmq.common.namesrv.NamesrvConfig; -import org.apache.rocketmq.remoting.netty.NettyServerConfig; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class NamesrvControllerTest { - private final static int RESTARTNUM = 2; - - /** - * Tests if the controller can be properly stopped and started. - * - * @throws Exception If fails. - */ - @Test - public void testRestart() throws Exception { - for (int i = 0; i < RESTARTNUM; i++) { - NamesrvController namesrvController = new NamesrvController( - new NamesrvConfig(), - new NettyServerConfig() - ); - boolean initResult = namesrvController.initialize(); - assertThat(initResult).isEqualTo(true); - namesrvController.start(); - namesrvController.shutdown(); - } - } -} \ No newline at end of file diff --git a/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java b/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java index 8efa536fb57d821123055f847b51b8c10e881fb6..b74d66b2b42bee5ebd93cf529f79131c99a2b787 100644 --- a/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java +++ b/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java @@ -34,7 +34,6 @@ public class KVConfigManagerTest extends NameServerInstanceTest { @Test public void testPutKVConfig() { - kvConfigManager.load(); kvConfigManager.putKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, "UnitTest", "test"); byte[] kvConfig = kvConfigManager.getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); assertThat(kvConfig).isNotNull(); diff --git a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java index 28d7478948db8bda4ebaf053093cad5e2125280a..6e37b705f7435003edae4eeac3654566f7a6cacc 100644 --- a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java @@ -43,15 +43,24 @@ public class DefaultMessageStoreTest { private SocketAddress BornHost; private SocketAddress StoreHost; private byte[] MessageBody; + private MessageStore messageStore; @Before public void init() throws Exception { StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123); BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0); + + messageStore = buildMessageStore(); + boolean load = messageStore.load(); + assertTrue(load); + messageStore.start(); } @After public void destory() { + messageStore.shutdown(); + messageStore.destroy(); + MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); File file = new File(messageStoreConfig.getStorePathRootDir()); UtilAll.deleteFile(file); @@ -63,7 +72,7 @@ public class DefaultMessageStoreTest { messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 1024 * 10); messageStoreConfig.setMaxHashSlotNum(10000); messageStoreConfig.setMaxIndexNum(100 * 100); - messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH); + messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH); return new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager("simpleTest"), new MyMessageArrivingListener(), new BrokerConfig()); } @@ -72,12 +81,16 @@ public class DefaultMessageStoreTest { long totalMsgs = 100; QUEUE_TOTAL = 1; MessageBody = StoreMessage.getBytes(); - MessageStore master = buildMessageStore(); - boolean load = master.load(); - assertTrue(load); + for (long i = 0; i < totalMsgs; i++) { + messageStore.putMessage(buildMessage()); + } - master.start(); - verifyThatMasterIsFunctional(totalMsgs, master); + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = messageStore.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); + } + verifyThatMasterIsFunctional(totalMsgs, messageStore); } public MessageExtBrokerInner buildMessage() { @@ -97,54 +110,46 @@ public class DefaultMessageStoreTest { @Test public void testGroupCommit() throws Exception { - long totalMsgs = 100; + long totalMsgs = 10; QUEUE_TOTAL = 1; MessageBody = StoreMessage.getBytes(); - MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); - messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8); - messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH); - MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig()); - boolean load = master.load(); - assertTrue(load); + for (long i = 0; i < totalMsgs; i++) { + messageStore.putMessage(buildMessage()); + } - master.start(); - verifyThatMasterIsFunctional(totalMsgs, master); + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = messageStore.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); + } + verifyThatMasterIsFunctional(totalMsgs, messageStore); } private void verifyThatMasterIsFunctional(long totalMsgs, MessageStore master) { - try { - for (long i = 0; i < totalMsgs; i++) { - master.putMessage(buildMessage()); - } - - for (long i = 0; i < totalMsgs; i++) { - GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); - assertThat(result).isNotNull(); - result.release(); - - } - } finally { - master.shutdown(); - master.destroy(); + for (long i = 0; i < totalMsgs; i++) { + master.putMessage(buildMessage()); + } + + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); + } } @Test public void testPullSize() throws Exception { - MessageStore messageStore = buildMessageStore(); - boolean load = messageStore.load(); - assertTrue(load); - messageStore.start(); String topic = "pullSizeTopic"; for (int i = 0; i < 32; i++) { MessageExtBrokerInner messageExtBrokerInner = buildMessage(); messageExtBrokerInner.setTopic(topic); messageExtBrokerInner.setQueueId(0); - PutMessageResult putMessageResult = messageStore.putMessage(messageExtBrokerInner); + messageStore.putMessage(messageExtBrokerInner); } //wait for consume queue build - Thread.sleep(100); + Thread.sleep(10); String group = "simple"; GetMessageResult getMessageResult32 = messageStore.getMessage(group, topic, 0, 0, 32, null); assertThat(getMessageResult32.getMessageBufferList().size()).isEqualTo(32); @@ -154,8 +159,6 @@ public class DefaultMessageStoreTest { GetMessageResult getMessageResult45 = messageStore.getMessage(group, topic, 0, 0, 10, null); assertThat(getMessageResult45.getMessageBufferList().size()).isEqualTo(10); - - messageStore.shutdown(); } private class MyMessageArrivingListener implements MessageArrivingListener {