From 3d2f910bd3a4a7197e0421d12bb0af604ffd74e0 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Sat, 4 Jun 2022 16:59:21 +0200 Subject: [PATCH] feat: get current time --- .../camunda/community/eze/ZeebeEngineClock.kt | 3 + .../community/eze/ZeebeEngineClockImpl.kt | 5 ++ .../camunda/community/eze/EngineApiTest.kt | 62 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 eze/src/test/kotlin/org/camunda/community/eze/EngineApiTest.kt diff --git a/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClock.kt b/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClock.kt index a6244c2..a3c3c96 100644 --- a/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClock.kt +++ b/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClock.kt @@ -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 } diff --git a/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClockImpl.kt b/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClockImpl.kt index f9bc5b3..f6b4ef6 100644 --- a/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClockImpl.kt +++ b/eze/src/main/kotlin/org/camunda/community/eze/ZeebeEngineClockImpl.kt @@ -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 + } } diff --git a/eze/src/test/kotlin/org/camunda/community/eze/EngineApiTest.kt b/eze/src/test/kotlin/org/camunda/community/eze/EngineApiTest.kt new file mode 100644 index 0000000..0f7a808 --- /dev/null +++ b/eze/src/test/kotlin/org/camunda/community/eze/EngineApiTest.kt @@ -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)) + } + +}