Skip to content

Commit

Permalink
Adds remaining base operations to AbstractRetrievableWriterTest.
Browse files Browse the repository at this point in the history
Signed-off-by: Ralph Gasser <[email protected]>
  • Loading branch information
ppanopticon committed Jul 11, 2024
1 parent e8d026b commit 3d83f88
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,60 @@ abstract class AbstractRetrievableWriterTest(schemaPath: String) : AbstractDatab
}
}

/**
* Tests if the [RetrievableWriter.add] works as expected.
*/
@Test
fun testDeleteAll() {
val writer = this.testConnection.getRetrievableWriter()
val reader = this.testConnection.getRetrievableReader()
val size = Random().nextInt(500, 5000)

/* Create and add retrievable. */
val ids = (0 until size).map { UUID.randomUUID() }
val ingested = ids.map { Ingested(it, "INGESTED:TEST", false) }

/* Execute actions. */
Assertions.assertTrue(writer.addAll(ingested))

/* Check if retrievable can be read. */
Assertions.assertEquals(ids.size.toLong(), reader.count())
reader.getAll(ids).forEachIndexed() { i, it ->
Assertions.assertEquals("INGESTED:TEST", it.type)
}

/* Execute actions. */
Assertions.assertTrue(writer.deleteAll(ingested))
Assertions.assertEquals(0L, reader.count())
}


/**
* Tests if the [RetrievableWriter.add] works as expected.
*/
@Test
fun testUpdate() {
val writer = this.testConnection.getRetrievableWriter()
val reader = this.testConnection.getRetrievableReader()
val size = Random().nextInt(500, 5000)

/* Create and add retrievable. */
val ids = (0 until size).map { UUID.randomUUID() }
val ingested = ids.map { Ingested(it, "INGESTED:TEST", false) }
val update = ingested[Random().nextInt(0, ingested.size)]

/* Execute actions. */
Assertions.assertTrue(writer.addAll(ingested))

/* Check if retrievable can be read. */
Assertions.assertEquals(ids.size.toLong(), reader.count())
Assertions.assertTrue(writer.update(update.copy(type = "INGESTED:TEST2")))

/* Execute actions. */
Assertions.assertEquals(ids.size.toLong(), reader.count())
Assertions.assertEquals("INGESTED:TEST2", reader[update.id]?.type)
}

/**
* Cleans up the database after each test.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class RetrievableWriter(override val connection: PgVectorConnection): R
this.connection.jdbc.prepareStatement("UPDATE $RETRIEVABLE_ENTITY_NAME SET $RETRIEVABLE_TYPE_COLUMN_NAME = ? WHERE $RETRIEVABLE_ID_COLUMN_NAME = ?").use { stmt ->
stmt.setString(1, item.type)
stmt.setObject(2, item.id)
return stmt.execute()
return stmt.executeUpdate() == 1
}
} catch (e: SQLException) {
LOGGER.error(e) { "Failed to update retrievable ${item.id} due to SQL error." }
Expand Down

0 comments on commit 3d83f88

Please sign in to comment.