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 b0f36488d99951de646745685a0d3a3e8ece051c..3a40dd56a7e3a584da13ae66f984f6a764726e6e 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 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"); + } }