You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by yu...@apache.org on 2017/01/22 12:46:26 UTC
incubator-rocketmq git commit: [ROCKETMQ-53] Polish unit tests for
MixAll
Repository: incubator-rocketmq
Updated Branches:
refs/heads/ROCKETMQ-53 6ce4e5cef -> 79977a900
[ROCKETMQ-53] Polish unit tests for MixAll
Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/79977a90
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/79977a90
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/79977a90
Branch: refs/heads/ROCKETMQ-53
Commit: 79977a90033ee2addbc4d6d087ff75a28acc323f
Parents: 6ce4e5c
Author: yukon <yu...@apache.org>
Authored: Sun Jan 22 20:43:36 2017 +0800
Committer: yukon <yu...@apache.org>
Committed: Sun Jan 22 20:43:36 2017 +0800
----------------------------------------------------------------------
.../org/apache/rocketmq/common/MixAllTest.java | 43 +++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/79977a90/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
index b0f3648..3a40dd5 100644
--- a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
@@ -17,14 +17,17 @@
package org.apache.rocketmq.common;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.net.InetAddress;
import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class MixAllTest {
-
@Test
public void testGetLocalInetAddress() throws Exception {
List<String> localInetAddress = MixAll.getLocalInetAddress();
@@ -32,4 +35,42 @@ public class MixAllTest {
assertThat(localInetAddress).contains("127.0.0.1");
assertThat(localInetAddress).contains(local);
}
+
+ @Test
+ public void testBrokerVIPChannel() {
+ assertThat(MixAll.brokerVIPChannel(true, "127.0.0.1:10911")).isEqualTo("127.0.0.1:10909");
+ }
+
+ @Test
+ public void testCompareAndIncreaseOnly() {
+ AtomicLong target = new AtomicLong(5);
+ assertThat(MixAll.compareAndIncreaseOnly(target, 6)).isTrue();
+ assertThat(target.get()).isEqualTo(6);
+
+ assertThat(MixAll.compareAndIncreaseOnly(target, 4)).isFalse();
+ assertThat(target.get()).isEqualTo(6);
+ }
+
+ @Test
+ public void testFile2String() throws IOException {
+ String fileName = System.getProperty("java.io.tmpdir") + File.separator + "MixAllTest" + System.currentTimeMillis();
+ File file = new File(fileName);
+ if (file.exists()) {
+ file.delete();
+ }
+ file.createNewFile();
+ try( PrintWriter out = new PrintWriter( fileName ) ){
+ out.write("TestForMixAll");
+ }
+ String string = MixAll.file2String(fileName);
+ assertThat(string).isEqualTo("TestForMixAll");
+ file.delete();
+ }
+
+ @Test
+ public void testString2File() throws IOException {
+ String fileName = System.getProperty("java.io.tmpdir") + File.separator + "MixAllTest" + System.currentTimeMillis();
+ MixAll.string2File("MixAll_testString2File", fileName);
+ assertThat(MixAll.file2String(fileName)).isEqualTo("MixAll_testString2File");
+ }
}