Skip to content

Commit

Permalink
Updates test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Gasser committed Apr 24, 2024
1 parent d9ce69f commit 55a3310
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ package org.vitrivr.cottontail.dbms.entity.sequence

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.vitrivr.cottontail.core.database.ColumnDef
import org.vitrivr.cottontail.core.database.Name
import org.vitrivr.cottontail.core.tuple.StandaloneTuple
import org.vitrivr.cottontail.core.types.Types
import org.vitrivr.cottontail.core.types.Value
import org.vitrivr.cottontail.core.values.IntValue
import org.vitrivr.cottontail.core.values.LongValue
import org.vitrivr.cottontail.core.values.generators.StringValueGenerator
import org.vitrivr.cottontail.dbms.entity.AbstractEntityTest
import org.vitrivr.cottontail.dbms.execution.transactions.TransactionType
import org.vitrivr.cottontail.dbms.queries.context.DefaultQueryContext
import org.vitrivr.cottontail.test.TestConstants
import java.util.*

class SequenceTest: AbstractEntityTest() {

private val random = SplittableRandom()

/** */
override val entities: List<Pair<Name.EntityName, List<ColumnDef<*>>>> = listOf(
TestConstants.TEST_ENTITY_NAME to listOf(
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.ID_COLUMN_NAME), Types.Int, nullable = false, primary = true, autoIncrement = true),
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.STRING_COLUMN_NAME), Types.String, nullable = false, primary = false, autoIncrement = false),
)
)
/**
* An abstract class for test cases that test for correctness of sequences
*
* @author Ralph Gasser
* @version 1.0.0
*/
abstract class AbstractSequenceTest: AbstractEntityTest() {
/** [SplittableRandom] used to generate random values. */
protected val random = SplittableRandom()

@Test
fun testSequence() {
Expand All @@ -38,8 +35,7 @@ class SequenceTest: AbstractEntityTest() {
val entity1 = schemaTx1.entityForName(TestConstants.TEST_ENTITY_NAME)
val entityTx1 = entity1.newTx(ctx1)
repeat(TestConstants.TEST_COLLECTION_SIZE - 1) {
val reference = this.nextRecord(it)
entityTx1.insert(reference)
entityTx1.insert(this.nextRecord())
}
txn1.commit()

Expand All @@ -55,21 +51,23 @@ class SequenceTest: AbstractEntityTest() {
val entityTx2 = entity2.newTx(ctx2)
val cursor = entityTx2.cursor(this.entities[0].second.toTypedArray())
for ((i, record) in cursor.withIndex()) {
Assertions.assertEquals(i+1, (record[this.entities[0].second[0]] as? IntValue)!!.value)
test(record[this.entities[0].second[0]], i)
}
txn2.commit()
}

/** We start with an empty entity. */
override fun populateDatabase() {
/* No op */
/* No op */
}

/**
* Generates the next [StandaloneTuple] and returns it.
*/
fun nextRecord(i: Int): StandaloneTuple {
fun nextRecord(): StandaloneTuple {
val string = StringValueGenerator.random(this.random)
return StandaloneTuple(0L, columns = arrayOf(this.entities[0].second[1]), values = arrayOf(string))
}

abstract fun test(value: Value?, index: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.vitrivr.cottontail.dbms.entity.sequence

import org.junit.jupiter.api.Assertions
import org.vitrivr.cottontail.core.database.ColumnDef
import org.vitrivr.cottontail.core.database.Name
import org.vitrivr.cottontail.core.types.Types
import org.vitrivr.cottontail.core.types.Value
import org.vitrivr.cottontail.core.values.IntValue
import org.vitrivr.cottontail.test.TestConstants

class IntSequenceTest: AbstractSequenceTest() {
/** The test entity. */
override val entities: List<Pair<Name.EntityName, List<ColumnDef<*>>>> = listOf(
TestConstants.TEST_ENTITY_NAME to listOf(
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.ID_COLUMN_NAME), Types.Int, nullable = false, primary = true, autoIncrement = true),
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.STRING_COLUMN_NAME), Types.String, nullable = false, primary = false, autoIncrement = false),
)
)

override fun test(value: Value?, index: Int) = Assertions.assertEquals(index+1, (value as? IntValue)!!.value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.vitrivr.cottontail.dbms.entity.sequence

import org.junit.jupiter.api.Assertions
import org.vitrivr.cottontail.core.database.ColumnDef
import org.vitrivr.cottontail.core.database.Name
import org.vitrivr.cottontail.core.types.Types
import org.vitrivr.cottontail.core.types.Value
import org.vitrivr.cottontail.core.values.LongValue
import org.vitrivr.cottontail.test.TestConstants

class LongSequenceTest: AbstractSequenceTest() {
/** The test entity. */
override val entities: List<Pair<Name.EntityName, List<ColumnDef<*>>>> = listOf(
TestConstants.TEST_ENTITY_NAME to listOf(
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.ID_COLUMN_NAME), Types.Long, nullable = false, primary = true, autoIncrement = true),
ColumnDef(TestConstants.TEST_ENTITY_NAME.column(TestConstants.STRING_COLUMN_NAME), Types.String, nullable = false, primary = false, autoIncrement = false),
)
)

override fun test(value: Value?, index: Int) = Assertions.assertEquals(index+1L, (value as? LongValue)!!.value)
}

0 comments on commit 55a3310

Please sign in to comment.