You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by ro...@apache.org on 2022/07/21 08:55:05 UTC
[incubator-uniffle] branch master updated: [TEST] Add more unit tests in rss-common (#63)
This is an automated email from the ASF dual-hosted git repository.
roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new 174e6bb [TEST] Add more unit tests in rss-common (#63)
174e6bb is described below
commit 174e6bb7c65556de51fd74dacca6d44469a36375
Author: Kaijie Chen <ch...@kaijie.org>
AuthorDate: Thu Jul 21 16:55:00 2022 +0800
[TEST] Add more unit tests in rss-common (#63)
### What changes were proposed in this pull request?
Add more unit tests in rss-common.
### Why are the changes needed?
Improve coverage.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
By CI.
---
.../apache/uniffle/common/BufferSegmentTest.java | 1 +
.../apache/uniffle/common/PartitionRangeTest.java | 2 +
.../apache/uniffle/common/RssShuffleUtilsTest.java | 39 ++++++++-------
.../uniffle/common/ShuffleBlockInfoTest.java | 54 +++++++++++++++++++++
...leUtilsTest.java => ShuffleDataResultTest.java} | 33 ++++++-------
...dBlockTest.java => ShuffleIndexResultTest.java} | 23 +++------
.../common/ShufflePartitionedBlockTest.java | 46 ++++++++++++++++++
.../uniffle/common/ShufflePartitionedDataTest.java | 42 ++++++++++++++++
.../uniffle/common/ShuffleRegisterInfoTest.java | 55 +++++++++++++++++++++
.../uniffle/common/ShuffleServerInfoTest.java | 56 ++++++++++++++++++++++
10 files changed, 298 insertions(+), 53 deletions(-)
diff --git a/common/src/test/java/org/apache/uniffle/common/BufferSegmentTest.java b/common/src/test/java/org/apache/uniffle/common/BufferSegmentTest.java
index 1e40447..abe5fb0 100644
--- a/common/src/test/java/org/apache/uniffle/common/BufferSegmentTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/BufferSegmentTest.java
@@ -32,6 +32,7 @@ public class BufferSegmentTest {
BufferSegment segment1 = new BufferSegment(0, 1, 2, 3, 4, 5);
BufferSegment segment2 = new BufferSegment(0, 1, 2, 3, 4, 5);
assertEquals(segment1, segment2);
+ assertEquals(segment1.hashCode(), segment2.hashCode());
assertNotEquals(segment1, null);
assertNotEquals(segment1, new Object());
}
diff --git a/common/src/test/java/org/apache/uniffle/common/PartitionRangeTest.java b/common/src/test/java/org/apache/uniffle/common/PartitionRangeTest.java
index 69bf97f..0025b6a 100644
--- a/common/src/test/java/org/apache/uniffle/common/PartitionRangeTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/PartitionRangeTest.java
@@ -44,7 +44,9 @@ public class PartitionRangeTest {
PartitionRange partitionRange3 = new PartitionRange(1, 1);
PartitionRange partitionRange4 = new PartitionRange(2, 2);
assertEquals(partitionRange1, partitionRange1);
+ assertEquals(partitionRange1.hashCode(), partitionRange1.hashCode());
assertEquals(partitionRange1, partitionRange2);
+ assertEquals(partitionRange1.hashCode(), partitionRange2.hashCode());
assertNotEquals(partitionRange1, partitionRange3);
assertNotEquals(partitionRange1, partitionRange4);
assertNotEquals(partitionRange1, null);
diff --git a/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java b/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java
index a0822a9..c348816 100644
--- a/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java
@@ -17,30 +17,33 @@
package org.apache.uniffle.common;
-import com.google.common.collect.Lists;
-import org.junit.jupiter.api.Test;
+import java.nio.ByteBuffer;
+import org.apache.commons.lang3.RandomUtils;
-import java.util.List;
-import java.util.Random;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class RssShuffleUtilsTest {
- @Test
- public void compressionTest() {
- List<Integer> testSizes = Lists.newArrayList(
- 1, 1024, 128 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024);
- for (int size : testSizes) {
- singleTest(size);
- }
- }
- private void singleTest(int size) {
- byte[] buf = new byte[size];
- new Random().nextBytes(buf);
+ @ParameterizedTest
+ @ValueSource(ints = {1, 1024, 128 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024})
+ public void testCompression(int size) {
+ byte[] data = RandomUtils.nextBytes(size);
+ byte[] compressed = RssShuffleUtils.compressData(data);
+ byte[] decompressed = RssShuffleUtils.decompressData(compressed, size);
+ assertArrayEquals(data, decompressed);
+
+ ByteBuffer decompressedBB = RssShuffleUtils.decompressData(ByteBuffer.wrap(compressed), size);
+ byte[] buffer = new byte[size];
+ decompressedBB.get(buffer);
+ assertArrayEquals(data, buffer);
- byte[] compressed = RssShuffleUtils.compressData(buf);
- byte[] uncompressed = RssShuffleUtils.decompressData(compressed, size);
- assertArrayEquals(buf, uncompressed);
+ ByteBuffer decompressedBB2 = RssShuffleUtils.decompressData(ByteBuffer.wrap(compressed), size, false);
+ byte[] buffer2 = new byte[size];
+ decompressedBB2.get(buffer2);
+ assertArrayEquals(data, buffer2);
}
+
}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShuffleBlockInfoTest.java b/common/src/test/java/org/apache/uniffle/common/ShuffleBlockInfoTest.java
new file mode 100644
index 0000000..671ea56
--- /dev/null
+++ b/common/src/test/java/org/apache/uniffle/common/ShuffleBlockInfoTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.uniffle.common;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ShuffleBlockInfoTest {
+
+ @Test
+ public void testToString() {
+ List<ShuffleServerInfo> shuffleServerInfos =
+ Collections.singletonList(new ShuffleServerInfo("0", "localhost", 1234));
+ ShuffleBlockInfo info = new ShuffleBlockInfo(1, 2, 3, 4, 5, new byte[6],
+ shuffleServerInfos, 7, 8, 9);
+ assertEquals("ShuffleBlockInfo:shuffleId[" + info.getShuffleId() +
+ "],partitionId[" + info.getPartitionId() +
+ "],blockId[" + info.getBlockId() +
+ "],length[" + info.getLength() +
+ "],uncompressLength[" + info.getUncompressLength() +
+ "],crc[" + info.getCrc() +
+ "],shuffleServer[0,]",
+ info.toString());
+
+ ShuffleBlockInfo info2 = new ShuffleBlockInfo(1, 2, 3, 4, 5, new byte[6],
+ null, 7, 8, 9);
+ assertEquals("ShuffleBlockInfo:shuffleId[" + info2.getShuffleId() +
+ "],partitionId[" + info2.getPartitionId() +
+ "],blockId[" + info2.getBlockId() +
+ "],length[" + info2.getLength() +
+ "],uncompressLength[" + info2.getUncompressLength() +
+ "],crc[" + info2.getCrc() +
+ "],shuffleServer is empty",
+ info2.toString());
+ }
+}
diff --git a/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java b/common/src/test/java/org/apache/uniffle/common/ShuffleDataResultTest.java
similarity index 53%
copy from common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java
copy to common/src/test/java/org/apache/uniffle/common/ShuffleDataResultTest.java
index a0822a9..3a2bdd1 100644
--- a/common/src/test/java/org/apache/uniffle/common/RssShuffleUtilsTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/ShuffleDataResultTest.java
@@ -17,30 +17,25 @@
package org.apache.uniffle.common;
-import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
import org.junit.jupiter.api.Test;
-import java.util.List;
-import java.util.Random;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+public class ShuffleDataResultTest {
-public class RssShuffleUtilsTest {
@Test
- public void compressionTest() {
- List<Integer> testSizes = Lists.newArrayList(
- 1, 1024, 128 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024);
- for (int size : testSizes) {
- singleTest(size);
- }
+ public void testEmpty() {
+ List<BufferSegment> segments = Collections.singletonList(new BufferSegment(1, 2, 3, 4, 5, 6));
+ assertTrue(new ShuffleDataResult().isEmpty());
+ assertTrue(new ShuffleDataResult(new byte[1]).isEmpty());
+ assertTrue(new ShuffleDataResult(null, segments).isEmpty());
+ assertTrue(new ShuffleDataResult(new byte[0], segments).isEmpty());
+ assertTrue(new ShuffleDataResult(new byte[1], null).isEmpty());
+ assertTrue(new ShuffleDataResult(new byte[1], Collections.emptyList()).isEmpty());
+ assertFalse(new ShuffleDataResult(new byte[1], segments).isEmpty());
}
- private void singleTest(int size) {
- byte[] buf = new byte[size];
- new Random().nextBytes(buf);
-
- byte[] compressed = RssShuffleUtils.compressData(buf);
- byte[] uncompressed = RssShuffleUtils.decompressData(compressed, size);
- assertArrayEquals(buf, uncompressed);
- }
}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java b/common/src/test/java/org/apache/uniffle/common/ShuffleIndexResultTest.java
similarity index 58%
copy from common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java
copy to common/src/test/java/org/apache/uniffle/common/ShuffleIndexResultTest.java
index 9bca881..74c7c0d 100644
--- a/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/ShuffleIndexResultTest.java
@@ -17,25 +17,16 @@
package org.apache.uniffle.common;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Random;
import org.junit.jupiter.api.Test;
-public class ShufflePartitionedBlockTest {
-
- @Test
- public void shufflePartitionedBlockTest() {
- byte[] buf = new byte[3];
- new Random().nextBytes(buf);
+import static org.junit.jupiter.api.Assertions.assertTrue;
- ShufflePartitionedBlock b1 = new ShufflePartitionedBlock(1, 1, 2, 3, 1, buf);
- assertEquals(1, b1.getLength());
- assertEquals(2, b1.getCrc());
- assertEquals(3, b1.getBlockId());
+public class ShuffleIndexResultTest {
- ShufflePartitionedBlock b3 = new ShufflePartitionedBlock(1, 1, 2, 3, 3, buf);
- assertArrayEquals(buf, b3.getData());
+ @Test
+ public void testEmpty() {
+ assertTrue(new ShuffleIndexResult().isEmpty());
+ assertTrue(new ShuffleIndexResult(null).isEmpty());
}
+
}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java b/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java
index 9bca881..1cf3aff 100644
--- a/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedBlockTest.java
@@ -19,9 +19,12 @@ package org.apache.uniffle.common;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.Random;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
public class ShufflePartitionedBlockTest {
@@ -38,4 +41,47 @@ public class ShufflePartitionedBlockTest {
ShufflePartitionedBlock b3 = new ShufflePartitionedBlock(1, 1, 2, 3, 3, buf);
assertArrayEquals(buf, b3.getData());
}
+
+ @Test
+ public void testEquals() {
+ ShufflePartitionedBlock b1 = new ShufflePartitionedBlock(1, 2, 3, 4, 5, new byte[6]);
+ ShufflePartitionedBlock b2 = new ShufflePartitionedBlock(1, 6, 3, 4, 7, new byte[6]);
+ assertEquals(b1, b1);
+ assertEquals(b1.hashCode(), b1.hashCode());
+ assertEquals(b1, b2);
+ assertEquals(b1.hashCode(), b2.hashCode());
+ assertNotEquals(b1, null);
+ assertNotEquals(b1, new Object());
+ }
+
+ @ParameterizedTest
+ @CsvSource({
+ "5, 2, 3, 4",
+ "1, 5, 3, 4",
+ "1, 2, 5, 4",
+ "1, 2, 3, 5"
+ })
+ public void testNotEquals(int length, long crc, long blockId, int dataSize) {
+ ShufflePartitionedBlock b1 = new ShufflePartitionedBlock(1, 0, 2, 3, 0, new byte[4]);
+ ShufflePartitionedBlock b2 = new ShufflePartitionedBlock(length, 0, crc, blockId, 0, new byte[dataSize]);
+ assertNotEquals(b1, b2);
+ }
+
+ @Test
+ public void testToString() {
+ ShufflePartitionedBlock b1 = new ShufflePartitionedBlock(1, 2, 3, 4, 5, new byte[6]);
+ assertEquals("ShufflePartitionedBlock{blockId[" + b1.getBlockId() +
+ "], length[" + b1.getLength() +
+ "], uncompressLength[" + b1.getUncompressLength() +
+ "], crc[" + b1.getCrc() +
+ "], taskAttemptId[" + b1.getTaskAttemptId() + "]}",
+ b1.toString());
+ }
+
+ @Test
+ public void testSize() {
+ ShufflePartitionedBlock b1 = new ShufflePartitionedBlock(1, 2, 3, 4, 5, new byte[6]);
+ assertEquals(b1.getSize(), b1.getLength() + 3 * Long.BYTES + 2 * Integer.BYTES);
+ }
+
}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedDataTest.java b/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedDataTest.java
new file mode 100644
index 0000000..04529fb
--- /dev/null
+++ b/common/src/test/java/org/apache/uniffle/common/ShufflePartitionedDataTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.uniffle.common;
+
+import java.util.Arrays;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ShufflePartitionedDataTest {
+
+ @Test
+ public void testToString() {
+ ShufflePartitionedData data = new ShufflePartitionedData(0, new ShufflePartitionedBlock[]{});
+ assertEquals("ShufflePartitionedData{partitionId=" + data.getPartitionId() + ", blockList=" +
+ Arrays.toString(data.getBlockList()) + "}", data.toString());
+ ShufflePartitionedData data1 = new ShufflePartitionedData(1,
+ new ShufflePartitionedBlock[]{new ShufflePartitionedBlock(2, 3, 4, 5, 6, new byte[0])});
+ assertEquals("ShufflePartitionedData{partitionId=" + data1.getPartitionId() + ", blockList=" +
+ Arrays.toString(data1.getBlockList()) + "}", data1.toString());
+ ShufflePartitionedData data2 = new ShufflePartitionedData(0, null);
+ assertEquals("ShufflePartitionedData{partitionId=0, blockList=null}", data2.toString());
+ data2.setPartitionId(1);
+ assertEquals("ShufflePartitionedData{partitionId=1, blockList=null}", data2.toString());
+ }
+
+}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShuffleRegisterInfoTest.java b/common/src/test/java/org/apache/uniffle/common/ShuffleRegisterInfoTest.java
new file mode 100644
index 0000000..a83f42a
--- /dev/null
+++ b/common/src/test/java/org/apache/uniffle/common/ShuffleRegisterInfoTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.uniffle.common;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class ShuffleRegisterInfoTest {
+
+ @Test
+ public void testEquals() {
+ ShuffleServerInfo shuffleServerInfo = new ShuffleServerInfo("1", "localhost", 1234);
+ List<PartitionRange> partitionRanges = Collections.singletonList(new PartitionRange(2, 3));
+ ShuffleRegisterInfo info1 = new ShuffleRegisterInfo(shuffleServerInfo, partitionRanges);
+ ShuffleRegisterInfo info2 = new ShuffleRegisterInfo(info1.getShuffleServerInfo(), info1.getPartitionRanges());
+ ShuffleRegisterInfo info3 = new ShuffleRegisterInfo(info1.getShuffleServerInfo(), null);
+ ShuffleRegisterInfo info4 = new ShuffleRegisterInfo(null, info1.getPartitionRanges());
+ assertEquals(info1, info1);
+ assertEquals(info1.hashCode(), info1.hashCode());
+ assertEquals(info1, info2);
+ assertEquals(info1.hashCode(), info2.hashCode());
+ assertNotEquals(info1, null);
+ assertNotEquals(info1, new Object());
+ assertNotEquals(info1, info3);
+ assertNotEquals(info1, info4);
+ }
+
+ @Test
+ public void testToString() {
+ ShuffleServerInfo shuffleServerInfo = new ShuffleServerInfo("1", "localhost", 1234);
+ List<PartitionRange> partitionRanges = Collections.singletonList(new PartitionRange(2, 3));
+ ShuffleRegisterInfo info = new ShuffleRegisterInfo(shuffleServerInfo, partitionRanges);
+ assertEquals("ShuffleRegisterInfo: shuffleServerInfo[1], [PartitionRange[2, 3]]", info.toString());
+ }
+
+}
diff --git a/common/src/test/java/org/apache/uniffle/common/ShuffleServerInfoTest.java b/common/src/test/java/org/apache/uniffle/common/ShuffleServerInfoTest.java
new file mode 100644
index 0000000..dd98a7c
--- /dev/null
+++ b/common/src/test/java/org/apache/uniffle/common/ShuffleServerInfoTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.uniffle.common;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class ShuffleServerInfoTest {
+
+ @Test
+ public void testEquals() {
+ ShuffleServerInfo info = new ShuffleServerInfo("1", "localhost", 1234);
+ ShuffleServerInfo info2 = new ShuffleServerInfo("1", "localhost", 1234);
+ assertEquals(info, info);
+ assertEquals(info.hashCode(), info.hashCode());
+ assertEquals(info, info2);
+ assertEquals(info.hashCode(), info2.hashCode());
+ assertNotEquals(info, null);
+ assertNotEquals(info, new Object());
+
+ ShuffleServerInfo info3 = new ShuffleServerInfo("2", "localhost", 1234);
+ ShuffleServerInfo info4 = new ShuffleServerInfo("1", "host1", 1234);
+ ShuffleServerInfo info5 = new ShuffleServerInfo("1", "localhost", 1235);
+ assertNotEquals(info, info3);
+ assertNotEquals(info, info4);
+ assertNotEquals(info, info5);
+ }
+
+
+ @Test
+ public void testToString() {
+ ShuffleServerInfo info = new ShuffleServerInfo("1", "localhost", 1234);
+ assertEquals("ShuffleServerInfo{id[" + info.getId() +
+ "], host[" + info.getHost() +
+ "], port[" + info.getPort() +
+ "]}", info.toString());
+ }
+
+}