-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W-17464266: Add unit tests to bump up coverage over 70%
- Loading branch information
1 parent
61c1db7
commit befdb02
Showing
63 changed files
with
2,063 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ice/src/test/java/com/demandware/carbonj/service/accumulator/CountingLatePointLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import com.demandware.carbonj.service.engine.DataPoint; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class CountingLatePointLogger implements LatePointLogger { | ||
|
||
private final AtomicInteger latePoints; | ||
|
||
public CountingLatePointLogger(AtomicInteger latePoints) { | ||
this.latePoints = latePoints; | ||
} | ||
|
||
@Override | ||
public void logLatePoint(DataPoint m, long now, Reason r, String context) { | ||
latePoints.incrementAndGet(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...rvice/src/test/java/com/demandware/carbonj/service/accumulator/TestAggregateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class TestAggregateFunction { | ||
@Test | ||
public void testAggregateFunction() { | ||
AggregateFunction aggregateFunction = AggregateFunction.create("foo.bar.p95", MetricAggregationMethod.CUSTOM1); | ||
assertInstanceOf(AggregateFunction.AvgAggregateFunction.class, aggregateFunction); | ||
assertEquals(0, aggregateFunction.apply()); | ||
try { | ||
aggregateFunction.getValues(); | ||
fail("Should have thrown an exception"); | ||
} catch (UnsupportedOperationException e) { | ||
} | ||
aggregateFunction = AggregateFunction.create("foo.bar.latency", MetricAggregationMethod.LATENCY); | ||
assertInstanceOf(AggregateFunction.LatencyAggregateFunction.class, aggregateFunction); | ||
assertEquals(0, aggregateFunction.apply()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ice/src/test/java/com/demandware/carbonj/service/accumulator/TestLatePointLoggerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.demandware.carbonj.service.engine.DataPoint; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestLatePointLoggerImpl { | ||
@Test | ||
public void test() { | ||
MetricRegistry metricRegistry = new MetricRegistry(); | ||
LatePointLoggerImpl latePointLogger = new LatePointLoggerImpl(metricRegistry); | ||
latePointLogger.logLatePoint(new DataPoint("foo.bar", 123, 60), 120, LatePointLogger.Reason.SLOT_CLOSED, "Context"); | ||
assertEquals(1, metricRegistry.getCounters().get("aggregator.skippedDelayed").getCount()); | ||
assertEquals(60, metricRegistry.getHistograms().get("aggregator.pointAgeHistogram").getSnapshot().get95thPercentile()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...e/src/test/java/com/demandware/carbonj/service/accumulator/TestMetricAggregationRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TestMetricAggregationRule { | ||
@Test | ||
public void test() { | ||
String aggregationRule = "ocapi.<realm>.<tenant>.<metric> (60) c = custom1 pod[0-9]{3,6}.ecom.<realm>.<tenant>.*.*.ocapi.clients.*.<<metric>>"; | ||
MetricAggregationRule metricAggregationRule = MetricAggregationRule.parseDefinition(aggregationRule, 1, false); | ||
assertFalse(metricAggregationRule.isStopRule()); | ||
assertEquals(MetricAggregationMethod.CUSTOM1, metricAggregationRule.getMethod()); | ||
assertTrue(metricAggregationRule.equals(metricAggregationRule)); | ||
assertFalse(metricAggregationRule.equals(new Object())); | ||
assertTrue(metricAggregationRule.hashCode() > 0); | ||
assertEquals(String.format("com.demandware.carbonj.service.accumulator.MetricAggregationRule@%x", System.identityHashCode(metricAggregationRule)), metricAggregationRule.toString()); | ||
assertFalse(metricAggregationRule.equals(MetricAggregationRule.parseDefinition( | ||
"ocapi.<realm>.<tenant>.<metric> (60) c = sum pod[0-9]{3,6}.ecom.<realm>.<tenant>.*.*.ocapi.clients.*.<<metric>>", 1, false))); | ||
MetricAggregationRule.Result result = metricAggregationRule.apply("pod807.ecom.bgzz.bgzz_prd.blade_1.bgzz_prd.ocapi.clients.client.foo.bar"); | ||
assertTrue(result.equals(result)); | ||
assertFalse(result.equals(null)); | ||
assertNotEquals(0, result.hashCode()); | ||
assertEquals("Result{aggregateName=ocapi.bgzz.bgzz_prd.foo.bar, method=CUSTOM1, dropOriginal=false}", result.toString()); | ||
assertFalse(result.equals(metricAggregationRule.apply("pod807.ecom.bgzz.bgzz_prd.blade_1.bgzz_prd.ocapi.clients.client.foo.bar2"))); | ||
|
||
String aggregationRule2 = "ocapi.<realm>.<tenant>.<metric> (60) cc = custom1 pod[0-9]{3,6}.ecom.<realm>.<tenant>.*.*.ocapi.clients.*.<<metric>>"; | ||
try { | ||
MetricAggregationRule.parseDefinition(aggregationRule2, 2, false); | ||
fail("Should have thrown an exception"); | ||
} catch (RuntimeException e) { | ||
assertEquals("Unsupported flag: [cc]", e.getMessage()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../src/test/java/com/demandware/carbonj/service/accumulator/TestMetricAggregationRules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class TestMetricAggregationRules { | ||
@Test | ||
public void test() { | ||
MetricAggregationRules metricAggregationRules = new MetricAggregationRules(1, new ArrayList<>()); | ||
assertTrue(metricAggregationRules.isEmpty()); | ||
assertEquals("MetricAggregationRules{revision=1, rules=[]}", metricAggregationRules.toString()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
carbonj.service/src/test/java/com/demandware/carbonj/service/accumulator/TestSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.demandware.carbonj.service.accumulator; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.Timer; | ||
import com.demandware.carbonj.service.engine.DataPoint; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestSlot { | ||
@Test | ||
public void testSlot() { | ||
MetricRegistry metricRegistry = new MetricRegistry(); | ||
Timer aggregatorFlushTimer = metricRegistry.timer(MetricRegistry.name("aggregator", "slotFlushTimer")); | ||
Meter flushedAggregates = metricRegistry.meter(MetricRegistry.name("aggregator", "aggregates")); | ||
Meter createdSlots = metricRegistry.meter(MetricRegistry.name("aggregator", "slotCreated")); | ||
AtomicInteger counter = new AtomicInteger(); | ||
Slot slot = new Slot(60, new CountingLatePointLogger(counter), 1, aggregatorFlushTimer, flushedAggregates, createdSlots); | ||
MetricAggregate metricAggregate = new MetricAggregate("foo.bar.aggregated", MetricAggregationMethod.LATENCY, false); | ||
slot.apply(metricAggregate, new DataPoint("foo.bar", 123, 90, false), 90); | ||
assertEquals(1, slot.size()); | ||
assertEquals(60, slot.getTs()); | ||
slot.close(dataPoints -> {System.out.println(dataPoints.get(0));}); | ||
assertEquals(4, flushedAggregates.getCount()); | ||
assertEquals(0, counter.get()); | ||
slot.apply(metricAggregate, new DataPoint("foo.bar", 123, 90, false), 90); | ||
assertEquals(1, counter.get()); | ||
} | ||
} |
Oops, something went wrong.