forked from allegro/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allegro#1748 Test for monitoring of the executors with Micrometer
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...o/tech/hermes/common/metric/executor/InstrumentedExecutorServiceFactoryMetricsTest.groovy
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,70 @@ | ||
package pl.allegro.tech.hermes.common.metric.executor | ||
|
||
import com.codahale.metrics.MetricRegistry | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.micrometer.core.instrument.search.Search | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import pl.allegro.tech.hermes.common.metric.HermesMetrics | ||
import pl.allegro.tech.hermes.common.metric.MetricsFacade | ||
import pl.allegro.tech.hermes.metrics.PathsCompiler | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Future | ||
import java.util.concurrent.ScheduledExecutorService | ||
import java.util.concurrent.ScheduledFuture | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS | ||
|
||
class InstrumentedExecutorServiceFactoryMetricsTest extends Specification { | ||
|
||
private final MeterRegistry meterRegistry = new SimpleMeterRegistry() | ||
|
||
@Subject | ||
private final InstrumentedExecutorServiceFactory factory = | ||
new InstrumentedExecutorServiceFactory( | ||
new MetricsFacade( | ||
meterRegistry, | ||
new HermesMetrics(new MetricRegistry(), new PathsCompiler("host")) | ||
) | ||
) | ||
|
||
def "should record metrics for executor service (monitoring enabled: #monitoringEnabled)"() { | ||
given: | ||
ExecutorService executor = factory.getExecutorService("test-executor", 10, monitoringEnabled) | ||
when: | ||
Future<?> task = executor.submit { println("task executed") } | ||
task.get() | ||
then: | ||
metric("executor.completed", "test-executor").functionCounter()?.count() == expectedCompletedCount | ||
where: | ||
monitoringEnabled || expectedCompletedCount | ||
true || 1.0d | ||
false || null | ||
} | ||
def "should record metrics for scheduled executor service (monitoring enabled: #monitoringEnabled)"() { | ||
given: | ||
ScheduledExecutorService executor = factory.getScheduledExecutorService("test-scheduled-executor", 10, monitoringEnabled) | ||
when: | ||
ScheduledFuture<?> task = executor.schedule({ println("scheduled task executed") }, 1, SECONDS) | ||
task.get() | ||
then: | ||
metric("executor.completed", "test-scheduled-executor").functionCounter()?.count() == expectedCompletedCount | ||
where: | ||
monitoringEnabled || expectedCompletedCount | ||
true || 1.0d | ||
false || null | ||
} | ||
private Search metric(String name, String executorName) { | ||
return meterRegistry.find(name).tag("name", executorName) | ||
} | ||
} |