Repository: incubator-rocketmq
Updated Branches:
  refs/heads/master 13f4297ee -> 6f60b4e85


[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/6f60b4e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/6f60b4e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/6f60b4e8

Branch: refs/heads/master
Commit: 6f60b4e85c00ad9afcf574f631b9cd824f08fd54
Parents: f529670
Author: yukon <[email protected]>
Authored: Sun Jan 22 20:43:36 2017 +0800
Committer: yukon <[email protected]>
Committed: Sun Jan 22 20:58:08 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/6f60b4e8/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");
+    }
 }

Reply via email to