-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refrain from using ByteArray as key in tests
- Loading branch information
Showing
12 changed files
with
228 additions
and
98 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
85 changes: 85 additions & 0 deletions
85
src/test/kotlin/org/example/index/CheckpointableIndexes.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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.example.index | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import org.example.TestInstance | ||
import org.example.TestResources | ||
import org.example.encoder.JsonStringEncoder | ||
import org.example.encoder.ProtobufBinaryEncoder | ||
import org.example.log.LogFactories | ||
import java.util.concurrent.atomic.AtomicLong | ||
|
||
class CheckpointableIndexes(private val resources: TestResources, | ||
private val logs: LogFactories, | ||
private val dispatcher: CoroutineDispatcher) { | ||
|
||
private val generator = AtomicLong() | ||
|
||
@ExperimentalSerializationApi | ||
fun <K : Comparable<K>> indexes(serializer: KSerializer<IndexEntry<K>>) | ||
: Sequence<TestInstance<CheckpointableIndex<K>>> | ||
= comparableIndexes(serializer) + nonComparableIndexes(serializer) | ||
|
||
@ExperimentalSerializationApi | ||
fun <K: Comparable<K>> comparableIndexes(serializer: KSerializer<IndexEntry<K>>): | ||
Sequence<TestInstance<CheckpointableIndex<K>>> = indexes(TreeIndexFactory(), serializer) | ||
|
||
@ExperimentalSerializationApi | ||
fun <K> nonComparableIndexes(serializer: KSerializer<IndexEntry<K>>) | ||
: Sequence<TestInstance<CheckpointableIndex<K>>> = indexes(HashIndexFactory(), serializer) | ||
|
||
@ExperimentalSerializationApi | ||
private fun <K> indexes(innerIndexFactory: IndexFactory<K>, serializer: KSerializer<IndexEntry<K>>): | ||
Sequence<TestInstance<CheckpointableIndex<K>>> = indexFactories(innerIndexFactory, serializer) | ||
.map { case -> | ||
TestInstance(case.name) { | ||
case.instance().create("CheckpointableIndex${generator.getAndIncrement()}") | ||
} | ||
} | ||
|
||
@ExperimentalSerializationApi | ||
fun <K> nonComparableIndexFactories(serializer: KSerializer<IndexEntry<K>>) = indexFactories( | ||
HashIndexFactory(), | ||
serializer | ||
) | ||
|
||
@ExperimentalSerializationApi | ||
fun <K: Comparable<K>> comparableIndexFactories(serializer: KSerializer<IndexEntry<K>>) = indexFactories( | ||
TreeIndexFactory(), | ||
serializer | ||
) | ||
|
||
@ExperimentalSerializationApi | ||
private fun <K> indexFactories(innerIndexFactory: IndexFactory<K>, serializer: KSerializer<IndexEntry<K>>) | ||
: Sequence<TestInstance<CheckpointableIndexFactory<K>>> = sequence { | ||
|
||
for (lineLogInstance in logs.lineLogInstances()) { | ||
|
||
yield(TestInstance("Checkpointable String Index ~ ${lineLogInstance.name}") { | ||
val indexDir = resources.allocateTempDir("index-string-") | ||
CheckpointableIndexFactory( | ||
innerIndexFactory, | ||
indexDir, | ||
IndexEntryLogFactory(lineLogInstance.instance(), JsonStringEncoder(serializer)), | ||
10_000, | ||
dispatcher | ||
) | ||
}) | ||
} | ||
|
||
for (binaryInstance in logs.binaryInstances()) { | ||
|
||
yield(TestInstance("Checkpointable Binary Index ~ ${binaryInstance.name}") { | ||
val indexDir = resources.allocateTempDir("index-binary-") | ||
CheckpointableIndexFactory( | ||
innerIndexFactory, | ||
indexDir, | ||
IndexEntryLogFactory(binaryInstance.instance(), ProtobufBinaryEncoder(serializer)), | ||
10_000, | ||
dispatcher | ||
) | ||
}) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.example.index | ||
|
||
import org.example.TestInstance | ||
import java.util.concurrent.atomic.AtomicLong | ||
|
||
internal abstract class HashIndexTest<K>: IndexTest<K> { | ||
|
||
internal val uniqueGenerator = AtomicLong() | ||
|
||
override fun instances(): Sequence<TestInstance<Index<K>>> = indexes.hashIndexes() | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
internal val indexes = Indexes() | ||
} | ||
|
||
} | ||
|
||
internal class LongHashIndexTest: HashIndexTest<Long>() { | ||
|
||
override fun nextKey() = uniqueGenerator.getAndIncrement() | ||
|
||
} | ||
|
||
internal class StringHashIndexTest: HashIndexTest<String>() { | ||
|
||
override fun nextKey() = uniqueGenerator.getAndIncrement().toString() | ||
|
||
} |
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,93 +1,31 @@ | ||
package org.example.index | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import org.example.TestInstance | ||
import org.example.TestResources | ||
import org.example.encoder.JsonStringEncoder | ||
import org.example.encoder.ProtobufBinaryEncoder | ||
import org.example.log.LogFactories | ||
import java.util.concurrent.atomic.AtomicLong | ||
|
||
class Indexes(private val logs: LogFactories, | ||
private val resources: TestResources, | ||
private val dispatcher: CoroutineDispatcher) { | ||
class Indexes { | ||
|
||
private val generator = AtomicLong() | ||
|
||
@ExperimentalSerializationApi | ||
fun <K : Comparable<K>> instances(serializer: KSerializer<IndexEntry<K>>): Sequence<TestInstance<Index<K>>> | ||
= comparableInstances(serializer) + nonComparableInstances(serializer) | ||
|
||
@ExperimentalSerializationApi | ||
fun <K> nonComparableInstances(serializer: KSerializer<IndexEntry<K>>): Sequence<TestInstance<Index<K>>> { | ||
fun <K> hashIndexes(): Sequence<TestInstance<Index<K>>> { | ||
|
||
val factory = HashIndexFactory<K>() | ||
|
||
val volatileHash = TestInstance("Hash Index") { | ||
factory.create("HashIndex${generator.getAndIncrement()}") | ||
} | ||
|
||
return sequenceOf(volatileHash) + checkpointableNonComparableIndexes(serializer) | ||
return sequenceOf(volatileHash) | ||
} | ||
|
||
@ExperimentalSerializationApi | ||
private fun <K : Comparable<K>> comparableInstances(serializer: KSerializer<IndexEntry<K>>): | ||
Sequence<TestInstance<Index<K>>> { | ||
fun <K: Comparable<K>> treeIndexes(): Sequence<TestInstance<Index<K>>> { | ||
|
||
val factory = TreeIndexFactory<K>() | ||
val volatileTree = TestInstance("Tree Index") { | ||
val transientTree = TestInstance("Tree Index") { | ||
factory.create("TreeIndex${generator.getAndIncrement()}") | ||
} | ||
|
||
return sequenceOf(volatileTree) + checkpointableComparableIndexes(serializer) | ||
return sequenceOf(transientTree) | ||
} | ||
|
||
@ExperimentalSerializationApi | ||
private fun <K: Comparable<K>> checkpointableComparableIndexes(serializer: KSerializer<IndexEntry<K>>): | ||
Sequence<TestInstance<Index<K>>> = checkpointableIndexes(TreeIndexFactory(), serializer) | ||
|
||
@ExperimentalSerializationApi | ||
fun <K> checkpointableNonComparableIndexes(serializer: KSerializer<IndexEntry<K>>): Sequence<TestInstance<Index<K>>> | ||
= checkpointableIndexes(HashIndexFactory(), serializer) | ||
|
||
@ExperimentalSerializationApi | ||
private fun <K> checkpointableIndexes(innerIndexFactory: IndexFactory<K>, serializer: KSerializer<IndexEntry<K>>): | ||
Sequence<TestInstance<Index<K>>> = | ||
sequence { | ||
|
||
val indexDir = resources.allocateTempDir("index-") | ||
|
||
for (lineLogInstance in logs.lineLogInstances()) { | ||
val stringFactory = CheckpointableIndexFactory( | ||
innerIndexFactory, | ||
indexDir, | ||
IndexEntryLogFactory(lineLogInstance.instance(), JsonStringEncoder(serializer)), | ||
10_000, | ||
dispatcher | ||
) | ||
|
||
yield(TestInstance("Checkpointable String Index") { | ||
stringFactory.create("CheckpointableIndex${generator.getAndIncrement()} ~ ${lineLogInstance | ||
.name}") | ||
}) | ||
} | ||
|
||
for (binaryInstance in logs.binaryInstances()) { | ||
val binaryFactory = CheckpointableIndexFactory( | ||
innerIndexFactory, | ||
indexDir, | ||
IndexEntryLogFactory(binaryInstance.instance(), ProtobufBinaryEncoder(serializer)), | ||
10_000, | ||
dispatcher | ||
) | ||
|
||
yield(TestInstance("Checkpointable Binary Index") { | ||
binaryFactory.create("CheckpointableIndex${generator.getAndIncrement()} ~ ${binaryInstance | ||
.name}") | ||
}) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.