-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transactions to file writes and restore files to previous state w…
…hen transactions fail (#100) * Add missing documentation and labelled params * Update file codec to write to a temp file and move once completed * Add test cases for transactional encodes * Update kstore api * Move storeOf to kstore * Add test case for close * Fix VersionedCodec
- Loading branch information
Showing
12 changed files
with
138 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 30 additions & 4 deletions
34
kstore-file/src/commonTest/kotlin/io/github/xxfast/kstore/file/TestModels.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
package io.github.xxfast.kstore.file | ||
|
||
import io.github.xxfast.kstore.file.RobotCat.Id | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable | ||
sealed class Pet { | ||
abstract val name: String | ||
abstract val age: Int | ||
sealed interface Pet { | ||
val name: String | ||
val age: Number | ||
} | ||
|
||
@Serializable | ||
data class Cat( | ||
override val name: String, | ||
override val age: Int, | ||
val lives: Int = 9, | ||
) : Pet() | ||
) : Pet | ||
|
||
@Serializable | ||
data class RobotCat( | ||
override val name: String, | ||
override val age: Int, | ||
val id: Id | ||
): Pet { | ||
|
||
// This field helps to simulate encoder to fail half way through | ||
@Serializable(with = Id.Serializer::class) | ||
class Id(val value: Long) { | ||
companion object Serializer : KSerializer<Id> { | ||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Id", PrimitiveKind.LONG) | ||
override fun deserialize(decoder: Decoder): Id { TODO("Not yet implemented") } | ||
override fun serialize(encoder: Encoder, value: Id) { TODO("Not yet implemented") } | ||
} | ||
} | ||
} | ||
|
||
internal val MYLO = Cat(name = "Mylo", age = 1) | ||
internal val OREO = Cat(name = "Oreo", age = 1) | ||
internal val KAT = RobotCat(name = "Kat", age = 12, id = Id(123L)) | ||
|
||
const val FILE_PATH = "test.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters