-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kenshoo/fix-filter-customization
Integration tests + fixing filter setup
- Loading branch information
Showing
11 changed files
with
223 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ dependencies { | |
|
||
testCompile libraries.junit | ||
testCompile libraries.hamcrestLibrary | ||
testCompile libraries.wiremock | ||
} |
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
75 changes: 75 additions & 0 deletions
75
...porter2/src/test/java/com/kenshoo/metrics/anodot/metrics2/Anodot2ReporterBuilderTest.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,75 @@ | ||
package com.kenshoo.metrics.anodot.metrics2; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import com.kenshoo.metrics.anodot.AnodotReporterConfiguration; | ||
import com.kenshoo.metrics.anodot.AnodotReporterWrapper; | ||
import com.kenshoo.metrics.anodot.DefaultAnodotReporterConfiguration; | ||
import com.yammer.metrics.Metrics; | ||
import com.yammer.metrics.core.AnodotMetricFilter; | ||
import com.yammer.metrics.core.Metric; | ||
import com.yammer.metrics.core.spec.MetricName; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
|
||
/** | ||
* Created by tzachz on 4/24/17 | ||
*/ | ||
public class Anodot2ReporterBuilderTest { | ||
|
||
private final AnodotReporterConfiguration conf = new DefaultAnodotReporterConfiguration("t", 1, "http://localhost:8080/anodot"); | ||
|
||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(8080); | ||
|
||
@Test | ||
public void zeroesNotReportedByDefault() throws Exception { | ||
Metrics.newCounter(this.getClass(), "counter3333"); // create zero counter | ||
final AnodotReporterWrapper reporter = Anodot2ReporterBuilder.builderFor(conf).build(Metrics.defaultRegistry()); | ||
runReportCycle(reporter); | ||
verify(exactly(0), postRequestedFor(urlEqualTo("/anodot?token=t")).withRequestBody(containing("counter3333"))); | ||
} | ||
|
||
@Test | ||
public void zeroFilterTurnedOffMeansNoFilters() throws Exception { | ||
Metrics.newCounter(this.getClass(), "counter"); // create zero counter | ||
final AnodotReporterWrapper reporter = Anodot2ReporterBuilder.builderFor(conf).turnZeroFilterOff().build(Metrics.defaultRegistry()); | ||
runReportCycle(reporter); | ||
verify(postRequestedFor(urlEqualTo("/anodot?token=t"))); | ||
} | ||
|
||
@Test | ||
public void mustPassAllFilters() throws Exception { | ||
Metrics.newCounter(this.getClass(), "counter1111").inc(); | ||
Metrics.newCounter(this.getClass(), "counter2222").inc(); | ||
Metrics.newCounter(this.getClass(), "meter1111").inc(); | ||
|
||
final AnodotReporterWrapper reporter = Anodot2ReporterBuilder.builderFor(conf) | ||
.addFilter(whatPropertyContains("count")) // both counters pass this one | ||
.addFilter(whatPropertyContains("1111")) // but only the first passes this one | ||
.build(Metrics.defaultRegistry()); | ||
|
||
runReportCycle(reporter); | ||
verify(postRequestedFor(urlEqualTo("/anodot?token=t")) | ||
.withRequestBody(containing("counter1111")) | ||
.withRequestBody(notMatching(".*counter2222.*")) | ||
.withRequestBody(notMatching(".*meter1111.*")) | ||
); | ||
} | ||
|
||
private AnodotMetricFilter whatPropertyContains(final String substring) { | ||
return new AnodotMetricFilter() { | ||
@Override | ||
public boolean matches(MetricName metricName, Metric metric) { | ||
return metricName.getProperty("what").getValue().contains(substring); | ||
} | ||
}; | ||
} | ||
|
||
private void runReportCycle(AnodotReporterWrapper reporter) throws InterruptedException { | ||
reporter.start(); | ||
Thread.sleep(1300); | ||
reporter.stop(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ dependencies { | |
|
||
testCompile libraries.junit | ||
testCompile libraries.hamcrestLibrary | ||
testCompile libraries.wiremock | ||
} |
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
78 changes: 78 additions & 0 deletions
78
...porter3/src/test/java/com/kenshoo/metrics/anodot/metrics3/Anodot3ReporterBuilderTest.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,78 @@ | ||
package com.kenshoo.metrics.anodot.metrics3; | ||
|
||
import com.anodot.metrics.AnodotMetricFilter; | ||
import com.anodot.metrics.spec.MetricName; | ||
import com.codahale.metrics.Metric; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import com.kenshoo.metrics.anodot.AnodotReporterConfiguration; | ||
import com.kenshoo.metrics.anodot.AnodotReporterWrapper; | ||
import com.kenshoo.metrics.anodot.DefaultAnodotReporterConfiguration; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
|
||
/** | ||
* Created by tzachz on 4/24/17 | ||
*/ | ||
public class Anodot3ReporterBuilderTest { | ||
|
||
private final AnodotReporterConfiguration conf = new DefaultAnodotReporterConfiguration("t", 1, "http://localhost:8080/anodot"); | ||
|
||
private final MetricRegistry registry = new MetricRegistry(); | ||
|
||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(8080); | ||
|
||
@Test | ||
public void zeroesNotReportedByDefault() throws Exception { | ||
registry.counter("counter"); // create zero counter | ||
final AnodotReporterWrapper reporter = Anodot3ReporterBuilder.builderFor(conf).build(registry); | ||
runReportCycle(reporter); | ||
verify(exactly(0), postRequestedFor(urlEqualTo("/anodot?token=t"))); | ||
} | ||
|
||
@Test | ||
public void zeroFilterTurnedOffMeansNoFilters() throws Exception { | ||
registry.counter("counter"); // create zero counter | ||
final AnodotReporterWrapper reporter = Anodot3ReporterBuilder.builderFor(conf).turnZeroFilterOff().build(registry); | ||
runReportCycle(reporter); | ||
verify(postRequestedFor(urlEqualTo("/anodot?token=t"))); | ||
} | ||
|
||
@Test | ||
public void mustPassAllFilters() throws Exception { | ||
registry.counter("counter1111").inc(); | ||
registry.counter("counter2222").inc(); | ||
registry.counter("meter1111").inc(); | ||
|
||
final AnodotReporterWrapper reporter = Anodot3ReporterBuilder.builderFor(conf) | ||
.addFilter(whatPropertyContains("count")) // both counters pass this one | ||
.addFilter(whatPropertyContains("1111")) // but only the first passes this one | ||
.build(registry); | ||
|
||
runReportCycle(reporter); | ||
verify(postRequestedFor(urlEqualTo("/anodot?token=t")) | ||
.withRequestBody(containing("counter1111")) | ||
.withRequestBody(notMatching(".*counter2222.*")) | ||
.withRequestBody(notMatching(".*meter1111.*")) | ||
); | ||
} | ||
|
||
private AnodotMetricFilter whatPropertyContains(final String substring) { | ||
return new AnodotMetricFilter() { | ||
@Override | ||
public boolean matches(MetricName metricName, Metric metric) { | ||
return metricName.getProperty("what").getValue().contains(substring); | ||
} | ||
}; | ||
} | ||
|
||
private void runReportCycle(AnodotReporterWrapper reporter) throws InterruptedException { | ||
reporter.start(); | ||
Thread.sleep(1500); | ||
reporter.stop(); | ||
} | ||
|
||
} |
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