You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ad...@apache.org on 2022/05/17 18:58:41 UTC
[ozone] branch master updated: HDDS-6737. Migrate parameterized tests in hdds-server-framework to JUnit5 (#3414)
This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new e169d71467 HDDS-6737. Migrate parameterized tests in hdds-server-framework to JUnit5 (#3414)
e169d71467 is described below
commit e169d71467644ee105f71dd65bcef665991e6569
Author: Kaijie Chen <ch...@kaijie.org>
AuthorDate: Wed May 18 02:58:36 2022 +0800
HDDS-6737. Migrate parameterized tests in hdds-server-framework to JUnit5 (#3414)
---
hadoop-hdds/framework/pom.xml | 4 +
.../client/TestCertificateClientInit.java | 73 +++----
.../hdds/server/http/TestRatisNameRewrite.java | 65 +++---
.../hadoop/hdds/utils/db/cache/TestTableCache.java | 237 +++++++++++----------
4 files changed, 185 insertions(+), 194 deletions(-)
diff --git a/hadoop-hdds/framework/pom.xml b/hadoop-hdds/framework/pom.xml
index e09032c73f..f10cd3010c 100644
--- a/hadoop-hdds/framework/pom.xml
+++ b/hadoop-hdds/framework/pom.xml
@@ -141,6 +141,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ </dependency>
</dependencies>
diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/client/TestCertificateClientInit.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/client/TestCertificateClientInit.java
index dc4d7b7d5f..47b02a9a2e 100644
--- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/client/TestCertificateClientInit.java
+++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/x509/certificate/client/TestCertificateClientInit.java
@@ -28,21 +28,19 @@ import org.apache.hadoop.ozone.OzoneSecurityUtil;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.ozone.test.GenericTestUtils;
import org.bouncycastle.cert.X509CertificateHolder;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.UUID;
+import java.util.stream.Stream;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_METADATA_DIR_NAME;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse;
@@ -50,13 +48,13 @@ import static org.apache.hadoop.hdds.security.x509.certificate.client.Certificat
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.GETCERT;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.RECOVER;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.SUCCESS;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
/**
* Test class for {@link DefaultCertificateClient}.
*/
-@RunWith(Parameterized.class)
-@SuppressWarnings("visibilitymodifier")
public class TestCertificateClientInit {
private KeyPair keyPair;
@@ -72,29 +70,20 @@ public class TestCertificateClientInit {
private static final String DN_COMPONENT = DNCertificateClient.COMPONENT_NAME;
private static final String OM_COMPONENT = OMCertificateClient.COMPONENT_NAME;
- @Parameter
- public boolean pvtKeyPresent;
- @Parameter(1)
- public boolean pubKeyPresent;
- @Parameter(2)
- public boolean certPresent;
- @Parameter(3)
- public InitResponse expectedResult;
-
- @Parameterized.Parameters
- public static Collection<Object[]> initData() {
- return Arrays.asList(new Object[][]{
- {false, false, false, GETCERT},
- {false, false, true, FAILURE},
- {false, true, false, FAILURE},
- {true, false, false, FAILURE},
- {false, true, true, FAILURE},
- {true, true, false, GETCERT},
- {true, false, true, SUCCESS},
- {true, true, true, SUCCESS}});
+ private static Stream<Arguments> parameters() {
+ return Stream.of(
+ arguments(false, false, false, GETCERT),
+ arguments(false, false, true, FAILURE),
+ arguments(false, true, false, FAILURE),
+ arguments(true, false, false, FAILURE),
+ arguments(false, true, true, FAILURE),
+ arguments(true, true, false, GETCERT),
+ arguments(true, false, true, SUCCESS),
+ arguments(true, true, true, SUCCESS)
+ );
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
OzoneConfiguration config = new OzoneConfiguration();
final String path = GenericTestUtils
@@ -117,7 +106,7 @@ public class TestCertificateClientInit {
Files.createDirectories(securityConfig.getKeyLocation(OM_COMPONENT));
}
- @After
+ @AfterEach
public void tearDown() {
dnCertificateClient = null;
omCertificateClient = null;
@@ -125,8 +114,10 @@ public class TestCertificateClientInit {
}
- @Test
- public void testInitDatanode() throws Exception {
+ @ParameterizedTest
+ @MethodSource("parameters")
+ public void testInitDatanode(boolean pvtKeyPresent, boolean pubKeyPresent,
+ boolean certPresent, InitResponse expectedResult) throws Exception {
if (pvtKeyPresent) {
dnKeyCodec.writePrivateKey(keyPair.getPrivate());
} else {
@@ -157,7 +148,7 @@ public class TestCertificateClientInit {
}
InitResponse response = dnCertificateClient.init();
- assertTrue(response.equals(expectedResult));
+ assertEquals(expectedResult, response);
if (!response.equals(FAILURE)) {
assertTrue(OzoneSecurityUtil.checkIfFileExist(
@@ -169,8 +160,10 @@ public class TestCertificateClientInit {
}
}
- @Test
- public void testInitOzoneManager() throws Exception {
+ @ParameterizedTest
+ @MethodSource("parameters")
+ public void testInitOzoneManager(boolean pvtKeyPresent, boolean pubKeyPresent,
+ boolean certPresent, InitResponse expectedResult) throws Exception {
if (pvtKeyPresent) {
omKeyCodec.writePrivateKey(keyPair.getPrivate());
} else {
@@ -202,9 +195,9 @@ public class TestCertificateClientInit {
InitResponse response = omCertificateClient.init();
if (pvtKeyPresent && pubKeyPresent && !certPresent) {
- assertTrue(response.equals(RECOVER));
+ assertEquals(RECOVER, response);
} else {
- assertTrue(response.equals(expectedResult));
+ assertEquals(expectedResult, response);
}
if (!response.equals(FAILURE)) {
diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestRatisNameRewrite.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestRatisNameRewrite.java
index f0067fd569..774ccf11aa 100644
--- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestRatisNameRewrite.java
+++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestRatisNameRewrite.java
@@ -20,31 +20,24 @@ package org.apache.hadoop.hdds.server.http;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Stream;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.params.provider.Arguments.arguments;
/**
* Test Ratis metrics renaming.
*/
-@RunWith(Parameterized.class)
public class TestRatisNameRewrite {
- private List<String> names = new ArrayList<>();
- private List<String> values = new ArrayList<>();
-
- private String originalName;
- private String expectedName;
-
- private List<String> expectedTagNames;
- private List<String> expectedTagValues;
- @Parameterized.Parameters
- public static List<Object[]> parameters() {
- return Arrays.asList(
- new Object[] {
+ private static Stream<Arguments> parameters() {
+ return Stream.of(
+ arguments(
"ratis.log_appender"
+ ".851cb00a-af97-455a-b079-d94a77d2a936@group-C14654DE8C2C"
+ ".follower_65f881ea-8794-403d-be77-a030ed79c341_match_index",
@@ -53,8 +46,8 @@ public class TestRatisNameRewrite {
new String[] {"851cb00a-af97-455a-b079-d94a77d2a936",
"group-C14654DE8C2C",
"65f881ea-8794-403d-be77-a030ed79c341"}
- },
- new Object[] {
+ ),
+ arguments(
"ratis_grpc.log_appender.72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67@group"
+ "-72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"
+ ".grpc_log_appender_follower_75fa730a-59f0-4547"
@@ -64,15 +57,15 @@ public class TestRatisNameRewrite {
new String[] {"72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67",
"group-72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67",
"75fa730a-59f0-4547-bd68-216162c263eb"}
- },
- new Object[] {
+ ),
+ arguments(
"ratis_core.ratis_log_worker.72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"
+ ".dataQueueSize",
"ratis_core.ratis_log_worker.dataQueueSize",
new String[] {"instance"},
new String[] {"72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"}
- },
- new Object[] {
+ ),
+ arguments(
"ratis_grpc.log_appender.8e505d6e-12a4-4660-80e3-eb735879db06"
+ "@group-49616B7F02CE.grpc_log_appender_follower_a4b099a7"
+ "-511f-4fef-85bf-b9eeddd7c270_latency",
@@ -80,8 +73,8 @@ public class TestRatisNameRewrite {
new String[] {"instance", "group", "follower"},
new String[] {"8e505d6e-12a4-4660-80e3-eb735879db06",
"group-49616B7F02CE", "a4b099a7-511f-4fef-85bf-b9eeddd7c270"}
- },
- new Object[] {
+ ),
+ arguments(
"ratis_grpc.log_appender.8e505d6e-12a4-4660-80e3-eb735879db06"
+ "@group-49616B7F02CE.grpc_log_appender_follower_a4b099a7"
+ "-511f-4fef-85bf-b9eeddd7c270_success_reply_count",
@@ -90,28 +83,24 @@ public class TestRatisNameRewrite {
new String[] {"instance", "group", "follower"},
new String[] {"8e505d6e-12a4-4660-80e3-eb735879db06",
"group-49616B7F02CE", "a4b099a7-511f-4fef-85bf-b9eeddd7c270"}
- }
-
+ )
);
}
- public TestRatisNameRewrite(String originalName, String expectedName,
+ @ParameterizedTest
+ @MethodSource("parameters")
+ public void normalizeRatisMetricName(String originalName, String expectedName,
String[] expectedTagNames, String[] expectedTagValues) {
- this.originalName = originalName;
- this.expectedName = expectedName;
- this.expectedTagNames = Arrays.asList(expectedTagNames);
- this.expectedTagValues = Arrays.asList(expectedTagValues);
- }
- @Test
- public void normalizeRatisMetricName() {
+ List<String> names = new ArrayList<>();
+ List<String> values = new ArrayList<>();
String cleanName = new RatisNameRewriteSampleBuilder()
.normalizeRatisMetric(originalName, names, values);
- Assert.assertEquals(expectedName, cleanName);
- Assert.assertEquals(expectedTagNames, names);
- Assert.assertEquals(expectedTagValues, values);
+ Assertions.assertEquals(expectedName, cleanName);
+ Assertions.assertEquals(Arrays.asList(expectedTagNames), names);
+ Assertions.assertEquals(Arrays.asList(expectedTagValues), values);
}
}
\ No newline at end of file
diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/cache/TestTableCache.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/cache/TestTableCache.java
index 0449a79e1d..8881636d04 100644
--- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/cache/TestTableCache.java
+++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/cache/TestTableCache.java
@@ -20,68 +20,43 @@
package org.apache.hadoop.hdds.utils.db.cache;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import com.google.common.base.Optional;
import org.apache.ozone.test.GenericTestUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
import org.slf4j.event.Level;
-import static org.junit.Assert.fail;
/**
* Class tests partial table cache.
*/
-@RunWith(value = Parameterized.class)
public class TestTableCache {
- private static final Logger LOG =
- LoggerFactory.getLogger(TestTableCache.class);
-
private TableCache<CacheKey<String>, CacheValue<String>> tableCache;
- private final TableCache.CacheType cacheType;
-
-
- @Parameterized.Parameters
- public static Collection<Object[]> policy() {
- Object[][] params = new Object[][] {
- {TableCache.CacheType.FULL_CACHE},
- {TableCache.CacheType.PARTIAL_CACHE}
- };
- return Arrays.asList(params);
- }
-
- public TestTableCache(
- TableCache.CacheType cacheType) {
+ @BeforeAll
+ public static void setLogLevel() {
GenericTestUtils.setLogLevel(FullTableCache.LOG, Level.DEBUG);
- this.cacheType = cacheType;
}
-
- @Before
- public void create() {
+ private void createTableCache(TableCache.CacheType cacheType) {
if (cacheType == TableCache.CacheType.FULL_CACHE) {
tableCache = new FullTableCache<>();
} else {
tableCache = new PartialTableCache<>();
}
- LOG.info("cacheType: {}", cacheType);
}
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testPartialTableCache(TableCache.CacheType cacheType) {
- @Test
- public void testPartialTableCache() {
-
+ createTableCache(cacheType);
for (int i = 0; i < 10; i++) {
tableCache.put(new CacheKey<>(Integer.toString(i)),
@@ -90,27 +65,31 @@ public class TestTableCache {
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(Integer.toString(i),
+ Assertions.assertEquals(Integer.toString(i),
tableCache.get(new CacheKey<>(Integer.toString(i))).getCacheValue());
}
- ArrayList<Long> epochs = new ArrayList();
+ ArrayList<Long> epochs = new ArrayList<>();
epochs.add(0L);
epochs.add(1L);
epochs.add(2L);
epochs.add(3L);
epochs.add(4L);
- // On a full table cache if some one calls cleanup it is a no-op.
+ // On a full table cache if someone calls cleanup it is a no-op.
tableCache.evictCache(epochs);
for (int i = 5; i < 10; i++) {
- Assert.assertEquals(Integer.toString(i),
+ Assertions.assertEquals(Integer.toString(i),
tableCache.get(new CacheKey<>(Integer.toString(i))).getCacheValue());
}
}
- @Test
- public void testTableCacheWithRenameKey() {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testTableCacheWithRenameKey(TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
+
// putting cache with same epoch and different keyNames
for (int i = 0; i < 3; i++) {
tableCache.put(new CacheKey<>(Integer.toString(i).concat("A")),
@@ -121,18 +100,19 @@ public class TestTableCache {
// Epoch entries should be like (long, (key1, key2, ...))
// (0, (0A, 0B)) (1, (1A, 1B)) (2, (2A, 1B))
- Assert.assertEquals(3, tableCache.getEpochEntries().size());
- Assert.assertEquals(2, tableCache.getEpochEntries().get(0L).size());
+ Assertions.assertEquals(3, tableCache.getEpochEntries().size());
+ Assertions.assertEquals(2, tableCache.getEpochEntries().get(0L).size());
// Cache should be like (key, (cacheValue, long))
// (0A, (null, 0)) (0B, (0, 0))
// (1A, (null, 1)) (1B, (0, 1))
// (2A, (null, 2)) (2B, (0, 2))
for (int i = 0; i < 3; i++) {
- Assert.assertNull(tableCache.get(new CacheKey<>(
+ Assertions.assertNull(tableCache.get(new CacheKey<>(
Integer.toString(i).concat("A"))).getCacheValue());
- Assert.assertEquals(Integer.toString(i), tableCache.get(new CacheKey<>(
- Integer.toString(i).concat("B"))).getCacheValue());
+ Assertions.assertEquals(Integer.toString(i),
+ tableCache.get(new CacheKey<>(Integer.toString(i).concat("B")))
+ .getCacheValue());
}
ArrayList<Long> epochs = new ArrayList<>();
@@ -144,24 +124,29 @@ public class TestTableCache {
tableCache.evictCache(epochs);
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
} else {
- Assert.assertEquals(3, tableCache.size());
+ Assertions.assertEquals(3, tableCache.size());
}
}
- @Test
- public void testPartialTableCacheWithNotContinousEntries() throws Exception {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testPartialTableCacheWithNotContinuousEntries(
+ TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
+
int totalCount = 0;
int insertedCount = 3000;
int cleanupCount = 0;
- ArrayList<Long> epochs = new ArrayList();
+ ArrayList<Long> epochs = new ArrayList<>();
for (long i = 0; i < insertedCount; i += 2) {
if (cleanupCount++ < 1000) {
epochs.add(i);
@@ -171,7 +156,7 @@ public class TestTableCache {
totalCount++;
}
- Assert.assertEquals(totalCount, tableCache.size());
+ Assertions.assertEquals(totalCount, tableCache.size());
tableCache.evictCache(epochs);
@@ -179,30 +164,34 @@ public class TestTableCache {
// If cleanup policy is manual entries should have been removed.
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
- Assert.assertEquals(count - epochs.size(), tableCache.size());
+ Assertions.assertEquals(count - epochs.size(), tableCache.size());
// Check remaining entries exist or not and deleted entries does not
// exist.
for (long i = 0; i < insertedCount; i += 2) {
if (!epochs.contains(i)) {
- Assert.assertEquals(Long.toString(i),
+ Assertions.assertEquals(Long.toString(i),
tableCache.get(new CacheKey<>(Long.toString(i))).getCacheValue());
} else {
- Assert.assertEquals(null,
+ Assertions.assertNull(
tableCache.get(new CacheKey<>(Long.toString(i))));
}
}
} else {
for (long i = 0; i < insertedCount; i += 2) {
- Assert.assertEquals(Long.toString(i),
+ Assertions.assertEquals(Long.toString(i),
tableCache.get(new CacheKey<>(Long.toString(i))).getCacheValue());
}
}
}
- @Test
- public void testPartialTableCacheWithOverrideEntries() throws Exception {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testPartialTableCacheWithOverrideEntries(
+ TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
tableCache.put(new CacheKey<>(Long.toString(0)),
new CacheValue<>(Optional.of(Long.toString(0)), 0));
@@ -223,9 +212,9 @@ public class TestTableCache {
- Assert.assertEquals(3, tableCache.size());
+ Assertions.assertEquals(3, tableCache.size());
// It will have 2 additional entries because we have 2 override entries.
- Assert.assertEquals(3 + 2,
+ Assertions.assertEquals(3 + 2,
tableCache.getEpochEntries().size());
// Now remove
@@ -241,9 +230,9 @@ public class TestTableCache {
tableCache.evictCache(epochs);
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
}
// Add a new entry.
@@ -255,17 +244,21 @@ public class TestTableCache {
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
tableCache.evictCache(epochs);
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
- // Overrided entries would have been deleted.
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ // Overridden entries would have been deleted.
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
}
}
- @Test
- public void testPartialTableCacheWithOverrideAndDelete() throws Exception {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testPartialTableCacheWithOverrideAndDelete(
+ TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
tableCache.put(new CacheKey<>(Long.toString(0)),
new CacheValue<>(Optional.of(Long.toString(0)), 0));
@@ -275,13 +268,13 @@ public class TestTableCache {
new CacheValue<>(Optional.of(Long.toString(2)), 2));
- //Override entries
+ // Override entries
tableCache.put(new CacheKey<>(Long.toString(0)),
new CacheValue<>(Optional.of(Long.toString(0)), 3));
tableCache.put(new CacheKey<>(Long.toString(1)),
new CacheValue<>(Optional.of(Long.toString(1)), 4));
- // Finally mark them for deleted
+ // Finally, mark them for deleted
tableCache.put(new CacheKey<>(Long.toString(0)),
new CacheValue<>(Optional.absent(), 5));
tableCache.put(new CacheKey<>(Long.toString(1)),
@@ -293,9 +286,9 @@ public class TestTableCache {
// 0-5, 1-6, 2-2
- Assert.assertEquals(3, tableCache.size());
+ Assertions.assertEquals(3, tableCache.size());
// It will have 4 additional entries because we have 4 override entries.
- Assert.assertEquals(3 + 4,
+ Assertions.assertEquals(3 + 4,
tableCache.getEpochEntries().size());
// Now remove
@@ -313,16 +306,16 @@ public class TestTableCache {
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
tableCache.evictCache(epochs);
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
} else {
tableCache.evictCache(epochs);
- Assert.assertEquals(1, tableCache.size());
+ Assertions.assertEquals(1, tableCache.size());
- // Epoch entries which are overrided also will be cleaned up.
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ // Epoch entries which are overridden also will be cleaned up.
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
}
// Add a new entry, now old override entries will be cleaned up.
@@ -335,26 +328,30 @@ public class TestTableCache {
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
tableCache.evictCache(epochs);
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
- // Epoch entries which are overrided now would have been deleted.
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ // Epoch entries which are overridden now would have been deleted.
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
} else {
tableCache.evictCache(epochs);
// 2 entries will be in cache, as 2 are not deleted.
- Assert.assertEquals(2, tableCache.size());
+ Assertions.assertEquals(2, tableCache.size());
// Epoch entries which are not marked for delete will also be cleaned up.
// As they are override entries in full cache.
- Assert.assertEquals(0, tableCache.getEpochEntries().size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
}
}
- @Test
- public void testPartialTableCacheParallel() throws Exception {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testPartialTableCacheParallel(
+ TableCache.CacheType cacheType) throws Exception {
+
+ createTableCache(cacheType);
int totalCount = 0;
CompletableFuture<Integer> future =
@@ -362,12 +359,12 @@ public class TestTableCache {
try {
return writeToCache(10, 1, 0);
} catch (InterruptedException ex) {
- fail("writeToCache got interrupt exception");
+ Assertions.fail("writeToCache got interrupt exception");
}
return 0;
});
int value = future.get();
- Assert.assertEquals(10, value);
+ Assertions.assertEquals(10, value);
totalCount += value;
@@ -376,27 +373,27 @@ public class TestTableCache {
try {
return writeToCache(10, 11, 100);
} catch (InterruptedException ex) {
- fail("writeToCache got interrupt exception");
+ Assertions.fail("writeToCache got interrupt exception");
}
return 0;
});
// Check we have first 10 entries in cache.
for (int i = 1; i <= 10; i++) {
- Assert.assertEquals(Integer.toString(i),
+ Assertions.assertEquals(Integer.toString(i),
tableCache.get(new CacheKey<>(Integer.toString(i))).getCacheValue());
}
value = future.get();
- Assert.assertEquals(10, value);
+ Assertions.assertEquals(10, value);
totalCount += value;
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
int deleted = 5;
- // cleanup first 5 entires
+ // cleanup first 5 entries
ArrayList<Long> epochs = new ArrayList<>();
epochs.add(1L);
@@ -407,11 +404,10 @@ public class TestTableCache {
tableCache.evictCache(epochs);
// We should totalCount - deleted entries in cache.
- final int tc = totalCount;
- Assert.assertEquals(tc - deleted, tableCache.size());
+ Assertions.assertEquals(totalCount - deleted, tableCache.size());
// Check if we have remaining entries.
for (int i = 6; i <= totalCount; i++) {
- Assert.assertEquals(Integer.toString(i), tableCache.get(
+ Assertions.assertEquals(Integer.toString(i), tableCache.get(
new CacheKey<>(Integer.toString(i))).getCacheValue());
}
@@ -423,21 +419,24 @@ public class TestTableCache {
tableCache.evictCache(epochs);
// Cleaned up all entries, so cache size should be zero.
- Assert.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.size());
} else {
ArrayList<Long> epochs = new ArrayList<>();
for (long i = 0; i <= totalCount; i++) {
epochs.add(i);
}
tableCache.evictCache(epochs);
- Assert.assertEquals(totalCount, tableCache.size());
+ Assertions.assertEquals(totalCount, tableCache.size());
}
}
- @Test
- public void testTableCache() {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testTableCache(TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
// In non-HA epoch entries might be out of order.
// Scenario is like create vol, set vol, set vol, delete vol
@@ -459,13 +458,17 @@ public class TestTableCache {
tableCache.evictCache(epochs);
- Assert.assertTrue(tableCache.size() == 0);
- Assert.assertTrue(tableCache.getEpochEntries().size() == 0);
+ Assertions.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
}
- @Test
- public void testTableCacheWithNonConsecutiveEpochList() {
+ @ParameterizedTest
+ @EnumSource(TableCache.CacheType.class)
+ public void testTableCacheWithNonConsecutiveEpochList(
+ TableCache.CacheType cacheType) {
+
+ createTableCache(cacheType);
// In non-HA epoch entries might be out of order.
tableCache.put(new CacheKey<>(Long.toString(0)),
@@ -488,15 +491,15 @@ public class TestTableCache {
tableCache.evictCache(epochs);
- Assert.assertTrue(tableCache.size() == 2);
- Assert.assertTrue(tableCache.getEpochEntries().size() == 2);
+ Assertions.assertEquals(2, tableCache.size());
+ Assertions.assertEquals(2, tableCache.getEpochEntries().size());
- Assert.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(0))));
- Assert.assertEquals(2,
+ Assertions.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(0))));
+ Assertions.assertEquals(2,
tableCache.get(new CacheKey<>(Long.toString(0))).getEpoch());
- Assert.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(1))));
- Assert.assertEquals(4,
+ Assertions.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(1))));
+ Assertions.assertEquals(4,
tableCache.get(new CacheKey<>(Long.toString(1))).getEpoch());
// now evict 2,4
@@ -507,19 +510,21 @@ public class TestTableCache {
tableCache.evictCache(epochs);
if (cacheType == TableCache.CacheType.PARTIAL_CACHE) {
- Assert.assertTrue(tableCache.size() == 0);
- Assert.assertTrue(tableCache.getEpochEntries().size() == 0);
+ Assertions.assertEquals(0, tableCache.size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
} else {
- Assert.assertTrue(tableCache.size() == 2);
- Assert.assertTrue(tableCache.getEpochEntries().size() == 0);
+ Assertions.assertEquals(2, tableCache.size());
+ Assertions.assertEquals(0, tableCache.getEpochEntries().size());
// Entries should exist, as the entries are not delete entries
- Assert.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(0))));
- Assert.assertEquals(2,
+ Assertions.assertNotNull(
+ tableCache.get(new CacheKey<>(Long.toString(0))));
+ Assertions.assertEquals(2,
tableCache.get(new CacheKey<>(Long.toString(0))).getEpoch());
- Assert.assertNotNull(tableCache.get(new CacheKey<>(Long.toString(1))));
- Assert.assertEquals(4,
+ Assertions.assertNotNull(
+ tableCache.get(new CacheKey<>(Long.toString(1))));
+ Assertions.assertEquals(4,
tableCache.get(new CacheKey<>(Long.toString(1))).getEpoch());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org