-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
282 additions
and
15 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
24 changes: 24 additions & 0 deletions
24
...-async/src/test/groovy/com/raynigon/ecs/logging/async/FallbackMetricsServiceITSpec.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,24 @@ | ||
package com.raynigon.ecs.logging.async | ||
|
||
import com.raynigon.ecs.logging.async.helper.MeterRegistryProvider | ||
import com.raynigon.ecs.logging.async.service.AsyncMetricsService | ||
import com.raynigon.ecs.logging.async.service.NoOpMetricsService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.ContextConfiguration | ||
import spock.lang.Specification | ||
|
||
@EnableAutoConfiguration | ||
@ContextConfiguration(classes = [MdcExecutorConfiguration, MeterRegistryProvider]) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = []) | ||
class FallbackMetricsServiceITSpec extends Specification { | ||
|
||
@Autowired | ||
AsyncMetricsService metricsService | ||
|
||
def "test"(){ | ||
expect: | ||
metricsService instanceof NoOpMetricsService | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...sync/src/test/groovy/com/raynigon/ecs/logging/async/MicrometerMetricsServiceITSpec.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,24 @@ | ||
package com.raynigon.ecs.logging.async | ||
|
||
import com.raynigon.ecs.logging.async.helper.MeterRegistryProvider | ||
import com.raynigon.ecs.logging.async.service.AsyncMetricsService | ||
import com.raynigon.ecs.logging.async.service.MicrometerMetricsService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.ContextConfiguration | ||
import spock.lang.Specification | ||
|
||
@EnableAutoConfiguration | ||
@ContextConfiguration(classes = [MdcExecutorConfiguration, MeterRegistryProvider]) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = ["raynigon.logging.async.metrics.enabled=true"]) | ||
class MicrometerMetricsServiceITSpec extends Specification { | ||
|
||
@Autowired | ||
AsyncMetricsService metricsService | ||
|
||
def "test"() { | ||
expect: | ||
metricsService instanceof MicrometerMetricsService | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...rc/test/groovy/com/raynigon/ecs/logging/async/service/MicrometerMetricsServiceSpec.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,31 @@ | ||
package com.raynigon.ecs.logging.async.service | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
class MicrometerMetricsServiceSpec extends Specification { | ||
|
||
SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry() | ||
|
||
@Subject | ||
MicrometerMetricsService service = new MicrometerMetricsService(meterRegistry) | ||
|
||
def "create queue timer"() { | ||
when: | ||
service.createQueueTimer(String.class).record({ null }) | ||
|
||
then: | ||
meterRegistry.find(MicrometerMetricsService.QUEUE_TIMER_NAME).timer().count() == 1 | ||
meterRegistry.find(MicrometerMetricsService.EXECUTION_TIMER_NAME).timer() == null | ||
} | ||
|
||
def "create execution timer"() { | ||
when: | ||
service.createExecutionTimer(String.class).record({ null }) | ||
|
||
then: | ||
meterRegistry.find(MicrometerMetricsService.QUEUE_TIMER_NAME).timer() == null | ||
meterRegistry.find(MicrometerMetricsService.EXECUTION_TIMER_NAME).timer().count() == 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...sync/src/test/groovy/com/raynigon/ecs/logging/async/service/NoOpMetricsServiceSpec.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,20 @@ | ||
package com.raynigon.ecs.logging.async.service | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
class NoOpMetricsServiceSpec extends Specification { | ||
|
||
@Subject | ||
NoOpMetricsService service = new NoOpMetricsService() | ||
|
||
def "create queue timer"() { | ||
expect: | ||
service.createQueueTimer(String.class) != null | ||
} | ||
|
||
def "create execution timer"() { | ||
expect: | ||
service.createExecutionTimer(String.class) != null | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...src/test/groovy/com/raynigon/ecs/logging/async/service/helper/MicrometerSampleSpec.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,33 @@ | ||
package com.raynigon.ecs.logging.async.service.helper | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import io.micrometer.core.instrument.Timer; | ||
import spock.lang.Specification | ||
|
||
class MicrometerSampleSpec extends Specification { | ||
|
||
def "can be created"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
Timer.Sample sample = Timer.start() | ||
|
||
when: | ||
def result = new MicrometerSample(timer, sample) | ||
|
||
then: | ||
noExceptionThrown() | ||
} | ||
|
||
def "can be stopped"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
Timer.Sample sample = Timer.start() | ||
MicrometerSample wrapper = new MicrometerSample(timer, sample) | ||
|
||
when: | ||
def result = wrapper.stop() | ||
|
||
then: | ||
result > 0 | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../src/test/groovy/com/raynigon/ecs/logging/async/service/helper/MicrometerTimerSpec.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,68 @@ | ||
package com.raynigon.ecs.logging.async.service.helper | ||
|
||
import io.micrometer.core.instrument.Timer | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import spock.lang.Specification | ||
|
||
import java.util.concurrent.Callable | ||
import java.util.function.Supplier | ||
|
||
class MicrometerTimerSpec extends Specification { | ||
|
||
def "supplier gets executed"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
MicrometerTimer wrapper = new MicrometerTimer(timer); | ||
Supplier supplier = Mock() | ||
|
||
when: | ||
wrapper.record(supplier) | ||
|
||
then: | ||
1 * supplier.get() >> null | ||
|
||
and: | ||
timer.count() == 1 | ||
} | ||
|
||
def "callable gets executed"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
MicrometerTimer wrapper = new MicrometerTimer(timer); | ||
Callable callable = Mock() | ||
|
||
when: | ||
wrapper.recordCallable(callable) | ||
|
||
then: | ||
1 * callable.call() >> null | ||
|
||
and: | ||
timer.count() == 1 | ||
} | ||
|
||
def "start created sample"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
MicrometerTimer wrapper = new MicrometerTimer(timer); | ||
|
||
when: | ||
def result = wrapper.start() | ||
|
||
then: | ||
result instanceof MicrometerSample | ||
} | ||
|
||
def "stop returns minus duration"() { | ||
given: | ||
Timer timer = new SimpleMeterRegistry().timer("test") | ||
MicrometerTimer wrapper = new MicrometerTimer(timer); | ||
SampleWrapper sample = wrapper.start() | ||
|
||
when: | ||
def result = wrapper.stop(sample) | ||
|
||
then: | ||
result > 0 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...async/src/test/groovy/com/raynigon/ecs/logging/async/service/helper/NoOpSampleSpec.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,11 @@ | ||
package com.raynigon.ecs.logging.async.service.helper | ||
|
||
import spock.lang.Specification | ||
|
||
class NoOpSampleSpec extends Specification { | ||
|
||
def "can be created"() { | ||
expect: | ||
new NoOpSample() != null | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...-async/src/test/groovy/com/raynigon/ecs/logging/async/service/helper/NoOpTimerSpec.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,44 @@ | ||
package com.raynigon.ecs.logging.async.service.helper | ||
|
||
|
||
import spock.lang.Specification | ||
|
||
import java.util.concurrent.Callable | ||
import java.util.function.Supplier | ||
|
||
class NoOpTimerSpec extends Specification { | ||
|
||
def "supplier gets executed"() { | ||
given: | ||
NoOpTimer wrapper = new NoOpTimer(); | ||
Supplier supplier = Mock() | ||
|
||
when: | ||
wrapper.record(supplier) | ||
|
||
then: | ||
1 * supplier.get() >> null | ||
} | ||
|
||
def "callable gets executed"() { | ||
given: | ||
NoOpTimer wrapper = new NoOpTimer(); | ||
Callable callable = Mock() | ||
|
||
when: | ||
wrapper.recordCallable(callable) | ||
|
||
then: | ||
1 * callable.call() >> null | ||
} | ||
|
||
def "start created sample"() { | ||
expect: | ||
new NoOpTimer().start() instanceof NoOpSample | ||
} | ||
|
||
def "stop returns minus 1"() { | ||
expect: | ||
new NoOpTimer().stop(null) == -1 | ||
} | ||
} |