-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds basic CI facilities to build Unit Tests:
- GitHub Action for pushes / PRs to dev and main - Service containers for PostgreSQL and Cottontail DB - Scaffold for test case on database layer (to be extended). Signed-off-by: Ralph Gasser <[email protected]>
- Loading branch information
1 parent
a74dc3a
commit 7ff7d5f
Showing
9 changed files
with
230 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Java CI with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ main, dev ] | ||
pull_request: | ||
branches: [ main, dev ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
# Setup Cottontail DB and PostgreSQL service container | ||
services: | ||
cottontail: | ||
image: vitrivr/cottontaildb:0.16.6 | ||
ports: | ||
- 1865:1865 | ||
options: -it | ||
pgvector: | ||
image: pgvector/pgvector:pg16 | ||
ports: | ||
- 5432:5432 | ||
env: | ||
POSTGRES_PASSWORD: vitrivr | ||
|
||
# Start actual job. | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Cottontail DB connection test | ||
run: nc -zv 127.0.0.1 1865 | ||
- name: PostgreSQL connection test | ||
run: nc -zv 127.0.0.1 5432 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | ||
restore-keys: ${{ runner.os }}-gradle | ||
- name: Test with gradle ubuntu | ||
if: matrix.os == 'ubuntu-latest' | ||
run: ./gradlew test --info | ||
- name: Test with gradle windows | ||
if: matrix.os == 'windows-latest' | ||
run: ./gradlew test --info |
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
31 changes: 31 additions & 0 deletions
31
...ine-core/src/testFixtures/kotlin/org/vitrivr/engine/core/database/AbstractDatabaseTest.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,31 @@ | ||
package org.vitrivr.engine.core.database | ||
|
||
import org.vitrivr.engine.core.config.schema.SchemaConfig | ||
import org.vitrivr.engine.core.model.metamodel.SchemaManager | ||
|
||
/** | ||
* Abstract base class for database tests. | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
abstract class AbstractDatabaseTest(schemaPath: String) { | ||
|
||
companion object { | ||
val SCHEMA_NAME = "vitrivr-test" | ||
} | ||
|
||
|
||
/** [SchemaManager] for this [AbstractDatabaseTest]. */ | ||
protected val manager = SchemaManager() | ||
|
||
init { | ||
/* Loads schema. */ | ||
val schema = SchemaConfig.loadFromResource(schemaPath) | ||
this.manager.load(schema) | ||
} | ||
|
||
|
||
/** */ | ||
protected val schema = this.manager.getSchema("vitrivr-test") ?: throw IllegalArgumentException("Schema 'vitrivr-test' not found!") | ||
} |
36 changes: 36 additions & 0 deletions
36
...kotlin/org/vitrivr/engine/core/database/retrievable/AbstractRetrievableInitializerTest.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,36 @@ | ||
package org.vitrivr.engine.core.database.retrievable | ||
|
||
import org.junit.jupiter.api.AfterEach | ||
import org.vitrivr.engine.core.database.AbstractDatabaseTest | ||
|
||
/** | ||
* An abstract set of test cases to test the proper functioning of [RetrievableInitializer] implementations. | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
abstract class AbstractRetrievableInitializerTest(schemaPath: String) : AbstractDatabaseTest(schemaPath) { | ||
/** | ||
* Tests if the [RetrievableInitializer] can be initialized without throwing an exception. Furthermore, | ||
* the test should check if the necessary tables have been created. | ||
*/ | ||
abstract fun testIsInitializedWithoutInitialization() | ||
|
||
/** | ||
* Tests if the [RetrievableInitializer] can be initialized without throwing an exception. Furthermore, | ||
* the test should check if the necessary tables have been created. | ||
*/ | ||
abstract fun testInitializeEntities() | ||
|
||
/** | ||
* Cleans up the database after each test. | ||
* | ||
*/ | ||
@AfterEach | ||
open fun cleanup() { | ||
this.schema.connection.getRetrievableInitializer().deinitialize() | ||
for (field in this.schema.fields()) { | ||
field.getInitializer().deinitialize() | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...vector/src/test/kotlin/org/vitrivr/engine/database/pgvector/RetrievableInitializerTest.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,51 @@ | ||
package org.vitrivr.engine.database.pgvector | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.vitrivr.engine.core.database.retrievable.AbstractRetrievableInitializerTest | ||
|
||
/** | ||
* An [AbstractRetrievableInitializerTest] for the [PgVectorConnection]. | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
class RetrievableInitializerTest : AbstractRetrievableInitializerTest("test-schema-postgres.json") { | ||
|
||
/** Internal [PgVectorConnection] object. */ | ||
private val connection = this.schema.connection as? PgVectorConnection ?: throw IllegalArgumentException("Schema 'vitrivr-test' not found!") | ||
|
||
@Test | ||
override fun testIsInitializedWithoutInitialization() { | ||
Assertions.assertFalse(this.connection.getRetrievableInitializer().isInitialized()) | ||
} | ||
|
||
@Test | ||
override fun testInitializeEntities() { | ||
/* Check initialization status (should be false). */ | ||
Assertions.assertFalse(this.connection.getRetrievableInitializer().isInitialized()) | ||
|
||
/* Initialize basic tables. */ | ||
this.connection.getRetrievableInitializer().initialize() | ||
|
||
/* Check initialization status (should be true). */ | ||
Assertions.assertTrue(this.connection.getRetrievableInitializer().isInitialized()) | ||
|
||
/* Check for existence of tables. */ | ||
this.connection.jdbc.prepareStatement("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ? AND table_name = ?)").use { statement -> | ||
/* Check existence of retrievable table. */ | ||
statement.setString(1, SCHEMA_NAME) | ||
statement.setString(2, RETRIEVABLE_ENTITY_NAME) | ||
statement.executeQuery().use { result -> | ||
Assertions.assertTrue(result.next() && result.getBoolean(1)) | ||
} | ||
|
||
/* Check existence of relationship table. */ | ||
statement.setString(1, SCHEMA_NAME) | ||
statement.setString(2, RELATIONSHIP_ENTITY_NAME) | ||
statement.executeQuery().use { result -> | ||
Assertions.assertTrue(result.next() && result.getBoolean(1)) | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
vitrivr-engine-module-pgvector/src/test/resources/test-schema-postgres.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "vitrivr-test", | ||
"connection": { | ||
"database": "PgVectorConnectionProvider", | ||
"parameters": { | ||
"host": "127.0.0.1", | ||
"port": "5432", | ||
"username": "postgres", | ||
"password": "vitrivr" | ||
} | ||
}, | ||
"fields": [ | ||
{ | ||
"name": "averagecolor", | ||
"factory": "AverageColor" | ||
}, | ||
{ | ||
"name": "file", | ||
"factory": "FileSourceMetadata" | ||
}, | ||
{ | ||
"name": "time", | ||
"factory": "TemporalMetadata" | ||
}, | ||
{ | ||
"name": "video", | ||
"factory": "VideoSourceMetadata" | ||
} | ||
], | ||
"exporters": [] | ||
} |