diff --git a/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/util/queries.kt b/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/util/queries.kt new file mode 100644 index 0000000..7771f35 --- /dev/null +++ b/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/util/queries.kt @@ -0,0 +1,15 @@ +package ru.mipt.npm.controls.xodus.util + +import jetbrains.exodus.entitystore.StoreTransaction +import kotlinx.datetime.Instant +import ru.mipt.npm.controls.api.PropertyChangedMessage +import ru.mipt.npm.controls.xodus.toPropertyChangedMessage + +public fun StoreTransaction.fromTo(from: Instant, to: Instant): List { + return find( + "PropertyChangedMessage", + "time", + from.toEpochMilliseconds(), + to.toEpochMilliseconds() + ).map { it -> it.toPropertyChangedMessage() }.filterNotNull() +} diff --git a/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/ConvertersTest.kt b/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/ConvertersTest.kt index 85e8ba0..da7f4d6 100644 --- a/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/ConvertersTest.kt +++ b/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/ConvertersTest.kt @@ -16,7 +16,8 @@ import kotlin.test.assertEquals internal class ConvertersTest { companion object { - private val entityStore = PersistentEntityStores.newInstance(".test") + private val storeName = ".converters_test" + private val entityStore = PersistentEntityStores.newInstance(storeName) private val expectedMessage = MagixMessage( "dataforge", "dataforge", @@ -46,7 +47,7 @@ internal class ConvertersTest { @JvmStatic fun deleteDatabase() { entityStore.close() - File(".test").deleteRecursively() + File(storeName).deleteRecursively() } } diff --git a/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/util/QueriesTest.kt b/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/util/QueriesTest.kt new file mode 100644 index 0000000..7da8bba --- /dev/null +++ b/controls-xodus/src/test/kotlin/ru/mipt/npm/controls/xodus/util/QueriesTest.kt @@ -0,0 +1,62 @@ +package ru.mipt.npm.controls.xodus.util + +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.PropertyChangedMessage +import ru.mipt.npm.controls.xodus.toEntity +import space.kscience.dataforge.meta.Meta +import java.io.File + +internal class QueriesTest { + companion object { + private val storeName = ".queries_test" + private val entityStore = PersistentEntityStores.newInstance(storeName) + + private val propertyChangedMessages = listOf( + PropertyChangedMessage( + "", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(1000) + ), + PropertyChangedMessage( + "", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(1500) + ), + PropertyChangedMessage( + "", + Meta.EMPTY, + time = Instant.fromEpochMilliseconds(2000) + ) + ) + + @BeforeAll + @JvmStatic + fun createEntities() { + entityStore.executeInTransaction { transaction -> + propertyChangedMessages.forEach { + it.toEntity(transaction) + } + } + } + + @AfterAll + @JvmStatic + fun deleteDatabase() { + entityStore.close() + File(storeName).deleteRecursively() + } + } + + @Test + fun testFromTo() { + assertEquals(propertyChangedMessages.subList(0, 2).toSet(), entityStore.computeInReadonlyTransaction { + it.fromTo(Instant.fromEpochMilliseconds(1000), Instant.fromEpochMilliseconds(1500)) + }.toSet()) + } + +} \ No newline at end of file