Fixes
This commit is contained in:
@@ -5,6 +5,7 @@ import nl.astraeus.persistence.domain.Person
|
||||
import java.io.File
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class TestThreaded {
|
||||
|
||||
@@ -42,6 +43,7 @@ class TestThreaded {
|
||||
person.name to person.age
|
||||
}
|
||||
},
|
||||
index<Person>("personCompanyId") { p -> (p as? Person)?.company?.id ?: 0L },
|
||||
index<Company>("name") { p -> (p as? Company)?.name ?: "" },
|
||||
)
|
||||
)
|
||||
@@ -68,7 +70,7 @@ class TestThreaded {
|
||||
name = names[random.nextInt(names.size)],
|
||||
age = random.nextInt(0, 100),
|
||||
)
|
||||
//person.company = company
|
||||
person.company = company
|
||||
|
||||
store(person)
|
||||
}
|
||||
@@ -80,6 +82,7 @@ class TestThreaded {
|
||||
Thread(runnable)
|
||||
}
|
||||
|
||||
val start = System.nanoTime()
|
||||
for (thread in threads) {
|
||||
thread.start()
|
||||
}
|
||||
@@ -87,19 +90,29 @@ class TestThreaded {
|
||||
for (thread in threads) {
|
||||
thread.join()
|
||||
}
|
||||
println("Store elapsed time: ${(System.nanoTime() - start) / 1_000_000}ms")
|
||||
}
|
||||
|
||||
pst.query {
|
||||
searchIndex<Person>("nameAndAge") { nameAndAge ->
|
||||
val (name, age) = nameAndAge as Pair<String, Int>
|
||||
|
||||
name.contains("mit") && age > 80
|
||||
}.forEach { p ->
|
||||
println("Found person by name and age: ${p.id}: ${p.name} - ${p.age}")
|
||||
var start = 0L
|
||||
repeat(10) {
|
||||
start = System.nanoTime()
|
||||
val withoutIndex = pst.query {
|
||||
search<Person> { person ->
|
||||
person.age == 20
|
||||
}
|
||||
}
|
||||
println("withoutIndex elapsed time: ${(System.nanoTime() - start) / 1_000_000f}ms")
|
||||
|
||||
start = System.nanoTime()
|
||||
val withIndex = pst.query {
|
||||
searchIndex<Person>("age") { age -> (age as? Int ?: -1) == 20 }
|
||||
}
|
||||
println("withIndex elapsed time: ${(System.nanoTime() - start) / 1_000_000f}ms")
|
||||
|
||||
assertEquals(withIndex.size, withoutIndex.size)
|
||||
}
|
||||
|
||||
//pst.snapshot()
|
||||
pst.snapshot()
|
||||
pst.datastore.printStatus()
|
||||
pst.removeOldFiles()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user