Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAT-15502] Add version matrix to integration and harness tests #503

Merged
merged 8 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
secrets: inherit

integration-tests:
name: Integration Test - Java ${{ matrix.java }}
name: Integration Test - Java ${{ matrix.java }} MongoDB ${{ matrix.mongodb }}
runs-on: ubuntu-latest
env:
LIQUIBOT_TOKEN: ${{ secrets.LIQUIBOT_PAT }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
strategy:
matrix:
java: [8, 11, 17]
mongodb: [4]
mongodb: [5, 6, 7]
services:
mongodb:
image: mongo:${{ matrix.mongodb }}
Expand Down Expand Up @@ -87,14 +87,15 @@ jobs:
run: mvn -B clean test verify -Prun-its --file pom.xml

harness-tests:
name: Harness Tests - Java ${{ matrix.java }}
name: Harness Tests - Java ${{ matrix.java }} MongoDB ${{ matrix.mongodb }}
runs-on: ubuntu-latest
env:
LIQUIBOT_TOKEN: ${{ secrets.LIQUIBOT_PAT }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
strategy:
matrix:
java: [ 11, 17 ]
mongodb: [5, 6, 7]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -160,15 +161,15 @@ jobs:
- name: Start Database
run: |
docker ps -a
docker-compose -f ./src/test/resources/docker/docker-compose.yml up -d
docker-compose -f ./src/test/resources/docker/docker-compose.yml up -d mongo-${{ matrix.mongodb }}
docker ps -a

- name: Harness Foundational Test Suite Run on Docker - Java ${{ matrix.java }}
run: mvn -Dtest="HarnessNoSqlCompatibility" -DdbName=mongodb clean package
run: mvn -Dtest="HarnessNoSqlCompatibility" -DdbName=mongodb clean package -DdbVersion=${{ matrix.mongodb }}

- name: Stop Docker Databases
if: always()
run: docker-compose -f ./src/test/resources/docker/docker-compose.yml down
run: docker-compose -f ./src/test/resources/docker/docker-compose.yml down mongo-${{ matrix.mongodb }}

- name: Archive Mongo Database Test Results
uses: actions/upload-artifact@v4
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/liquibase/ext/mongodb/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import com.mongodb.client.MongoDatabase;
import liquibase.Liquibase;
import liquibase.changelog.ChangeLogParameters;
import liquibase.changelog.ChangeSet;
Expand Down Expand Up @@ -101,4 +102,10 @@ public static List<ChangeSet> getChangesets(final String changeSetPath, final Mo
parser.parse(changeSetPath, new ChangeLogParameters(database), resourceAccessor);
return changeLog.getChangeSets();
}

public static int getMajorMongoDBServerVersion(MongoDatabase mongoDatabase) {
Document result = mongoDatabase.runCommand(new Document("buildInfo", 1));
List<Integer> versionArray = (List<Integer>) result.get("versionArray");
return versionArray.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import static liquibase.ext.mongodb.TestUtils.COLLECTION_NAME_1;
import static liquibase.ext.mongodb.TestUtils.EMPTY_OPTION;
import static liquibase.ext.mongodb.TestUtils.getCollections;
import static liquibase.ext.mongodb.TestUtils.getMajorMongoDBServerVersion;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;


class CreateCollectionStatementIT extends AbstractMongoIntegrationTest {
Expand Down Expand Up @@ -70,8 +72,15 @@ void cannotCreateExistingCollection() {
final CreateCollectionStatement statement = new CreateCollectionStatement(collectionName, "{}");
statement.execute(database);

assertThatExceptionOfType(MongoCommandException.class)
.isThrownBy(() -> statement.execute(database))
.withMessageContaining("already exists");

int mongoDBServerVersion = getMajorMongoDBServerVersion(database.getMongoDatabase());

if (mongoDBServerVersion == 5 || mongoDBServerVersion == 6) {
assertThatExceptionOfType(MongoCommandException.class)
.isThrownBy(() -> statement.execute(database))
.withMessageContaining("already exists");
} else if (mongoDBServerVersion == 7) {
assertThatNoException().isThrownBy(() -> statement.execute(database));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import com.mongodb.MongoCommandException;
import com.mongodb.MongoException;
import liquibase.ext.AbstractMongoIntegrationTest;
import org.bson.Document;
Expand Down Expand Up @@ -58,21 +59,29 @@ void execute() {
.findAny()
.orElseThrow(() -> new IllegalStateException("Index not found"));

assertThat(document.get("unique")).isEqualTo(true);
assertThat(document.get("key")).isEqualTo(Document.parse("{ locale: 1 }"));
assertThat(document.get("expireAfterSeconds")).isEqualTo(30L);
assertThat(document)
.containsEntry("unique", true)
.containsEntry("key", Document.parse("{ locale: 1 }"))
.containsEntry("expireAfterSeconds", 30);

// Same index name exception
final CreateIndexStatement createDuplicateNameIndexStatement = new CreateIndexStatement(COLLECTION_NAME_1, "{ otherField: 1 }", "{ name: \"" + indexName + "\" }");
assertThatExceptionOfType(MongoException.class).isThrownBy(() -> createDuplicateNameIndexStatement.execute(database))
.withMessageStartingWith("Command failed with error")
.withMessageContaining("Index must have unique name");
.withMessageContaining("An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation.");

// Same index name exception
// Same index name success
final CreateIndexStatement createSameFieldsIndexStatement = new CreateIndexStatement(COLLECTION_NAME_1, "{ locale: 1 }", "{ name: \"otherName\" }");
assertThatExceptionOfType(MongoException.class).isThrownBy(() -> createSameFieldsIndexStatement.execute(database))
.withMessageStartingWith("Command failed with error")
.withMessageContaining("Index")
.withMessageContaining("already exists with different options");
createSameFieldsIndexStatement.execute(database);

final Document document1 = StreamSupport.stream(mongoDatabase.getCollection(COLLECTION_NAME_1).listIndexes().spliterator(), false)
.filter(doc -> doc.get("name").equals("otherName"))
.findAny()
.orElseThrow(() -> new IllegalStateException("Index not found"));

assertThat(document1)
.containsEntry("v", 2)
.containsEntry("key", Document.parse("{ locale: 1 }"))
.containsEntry("name", "otherName");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
import java.util.List;

import static liquibase.ext.mongodb.TestUtils.COLLECTION_NAME_1;
import static liquibase.ext.mongodb.TestUtils.getMajorMongoDBServerVersion;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;

class DropCollectionStatementIT extends AbstractMongoIntegrationTest {

Expand All @@ -47,9 +49,15 @@ void execute() {
assertThat(mongoDatabase.listCollectionNames()).isEmpty();

// try to delete a non existing collection
assertThatExceptionOfType(MongoCommandException.class).isThrownBy(() -> dropCollectionStatement.execute(database))
.withMessageStartingWith("Command failed with error")
.withMessageContaining("NamespaceNotFound");
int mongoDBServerVersion = getMajorMongoDBServerVersion(database.getMongoDatabase());

if (mongoDBServerVersion == 5 || mongoDBServerVersion == 6) {
assertThatExceptionOfType(MongoCommandException.class).isThrownBy(() -> dropCollectionStatement.execute(database))
.withMessageStartingWith("Command failed with error")
.withMessageContaining("NamespaceNotFound");
} else if (mongoDBServerVersion == 7) {
assertThatNoException().isThrownBy(() -> dropCollectionStatement.execute(database));
}
}

@Test
Expand Down
22 changes: 20 additions & 2 deletions src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@ version: '3.1'

services:

mongo:
image: mongo:latest
mongo-5:
image: mongo:5
ports:
- "27015:27017"
environment:
MONGO_INITDB_DATABASE: lbcat
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

mongo-6:
image: mongo:6
ports:
- "27016:27017"
environment:
MONGO_INITDB_DATABASE: lbcat
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

mongo-7:
image: mongo:7
ports:
- "27017:27017"
environment:
Expand Down
14 changes: 13 additions & 1 deletion src/test/resources/harness-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ context: testContext

databasesUnderTest:
- name: mongodb
version:
version: 5
url: mongodb://lbuser:LiquibasePass1@localhost:27015/lbcat
username:
password:

- name: mongodb
version: 6
url: mongodb://lbuser:LiquibasePass1@localhost:27016/lbcat
username:
password:

- name: mongodb
version: 7
url: mongodb://lbuser:LiquibasePass1@localhost:27017/lbcat
username:
password:
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"databaseChangeLog": [
{
"changeSet": {
"id": "1",
"author": "as",
"changes": [
{
"createCollection": {
"collectionName": "countries_json"
}
}
]
}
},
{
"changeSet": {
"id": "2",
"author": "as",
"changes": [
{
"insertMany": {
"collectionName": "countries_json",
"documents": {
"$rawJson": [
{
"_id" : "us",
"name" : "United States",
"exports" : {
"foods" : [
{"name" : "bacon", "tasty" : "true" },
{"name" : "burger"}
]
}
},
{
"_id" : "ca",
"name" : "Canada",
"exports" : {
"foods" : [
{"name" : "bacon", "tasty" : false },
{"name" : "syrup", "tasty" : true}
]
}
},
{
"_id" : "mx",
"name" : "Mexico",
"exports" : {
"foods" : [
{"name" : "salsa", "tasty" : true, "condiment" : true}
]
}
}
]
}
}
}
],
"rollback": {
"runCommand": {
"command": "{ delete: \"countries_json\", deletes: [{q: { }, limit: 0}] }"
}
}
}
},
{
"changeSet": {
"id": "3",
"author": "as",
"changes": [
{
"createIndex": {
"collectionName": "countries_json",
"keys": {
"$rawJson": {
"name": 1,
"type": 1
}
},
"options": {
"$rawJson": {
"unique": true,
"name": "ui_countries_json"
}
}
}
}
]
}
},
{
"changeSet": {
"id": "4",
"author": "as",
"changes": [
{
"createIndex": {
"collectionName": "salesData_json",
"keys": {
"$rawJson": {
"tenantId": 1,
"customFields.$**": 1
}
},
"options": {
"$rawJson": {
"name": "compoundWildcardIndex_json"
}
}
}
}
]
}
}
]
}
Loading
Loading