From 21c13ce3afafbee6fee9ea1ba779725628074d5a Mon Sep 17 00:00:00 2001 From: Atos1337 Date: Sat, 15 Jan 2022 16:00:23 +0300 Subject: [PATCH] Update propertyHistoryTest for xodus --- .../src/test/kotlin/PropertyHistoryTest.kt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 controls-xodus/src/test/kotlin/PropertyHistoryTest.kt diff --git a/controls-xodus/src/test/kotlin/PropertyHistoryTest.kt b/controls-xodus/src/test/kotlin/PropertyHistoryTest.kt new file mode 100644 index 0000000..4df90ba --- /dev/null +++ b/controls-xodus/src/test/kotlin/PropertyHistoryTest.kt @@ -0,0 +1,66 @@ +import jetbrains.exodus.entitystore.PersistentEntityStores +import kotlinx.datetime.Instant +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import ru.mipt.npm.controls.api.DeviceMessage +import ru.mipt.npm.controls.api.PropertyChangedMessage +import ru.mipt.npm.controls.storage.synchronous.getPropertyHistory +import ru.mipt.npm.controls.xodus.DefaultSynchronousXodusClientFactory +import ru.mipt.npm.controls.xodus.XODUS_STORE_PROPERTY +import ru.mipt.npm.xodus.serialization.json.encodeToEntity +import space.kscience.dataforge.meta.Meta +import space.kscience.dataforge.names.Name +import java.io.File + +internal class PropertyHistoryTest { + companion object { + private val storeName = ".property_history_test" + private val entityStore = PersistentEntityStores.newInstance(storeName) + + private val propertyChangedMessages = listOf( + PropertyChangedMessage( + "speed", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(1000), + sourceDevice = Name.of("virtual-car") + ), + PropertyChangedMessage( + "acceleration", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(1500), + sourceDevice = Name.of("virtual-car") + ), + PropertyChangedMessage( + "speed", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(2000), + sourceDevice = Name.of("magix-virtual-car") + ) + ) + + @BeforeAll + @JvmStatic + fun createEntities() { + propertyChangedMessages.forEach { + entityStore.encodeToEntity(it, "DeviceMessage") + } + entityStore.close() + } + + @AfterAll + @JvmStatic + fun deleteDatabase() { + File(storeName).deleteRecursively() + } + } + + @Test + fun getPropertyHistoryTest() { + assertEquals(listOf(propertyChangedMessages[0]), getPropertyHistory( + "virtual-car", "speed", DefaultSynchronousXodusClientFactory, Meta { + XODUS_STORE_PROPERTY put storeName + })) + } +} \ No newline at end of file