Dev #8

Merged
altavir merged 78 commits from dev into master 2023-03-04 16:47:55 +03:00
3 changed files with 80 additions and 2 deletions
Showing only changes of commit 099649f090 - Show all commits

View File

@ -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()
}

View File

@ -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()
}
}

View File

@ -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())
}
}