Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get current engine time #159

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
package org.camunda.community.eze

import java.time.Duration
import java.time.Instant

interface ZeebeEngineClock {
fun increaseTime(timeToAdd: Duration)

fun getCurrentTime(): Instant
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ package org.camunda.community.eze

import io.camunda.zeebe.util.sched.clock.ControlledActorClock
import java.time.Duration
import java.time.Instant

class ZeebeEngineClockImpl(val clock: ControlledActorClock) : ZeebeEngineClock {

override fun increaseTime(timeToAdd: Duration) {
clock.addTime(timeToAdd)
}

override fun getCurrentTime(): Instant {
return clock.currentTime
}
}
62 changes: 62 additions & 0 deletions eze/src/test/kotlin/org/camunda/community/eze/EngineApiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Zeebe Community License 1.1. You may not use this file
* except in compliance with the Zeebe Community License 1.1.
*/
package org.camunda.community.eze

import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.within
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Duration
import java.time.Instant
import java.time.temporal.ChronoUnit


class EngineApiTest {

private lateinit var zeebeEngine: ZeebeEngine

@BeforeEach
fun `setup server`() {
zeebeEngine = EngineFactory.create()
zeebeEngine.start()
}

@AfterEach
fun `tear down`() {
zeebeEngine.stop()
}

@Test
fun `should get current time`() {
// given
val now = Instant.now()

// when
val currentTime = zeebeEngine.clock().getCurrentTime()

// then
assertThat(currentTime).isCloseTo(now, within(1, ChronoUnit.SECONDS))
}

@Test
fun `should increase time`() {
// given
val timeBefore = zeebeEngine.clock().getCurrentTime()
val duration = Duration.ofHours(1)

// when
zeebeEngine.clock().increaseTime(duration)

val timeAfter = zeebeEngine.clock().getCurrentTime()

// then
assertThat(timeAfter).isCloseTo(timeBefore.plus(duration), within(1, ChronoUnit.SECONDS))
}

}