Skip to content

Commit

Permalink
W-16554282: JUnit 5 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzxu-crm committed Aug 22, 2024
1 parent 1f647bb commit 6bef019
Show file tree
Hide file tree
Showing 67 changed files with 710 additions and 891 deletions.
2 changes: 1 addition & 1 deletion carbonj.service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ dependencies {
implementation "org.eclipse.jetty:jetty-server:${jettyServer}"

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: "${junit}"
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: "${hamcrest}"

implementation (group:"org.springframework.boot", name:"spring-boot-starter-logging", version: "${springbootVersion}") {
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
Expand All @@ -218,6 +217,7 @@ dependencies {
}

test {
useJUnitPlatform()
maxHeapSize = "2g"
jvmArgs = [
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/
package com.demandware.carbonj.service.accumulator;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(JUnit4.class)
public class TestDefaultSlotStrategy {

@Test
Expand All @@ -27,12 +25,12 @@ public void testSlotStrategy() {
}

private void verify(SlotStrategy slotStrategy, int metricTs, int expectedSlotTs, int expectedSlotStartTs, int expectedSlotEndTs) {
Assert.assertEquals(expectedSlotTs, slotStrategy.getSlotTs(metricTs));
Assert.assertEquals(expectedSlotStartTs, slotStrategy.getStartTs(metricTs));
Assert.assertEquals(expectedSlotEndTs, slotStrategy.getEndTs(metricTs));
assertEquals(expectedSlotTs, slotStrategy.getSlotTs(metricTs));
assertEquals(expectedSlotStartTs, slotStrategy.getStartTs(metricTs));
assertEquals(expectedSlotEndTs, slotStrategy.getEndTs(metricTs));
}

private void verify(SlotStrategy slotStrategy, int metricTs, int expectedSlotTs) {
Assert.assertEquals(expectedSlotTs, slotStrategy.getSlotTs(metricTs));
assertEquals(expectedSlotTs, slotStrategy.getSlotTs(metricTs));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

import com.demandware.carbonj.service.db.util.time.TimeSource;
import com.demandware.carbonj.service.engine.DataPoint;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

import java.util.Map;

@RunWith(JUnit4.class)
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestLatencyAggregation {

@Test
Expand All @@ -28,10 +26,10 @@ public void testLatencyAggregation() {
la.add(new DataPoint("metric4", 2, time), time + 3);
la.add(new DataPoint("metric5", 2, time), time + 4);
Map<String, Double> aggTypeToValues = la.getValues();
Assert.assertEquals(4, aggTypeToValues.size());
Assert.assertEquals(0, aggTypeToValues.get("min").intValue());
Assert.assertEquals(4, aggTypeToValues.get("max").intValue());
Assert.assertEquals(5, aggTypeToValues.get("count").intValue());
Assert.assertEquals(2, aggTypeToValues.get("mean").intValue());
assertEquals(4, aggTypeToValues.size());
assertEquals(0, aggTypeToValues.get("min").intValue());
assertEquals(4, aggTypeToValues.get("max").intValue());
assertEquals(5, aggTypeToValues.get("count").intValue());
assertEquals(2, aggTypeToValues.get("mean").intValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import static com.demandware.carbonj.service.accumulator.MetricAggregationMethod.LATENCY;
import static com.demandware.carbonj.service.accumulator.MetricAggregationMethod.SUM;
import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.demandware.carbonj.service.accumulator.MetricAggregationRule.Result;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class _MetricAggregationRule
{
Expand All @@ -24,7 +23,7 @@ public class _MetricAggregationRule
private MetricAggregationRule ecom_agRequest_new_Rule;


@Before
@BeforeEach
public void setUp()
{
ecom_agRule = MetricAggregationRule.parseDefinition( "<pod>.ecom_ag.<realm>.<tenant>.<metric> (60) = sum <pod>.ecom.<realm>.<tenant>.*.*.<<metric>>", 0, true );
Expand Down Expand Up @@ -56,6 +55,7 @@ public void shouldApply_ecom_ag_request_new_rule()
assertEquals( ecom_agRequest_new_Rule.apply( name1 ), expected1 );
assertEquals( ecom_agRequest_new_Rule.apply( name2 ), expected2 );
}

@Test
public void shouldApply_ecom_ag_rule()
{
Expand Down Expand Up @@ -97,5 +97,4 @@ public void noMatchWhenDifferentPos()
Result expected = new Result(null, null, false );
assertEquals( ocapiRule.apply( name ), expected );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@

import static com.demandware.carbonj.service.accumulator.MetricAggregationMethod.SUM;
import static com.demandware.carbonj.service.accumulator.MetricAggregationMethod.AVG;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.demandware.carbonj.service.accumulator.MetricAggregationRule.Result;
import com.demandware.carbonj.service.util.TestFileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class _MetricAggregationRules
{
Expand All @@ -28,7 +27,7 @@ public class _MetricAggregationRules
MetricAggregationRules rules;


@Before
@BeforeEach
public void setUp()
throws Exception
{
Expand Down Expand Up @@ -100,5 +99,4 @@ public void matchOnOnlyOneFromMultipleRules()
List<Result> expected = List.of(new Result("pi.response.count", AVG, true));
assertEquals( rules.apply( name ), expected );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@
package com.demandware.carbonj.service.accumulator.recovery;

import com.demandware.carbonj.service.BaseTest;
import com.demandware.carbonj.service.accumulator.*;
import com.demandware.carbonj.service.accumulator.DefaultSlotStrategy;
import com.demandware.carbonj.service.accumulator.LatePointLogger;
import com.demandware.carbonj.service.accumulator.MetricAggregate;
import com.demandware.carbonj.service.accumulator.MetricAggregationMethod;
import com.demandware.carbonj.service.accumulator.MetricAggregationPolicy;
import com.demandware.carbonj.service.accumulator.MetricAggregationPolicyProvider;
import com.demandware.carbonj.service.engine.DataPoint;
import com.demandware.carbonj.service.engine.DataPoints;
import com.demandware.carbonj.service.ns.NamespaceCounter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(JUnit4.class)
public class TestRecoveryAccumulator extends BaseTest {

private AtomicInteger flushedPoints;
private AtomicInteger latePoints;

@Before
@BeforeEach
public void setUp() {
flushedPoints = new AtomicInteger(0);
latePoints = new AtomicInteger(0);
Expand Down Expand Up @@ -65,14 +67,14 @@ public void testAllRecoveryPoints() {
// should be flushed forcefully.

accumulator.rollUp(this::incrementFlushPoints, toMillis(946), false);
Assert.assertEquals(2, flushedPoints.get());
assertEquals(2, flushedPoints.get());

accumulator.rollUp(this::incrementFlushPoints, toMillis(1100), true);
Assert.assertEquals(4, flushedPoints.get());
assertEquals(4, flushedPoints.get());

Assert.assertEquals(0, accumulator.getTimeSlots().size());
assertEquals(0, accumulator.getTimeSlots().size());

Assert.assertEquals(4, latePoints.get());
assertEquals(4, latePoints.get());
}

private long toMillis(int sec) {
Expand All @@ -88,10 +90,10 @@ private void addAndVerify(RecoveryAccumulator accumulator, int timeInSecs, long
int expectedSlotsAfterFlush, int expectedTotalFlushedSoFar) {
accumulator.add(new DataPoint("metric1", 1, timeInSecs));
accumulator.add(new DataPoint("metric2", 1, timeInSecs));
Assert.assertEquals(expectedSlotsBeforeFlush, accumulator.getTimeSlots().size());
assertEquals(expectedSlotsBeforeFlush, accumulator.getTimeSlots().size());
accumulator.rollUp(this::incrementFlushPoints, currentTimeInMillis, false);
Assert.assertEquals(expectedTotalFlushedSoFar, flushedPoints.get());
Assert.assertEquals(expectedSlotsAfterFlush, accumulator.getTimeSlots().size());
assertEquals(expectedTotalFlushedSoFar, flushedPoints.get());
assertEquals(expectedSlotsAfterFlush, accumulator.getTimeSlots().size());
// Assert.assertEquals(expectedMaxClosedTs, accumulator.getMaxClosedSlotTs());
}

Expand All @@ -113,11 +115,11 @@ public void testLatePoints() {
accumulator.add(getDataPoint(40));
accumulator.add(getDataPoint(120));
accumulator.add(getDataPoint(180));
Assert.assertEquals(0, latePoints.get());
assertEquals(0, latePoints.get());
accumulator.add(getDataPoint(20));
Assert.assertEquals(1, latePoints.get());
assertEquals(1, latePoints.get());
accumulator.add(getDataPoint(130));
Assert.assertEquals(1, latePoints.get());
assertEquals(1, latePoints.get());
}

private DataPoint getDataPoint(int ts) {
Expand All @@ -126,7 +128,7 @@ private DataPoint getDataPoint(int ts) {

private static class CountingLatePointLogger implements LatePointLogger {

private AtomicInteger latePoints;
private final AtomicInteger latePoints;

private CountingLatePointLogger(AtomicInteger latePoints) {
this.latePoints = latePoints;
Expand All @@ -137,4 +139,4 @@ public void logLatePoint(DataPoint m, long now, Reason r, String context) {
latePoints.incrementAndGet();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@
package com.demandware.carbonj.service.admin;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;
import java.util.List;

import com.demandware.carbonj.service.db.model.DataPointValue;
import com.demandware.carbonj.service.engine.DataPoint;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class _DumpFormat
{
@Test
public void writeSeries()
{
Assert.assertEquals( "abc|100|1|2",
DumpFormat.writeSeries( "abc", 1, Arrays.asList( new DataPointValue( 100, 2.0f ) ) ) );
Assert.assertEquals( "abc|100|1|2.35",
DumpFormat.writeSeries( "abc", 1, Arrays.asList( new DataPointValue( 100, 2.351f ) ) ) );
Assert.assertEquals(
assertEquals( "abc|100|1|2",
DumpFormat.writeSeries( "abc", 1, List.of(new DataPointValue(100, 2.0f))) );
assertEquals( "abc|100|1|2.35",
DumpFormat.writeSeries( "abc", 1, List.of(new DataPointValue(100, 2.351f))) );
assertEquals(
"abc|100|1|2.3,2.4",
DumpFormat.writeSeries( "abc", 1,
Arrays.asList( new DataPointValue( 100, 2.3f ), new DataPointValue( 101, 2.4f ) ) ) );
Assert.assertEquals( "abc|100|1|2.3,2:2.4,3", DumpFormat.writeSeries( "abc", 1, Arrays.asList(
assertEquals( "abc|100|1|2.3,2:2.4,3", DumpFormat.writeSeries( "abc", 1, Arrays.asList(
new DataPointValue( 100, 2.3f ), new DataPointValue( 102, 2.4f ), new DataPointValue( 103, 3f ) ) ) );
}

@Test
public void parseSeries()
{
Assert.assertEquals( Arrays.asList( new DataPoint( "abc", 2, 100 ) ), DumpFormat.parseSeries( "abc|100|1|2" ) );
Assert.assertEquals( Arrays.asList( new DataPoint( "abc", 2.35, 100 ) ),
assertEquals(List.of(new DataPoint("abc", 2, 100)), DumpFormat.parseSeries( "abc|100|1|2" ) );
assertEquals(List.of(new DataPoint("abc", 2.35, 100)),
DumpFormat.parseSeries( "abc|100|1|2.35" ) );
Assert.assertEquals( Arrays.asList( new DataPoint( "abc", 2.3, 100 ), new DataPoint( "abc", 2.4, 101 ) ),
assertEquals( Arrays.asList( new DataPoint( "abc", 2.3, 100 ), new DataPoint( "abc", 2.4, 101 ) ),
DumpFormat.parseSeries( "abc|100|1|2.3,2.4" ) );
Assert.assertEquals( Arrays.asList( new DataPoint( "abc", 2.3, 100 ), new DataPoint( "abc", 2.4, 102 ),
assertEquals( Arrays.asList( new DataPoint( "abc", 2.3, 100 ), new DataPoint( "abc", 2.4, 102 ),
new DataPoint( "abc", 3, 103 ) ), DumpFormat.parseSeries( "abc|100|1|2.3,2:2.4,3" ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import com.demandware.carbonj.service.engine.Query;
import com.demandware.carbonj.service.events.NoOpLogger;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.time.Clock;
import java.util.ArrayList;
import java.util.List;

@RunWith(JUnit4.class)
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class Test60s30dTimeSeries extends BaseTest {

private static final boolean longId = true;
Expand All @@ -39,7 +38,7 @@ public class Test60s30dTimeSeries extends BaseTest {
public void test60s30dTimeSeries() throws Exception {
long currentTime = Clock.systemUTC().millis();
File dbDirFile = new File("/tmp/" + currentTime);
Assert.assertTrue(dbDirFile.mkdirs());
assertTrue(dbDirFile.mkdirs());
File metricStoreConfFile = new File(dbDirFile, "metric-store.conf");
List<String> metricStoreConfigs = new ArrayList<>();
metricStoreConfigs.add("metrics.store.retentions=60s:30d");
Expand All @@ -65,20 +64,20 @@ dataPointStore, new DatabaseMetrics(metricRegistry), false,
points.add(new DataPoint("a.b.c", 123, (int)(currentTime / 1000)));
timeSeriesStore.accept(new DataPoints(points));
Metric metric = timeSeriesStore.getMetric("a.b.c");
Assert.assertEquals(2, metric.id);
Assert.assertEquals(1, metric.getRetentionPolicies().size());
Assert.assertTrue(metric.getRetentionPolicies().get(0).is60s30d());
Assert.assertTrue(new File(dbDirFile, "60s30d").exists());
Assert.assertTrue(new File(new File(dbDirFile, "60s30d"), "LOG").exists());
assertEquals(2, metric.id);
assertEquals(1, metric.getRetentionPolicies().size());
assertTrue(metric.getRetentionPolicies().get(0).is60s30d());
assertTrue(new File(dbDirFile, "60s30d").exists());
assertTrue(new File(new File(dbDirFile, "60s30d"), "LOG").exists());
long now = Clock.systemUTC().millis();
List<Series> series = timeSeriesStore.fetchSeriesData(new Query("a.b.c", (int)(currentTime / 1000),
(int)(currentTime / 1000) + 10, (int)(now / 1000), now));
Assert.assertEquals(1, series.size());
Assert.assertEquals("a.b.c", series.get(0).name);
Assert.assertEquals(60, series.get(0).step);
assertEquals(1, series.size());
assertEquals("a.b.c", series.get(0).name);
assertEquals(60, series.get(0).step);
// This could be a query boundary issue
Assert.assertTrue(series.get(0).values.size() == 1 || series.get(0).values.size() == 2);
Assert.assertEquals(123, series.get(0).values.get(0).intValue());
assertTrue(series.get(0).values.size() == 1 || series.get(0).values.size() == 2);
assertEquals(123, series.get(0).values.get(0).intValue());

dataPointStore.close();
metricIndex.close();
Expand Down
Loading

0 comments on commit 6bef019

Please sign in to comment.