Stats printing

This commit is contained in:
2024-05-05 10:33:17 +02:00
parent da046fa6ec
commit 045306f7d1
7 changed files with 60 additions and 6 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
gradle.properties
### IntelliJ IDEA ###
.idea/modules.xml

View File

@@ -1 +0,0 @@
kotlin.code.style=official

View File

@@ -29,7 +29,9 @@ class Persistent(
try {
block(transactions.get())
if (cleanup) {
transactions.get().commit()
}
} finally {
if (cleanup) {
transactions.remove()

View File

@@ -18,9 +18,9 @@ class Reference<S : Persistable, H : Persistable>(
operator fun setValue(thisRef: H, property: KProperty<*>, value: S) {
id = value.id
// todo: only store if not already stored?
currentTransaction()?.store(value)
}
}
class ListReference<S : Persistable, H : Persistable>(

View File

@@ -12,6 +12,22 @@ class TransactionLog(
fileManager.findLastSnapshot().let { (after, snapshot) ->
println("Last snapshot: $snapshot")
println("Snapshot:")
snapshot?.inputStream()?.use { input ->
ObjectInputStream(input).use { ois ->
val versionNumber = ois.readInt()
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
val transactionNumber = ois.readLong()
println("[$versionNumber] $transactionNumber")
val data = ois.readObject() as MutableMap<Class<*>, TypeData>
println("Data:")
println("\tClasses:")
for ((cls, entries) in data.entries) {
println("\t\t- $cls: ${entries.data.keys.size}")
}
}
}
val transactions = fileManager.findTransactionsAfter(after ?: 0L)
println("Transactions:")
@@ -22,7 +38,10 @@ class TransactionLog(
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
val transactionNumber = ois.readLong()
val actions = ois.readObject() as Set<Action>
println("[$versionNumber] $transactionNumber - ${actions.joinToString(",")}")
println("\t[$transactionNumber]")
for (action in actions) {
println("\t\t- $action")
}
}
}
}

View File

@@ -3,6 +3,7 @@ package nl.astraeus.persistence
import nl.astraeus.nl.astraeus.persistence.Persistable
import nl.astraeus.nl.astraeus.persistence.Persistent
import nl.astraeus.nl.astraeus.persistence.Reference
import nl.astraeus.nl.astraeus.persistence.TransactionLog
import nl.astraeus.nl.astraeus.persistence.find
import nl.astraeus.nl.astraeus.persistence.findByIndex
import nl.astraeus.nl.astraeus.persistence.index
@@ -23,6 +24,10 @@ class TestPersistence {
companion object {
private const val serialVersionUID: Long = 1L
}
override fun toString(): String {
return "Company(id=$id, version=$version, name='$name')"
}
}
class Person(
@@ -36,6 +41,17 @@ class TestPersistence {
companion object {
private const val serialVersionUID: Long = 1L
}
override fun toString(): String {
return "Person(id=$id, version=$version, name='$name', age=$age)"
}
}
@Test
fun showTransactions() {
val log = TransactionLog(File("data", "test-persistence"))
log.showTransactions()
}
@Test
@@ -153,7 +169,7 @@ class TestPersistence {
}
}
pst.snapshot()
//pst.snapshot()
pst.transaction {
store(

View File

@@ -3,6 +3,7 @@ package nl.astraeus.persistence
import nl.astraeus.nl.astraeus.persistence.Persistable
import nl.astraeus.nl.astraeus.persistence.Persistent
import nl.astraeus.nl.astraeus.persistence.Reference
import nl.astraeus.nl.astraeus.persistence.TransactionLog
import nl.astraeus.nl.astraeus.persistence.count
import nl.astraeus.nl.astraeus.persistence.index
import nl.astraeus.nl.astraeus.persistence.searchIndex
@@ -23,6 +24,11 @@ class TestThreaded {
companion object {
private const val serialVersionUID: Long = 1L
}
override fun toString(): String {
return "Company(id=$id, version=$version, name='$name', adres='$adres')"
}
}
class Person(
@@ -36,6 +42,17 @@ class TestThreaded {
companion object {
private const val serialVersionUID: Long = 1L
}
override fun toString(): String {
return "Person(id=$id, version=$version, name='$name', age=$age)"
}
}
@Test
fun showTransactions() {
val log = TransactionLog(File("data", "test-threaded"))
log.showTransactions()
}
@Test
@@ -122,7 +139,7 @@ class TestThreaded {
}
}
pst.snapshot()
//pst.snapshot()
pst.datastore.printStatus()
pst.removeOldFiles()
}