-
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.
- Loading branch information
1 parent
689652e
commit 1f49e76
Showing
2 changed files
with
41 additions
and
1 deletion.
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
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/org/codefreak/cloud/companion/WebsocketConnectionMetricAdviceTest.kt
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,40 @@ | ||
package org.codefreak.cloud.companion | ||
|
||
import io.micrometer.core.instrument.Gauge | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry | ||
import org.aspectj.lang.ProceedingJoinPoint | ||
import org.hamcrest.CoreMatchers.`is` | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.any | ||
import reactor.core.publisher.Mono | ||
import reactor.test.StepVerifier | ||
|
||
internal class WebsocketConnectionMetricAdviceTest { | ||
|
||
private lateinit var connectionMetricAdvice: WebsocketConnectionMetricAdvice | ||
private lateinit var gauge: Gauge | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
val meterRegistry = SimpleMeterRegistry() | ||
connectionMetricAdvice = WebsocketConnectionMetricAdvice(meterRegistry) | ||
gauge = meterRegistry.get("http.websocket.connections").gauge() | ||
} | ||
|
||
@Test | ||
fun testCountsUpAndDown() { | ||
val pjp = Mockito.mock(ProceedingJoinPoint::class.java) | ||
`when`(pjp.proceed(any())).thenReturn(Mono.just("1")) | ||
val wrappedMono = connectionMetricAdvice.onHandle(pjp) | ||
|
||
assertThat(gauge.value(), `is`(.0)) | ||
StepVerifier.create(wrappedMono) | ||
.assertNext { assertThat(gauge.value(), `is`(1.0)) } | ||
.verifyComplete() | ||
assertThat(gauge.value(), `is`(.0)) | ||
} | ||
} |