Skip to content

Commit

Permalink
Merge pull request #62 from camunda-community-hub/zell-eze-close-client
Browse files Browse the repository at this point in the history
Close client in test and extension
  • Loading branch information
ChrisKujawa authored Nov 19, 2021
2 parents 946900f + 38ef902 commit 76d6667
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
40 changes: 21 additions & 19 deletions eze/src/test/kotlin/org/camunda/community/eze/EngineClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import java.time.Duration
class EngineClientTest {

private lateinit var zeebeEngine: ZeebeEngine
private lateinit var zeebeClient: ZeebeClient

@BeforeEach
fun `setup grpc server`() {
Expand All @@ -48,12 +49,13 @@ class EngineClientTest {
@AfterEach
fun `tear down`() {
zeebeEngine.stop()
zeebeClient.close()
}

@Test
fun `should request topology`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

// when
val topology = zeebeClient
Expand Down Expand Up @@ -84,7 +86,7 @@ class EngineClientTest {
@Test
fun `should use built in client`() {
// given
val zeebeClient = zeebeEngine.createClient()
zeebeClient = zeebeEngine.createClient()

// when
val topology = zeebeClient
Expand All @@ -99,7 +101,7 @@ class EngineClientTest {
@Test
fun `should use gateway address to build client`() {
// given
val zeebeClient = ZeebeClient
zeebeClient = ZeebeClient
.newClientBuilder()
.usePlaintext()
.gatewayAddress(zeebeEngine.getGatewayAddress())
Expand All @@ -119,7 +121,7 @@ class EngineClientTest {
@Test
fun `should publish message`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

zeebeClient.newDeployCommand()
.addProcessModel(Bpmn.createExecutableProcess("process")
Expand Down Expand Up @@ -155,7 +157,7 @@ class EngineClientTest {
@Test
fun `should deploy process`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

// when
val deployment = zeebeClient
Expand Down Expand Up @@ -185,7 +187,7 @@ class EngineClientTest {
@Test
fun `should create instance without variables`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
val deployment = zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -214,7 +216,7 @@ class EngineClientTest {
@Test
fun `should reject command`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

// when
val future = zeebeClient.newCreateInstanceCommand()
Expand All @@ -231,7 +233,7 @@ class EngineClientTest {
@Test
fun `should create process instance`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
val deployment = zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -261,7 +263,7 @@ class EngineClientTest {
@Test
fun `should cancel process instance`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -301,7 +303,7 @@ class EngineClientTest {
@Test
fun `should update variables on process instance`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -337,7 +339,7 @@ class EngineClientTest {
@Test
fun `should create process instance with result`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

val deployment = zeebeClient
.newDeployCommand()
Expand Down Expand Up @@ -371,7 +373,7 @@ class EngineClientTest {
@Test
fun `should activate job`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
val deployment = zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -419,7 +421,7 @@ class EngineClientTest {
@Test
fun `should complete job`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

zeebeClient
.newDeployCommand()
Expand Down Expand Up @@ -458,7 +460,7 @@ class EngineClientTest {
@Test
fun `should fail job`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -515,7 +517,7 @@ class EngineClientTest {
@Test
fun `should throw error on job`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -575,7 +577,7 @@ class EngineClientTest {
@Test
fun `should update retries on job`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient
.newDeployCommand()
.addProcessModel(
Expand Down Expand Up @@ -631,7 +633,7 @@ class EngineClientTest {
@Test
fun `should read process instance records`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

zeebeClient
.newDeployCommand()
Expand Down Expand Up @@ -682,7 +684,7 @@ class EngineClientTest {
@Test
fun `should print records`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

zeebeClient
.newDeployCommand()
Expand Down Expand Up @@ -720,7 +722,7 @@ class EngineClientTest {
@Test
fun `should increase the time`() {
// given
val zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()
zeebeClient = ZeebeClient.newClientBuilder().usePlaintext().build()

zeebeClient
.newDeployCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EzeExtension : BeforeEachCallback, TestWatcher {
private fun injectFields(context: ExtensionContext, testInstance: Any, testClass: Class<*>) {
mapOf(
ZeebeEngine::class to EzeExtensionState::zeebe,
ZeebeClient::class to { it.zeebe.createClient() },
ZeebeClient::class to { it.zeebeClient },
ZeebeEngineClock::class to { it.zeebe.clock() },
RecordStreamSource::class to EzeExtensionState::zeebe
).forEach { (fieldType, fieldValue) ->
Expand Down Expand Up @@ -85,13 +85,15 @@ class EzeExtension : BeforeEachCallback, TestWatcher {
}

class EzeExtensionState(val zeebe: ZeebeEngine) : CloseableResource {
internal var zeebeClient: ZeebeClient;
init {
zeebe.start()
zeebeClient = zeebe.createClient()
}

override fun close() {
zeebeClient.close()
zeebe.stop()
}
}

}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.version.surefire}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>

<!-- flaky test extractor plugin -->
Expand Down

0 comments on commit 76d6667

Please sign in to comment.