Skip to content

Commit

Permalink
RATIS-1975. Migrate ratis-metrics-dropwizard3 tests to Junit 5. (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
nandakumar131 authored and szetszwo committed Jun 16, 2024
1 parent 2b30cb8 commit 016018f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
10 changes: 10 additions & 0 deletions ratis-metrics-dropwizard3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.ratis.metrics.MetricRegistriesLoader;
import org.apache.ratis.metrics.MetricRegistryInfo;
import org.apache.ratis.metrics.RatisMetricRegistry;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Test class for {@link MetricRegistriesLoader}.
Expand All @@ -33,7 +33,7 @@ public class TestLoadDm3MetricRegistries {
@Test
public void testLoadDm3() {
final MetricRegistries r = MetricRegistriesLoader.load();
Assert.assertSame(Dm3MetricRegistriesImpl.class, r.getClass());
Assertions.assertSame(Dm3MetricRegistriesImpl.class, r.getClass());
}

@Test
Expand All @@ -47,15 +47,15 @@ public void testAddRemoveReporter() {
// check if add and remove of metric do reporting counter increase
MetricRegistryInfo info = new MetricRegistryInfo("t1", "t1", "t1", "t1");
r.create(info);
Assert.assertTrue(cntr.get() == 1);
Assertions.assertEquals(1, cntr.get());
r.remove(info);
Assert.assertTrue(cntr.get() == 2);
Assertions.assertEquals(2, cntr.get());

// after removal, add and remove of metric must not do any increase
r.removeReporterRegistration(reporter, stopReporter);
r.create(info);
Assert.assertTrue(cntr.get() == 2);
Assertions.assertEquals(2, cntr.get());
r.remove(info);
Assert.assertTrue(cntr.get() == 2);
Assertions.assertEquals(2, cntr.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
*/
package org.apache.ratis.metrics.dropwizard3;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collection;
import java.util.Set;

import org.apache.ratis.thirdparty.com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestRefCountingMap {

private RefCountingMap<String, String> map;

@Before
@BeforeEach
public void setUp() {
map = new RefCountingMap<>();
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testKeySet() {
Set<String> keys = map.keySet();
assertEquals(3, keys.size());

Lists.newArrayList("foo", "bar", "baz").stream().forEach(v -> assertTrue(keys.contains(v)));
Lists.newArrayList("foo", "bar", "baz").forEach(v -> assertTrue(keys.contains(v)));
}

@Test
Expand All @@ -141,7 +141,7 @@ public void testValues() {
Collection<String> values = map.values();
assertEquals(3, values.size());

Lists.newArrayList("foovalue", "foovalue3", "foovalue4").stream()
Lists.newArrayList("foovalue", "foovalue3", "foovalue4")
.forEach(v -> assertTrue(values.contains(v)));
}
}

0 comments on commit 016018f

Please sign in to comment.