Add fromTo util function for storeTransacton
This commit is contained in:
parent
53f9af3ba4
commit
099649f090
@ -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<PropertyChangedMessage> {
|
||||
return find(
|
||||
"PropertyChangedMessage",
|
||||
"time",
|
||||
from.toEpochMilliseconds(),
|
||||
to.toEpochMilliseconds()
|
||||
).map { it -> it.toPropertyChangedMessage() }.filterNotNull()
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user