|
30 | 30 | import io.flamingock.store.couchbase.CouchbaseAuditStore; |
31 | 31 | import io.flamingock.internal.common.core.response.data.ErrorInfo; |
32 | 32 | import io.flamingock.internal.common.couchbase.CouchbaseCollectionHelper; |
33 | | -import io.flamingock.internal.core.builder.FlamingockFactory; |
34 | 33 | import io.flamingock.internal.core.builder.runner.Runner; |
35 | 34 | import io.flamingock.internal.core.operation.StagedExecuteOperationException; |
36 | 35 | import io.flamingock.internal.util.constants.CommunityPersistenceConstants; |
|
53 | 52 | import static io.flamingock.core.kit.audit.AuditEntryExpectation.APPLIED; |
54 | 53 | import static io.flamingock.core.kit.audit.AuditEntryExpectation.STARTED; |
55 | 54 | import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY; |
| 55 | +import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_IGNORE_UNKNOWN_AUDIT_ENTRIES_PROPERTY_KEY; |
56 | 56 | import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_ORIGIN_PROPERTY_KEY; |
57 | 57 | import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_SKIP_PROPERTY_KEY; |
58 | 58 | import static io.flamingock.internal.util.constants.AuditEntryFieldConstants.KEY_CREATED_AT; |
@@ -320,6 +320,108 @@ void GIVEN_allMongockChangeUnitsAlreadyExecutedAndCustomOriginProvided_WHEN_migr |
320 | 320 |
|
321 | 321 | } |
322 | 322 |
|
| 323 | + @Test |
| 324 | + @DisplayName("GIVEN Mongock audit history contains unknown entries " + |
| 325 | + "AND relaxed import flag is not provided " + |
| 326 | + "WHEN migrating to Flamingock Community " + |
| 327 | + "THEN should fail with the current strict validation") |
| 328 | + void GIVEN_unknownAuditEntriesAndImplicitStrictMode_WHEN_migratingToFlamingockCommunity_THEN_shouldFail() { |
| 329 | + Collection originCollection = cluster.bucket(MONGOCK_BUCKET_NAME).scope(MONGOCK_SCOPE_NAME).collection(MONGOCK_COLLECTION_NAME); |
| 330 | + |
| 331 | + originCollection.upsert("mongock-change-1", createAuditObject("mongock-change-1")); |
| 332 | + originCollection.upsert("foreign-change-1", createAuditObject("foreign-change-1", false, "io.example.foreign.ForeignChangeUnit", "apply")); |
| 333 | + |
| 334 | + CouchbaseTargetSystem targetSystem = new CouchbaseTargetSystem("couchbase-target-system", cluster, FLAMINGOCK_BUCKET_NAME); |
| 335 | + |
| 336 | + Runner flamingock = testKit.createBuilder() |
| 337 | + .setAuditStore(auditStore) |
| 338 | + .addTargetSystem(targetSystem) |
| 339 | + .build(); |
| 340 | + |
| 341 | + StagedExecuteOperationException ex = assertThrows(StagedExecuteOperationException.class, flamingock::run); |
| 342 | + assertEquals("Error importing audit entry with changeId[foreign-change-1]: no matching change was found in the current Flamingock pipeline.", |
| 343 | + firstFailedStageErrorMessage(ex)); |
| 344 | + } |
| 345 | + |
| 346 | + @Test |
| 347 | + @DisplayName("GIVEN Mongock audit history contains unknown entries " + |
| 348 | + "AND relaxed import flag is explicitly disabled " + |
| 349 | + "WHEN migrating to Flamingock Community " + |
| 350 | + "THEN should fail with the current strict validation") |
| 351 | + void GIVEN_unknownAuditEntriesAndExplicitStrictMode_WHEN_migratingToFlamingockCommunity_THEN_shouldFail() { |
| 352 | + Collection originCollection = cluster.bucket(MONGOCK_BUCKET_NAME).scope(MONGOCK_SCOPE_NAME).collection(MONGOCK_COLLECTION_NAME); |
| 353 | + |
| 354 | + originCollection.upsert("mongock-change-1", createAuditObject("mongock-change-1")); |
| 355 | + originCollection.upsert("foreign-change-1", createAuditObject("foreign-change-1", false, "io.example.foreign.ForeignChangeUnit", "apply")); |
| 356 | + |
| 357 | + CouchbaseTargetSystem targetSystem = new CouchbaseTargetSystem("couchbase-target-system", cluster, FLAMINGOCK_BUCKET_NAME); |
| 358 | + |
| 359 | + Runner flamingock = testKit.createBuilder() |
| 360 | + .setAuditStore(auditStore) |
| 361 | + .addTargetSystem(targetSystem) |
| 362 | + .setProperty(MONGOCK_IMPORT_IGNORE_UNKNOWN_AUDIT_ENTRIES_PROPERTY_KEY, Boolean.FALSE.toString()) |
| 363 | + .build(); |
| 364 | + |
| 365 | + StagedExecuteOperationException ex = assertThrows(StagedExecuteOperationException.class, flamingock::run); |
| 366 | + assertEquals("Error importing audit entry with changeId[foreign-change-1]: no matching change was found in the current Flamingock pipeline.", |
| 367 | + firstFailedStageErrorMessage(ex)); |
| 368 | + } |
| 369 | + |
| 370 | + @Test |
| 371 | + @DisplayName("GIVEN Mongock audit history contains unknown entries " + |
| 372 | + "AND relaxed import flag is enabled " + |
| 373 | + "WHEN migrating to Flamingock Community " + |
| 374 | + "THEN should skip the unknown entries and continue") |
| 375 | + void GIVEN_unknownAuditEntriesAndRelaxedMode_WHEN_migratingToFlamingockCommunity_THEN_shouldSkipUnknownEntries() { |
| 376 | + Collection originCollection = cluster.bucket(MONGOCK_BUCKET_NAME).scope(MONGOCK_SCOPE_NAME).collection(MONGOCK_COLLECTION_NAME); |
| 377 | + |
| 378 | + originCollection.upsert("mongock-change-1", createAuditObject("mongock-change-1")); |
| 379 | + originCollection.upsert("foreign-change-1", createAuditObject("foreign-change-1", false, "io.example.foreign.ForeignChangeUnit", "apply")); |
| 380 | + |
| 381 | + CouchbaseTargetSystem targetSystem = new CouchbaseTargetSystem("couchbase-target-system", cluster, FLAMINGOCK_BUCKET_NAME); |
| 382 | + |
| 383 | + Runner flamingock = testKit.createBuilder() |
| 384 | + .setAuditStore(auditStore) |
| 385 | + .addTargetSystem(targetSystem) |
| 386 | + .setProperty(MONGOCK_IMPORT_IGNORE_UNKNOWN_AUDIT_ENTRIES_PROPERTY_KEY, Boolean.TRUE.toString()) |
| 387 | + .build(); |
| 388 | + |
| 389 | + flamingock.run(); |
| 390 | + |
| 391 | + auditHelper.verifyAuditSequenceStrict( |
| 392 | + APPLIED("mongock-change-1"), |
| 393 | + STARTED("migration-mongock-to-flamingock-community"), |
| 394 | + APPLIED("migration-mongock-to-flamingock-community"), |
| 395 | + STARTED("mongock-change-2"), |
| 396 | + APPLIED("mongock-change-2"), |
| 397 | + STARTED("flamingock-change"), |
| 398 | + APPLIED("flamingock-change") |
| 399 | + ); |
| 400 | + } |
| 401 | + |
| 402 | + @Test |
| 403 | + @DisplayName("GIVEN relaxed import flag with invalid value " + |
| 404 | + "WHEN migrating to Flamingock Community " + |
| 405 | + "THEN should throw exception") |
| 406 | + void GIVEN_relaxedImportFlagWithInvalidValue_WHEN_migratingToFlamingockCommunity_THEN_shouldThrowException() { |
| 407 | + Collection originCollection = cluster.bucket(MONGOCK_BUCKET_NAME).scope(MONGOCK_SCOPE_NAME).collection(MONGOCK_COLLECTION_NAME); |
| 408 | + originCollection.upsert("foreign-change-1", createAuditObject("foreign-change-1", false, "io.example.foreign.ForeignChangeUnit", "apply")); |
| 409 | + |
| 410 | + final String flagValue = "invalid_value"; |
| 411 | + |
| 412 | + CouchbaseTargetSystem targetSystem = new CouchbaseTargetSystem("couchbase-target-system", cluster, FLAMINGOCK_BUCKET_NAME); |
| 413 | + |
| 414 | + Runner flamingock = testKit.createBuilder() |
| 415 | + .setAuditStore(auditStore) |
| 416 | + .addTargetSystem(targetSystem) |
| 417 | + .setProperty(MONGOCK_IMPORT_IGNORE_UNKNOWN_AUDIT_ENTRIES_PROPERTY_KEY, flagValue) |
| 418 | + .build(); |
| 419 | + |
| 420 | + StagedExecuteOperationException ex = assertThrows(StagedExecuteOperationException.class, flamingock::run); |
| 421 | + assertEquals("Invalid value for " + MONGOCK_IMPORT_IGNORE_UNKNOWN_AUDIT_ENTRIES_PROPERTY_KEY + ": " + flagValue |
| 422 | + + " (expected \"true\" or \"false\" or empty)", firstFailedStageErrorMessage(ex)); |
| 423 | + } |
| 424 | + |
323 | 425 | @Test |
324 | 426 | @DisplayName("GIVEN skip import flag with invalid value " + |
325 | 427 | "WHEN migrating to Flamingock Community" + |
@@ -481,20 +583,24 @@ private List<JsonObject> getAuditLog() { |
481 | 583 | } |
482 | 584 |
|
483 | 585 | private static JsonObject createAuditObject(String value) { |
| 586 | + return createAuditObject(value, true, "io.flamingock.changelog.Class1", "method1"); |
| 587 | + } |
| 588 | + |
| 589 | + private static JsonObject createAuditObject(String value, boolean systemChange, String changeLogClass, String changeSetMethod) { |
484 | 590 | JsonObject doc = JsonObject.create() |
485 | 591 | .put("executionId", "exec-1") |
486 | 592 | .put("changeId", value) |
487 | 593 | .put("author", "author1") |
488 | 594 | .put("timestamp", Instant.now().toEpochMilli()) |
489 | 595 | .put("state", "EXECUTED") |
490 | 596 | .put("type", "EXECUTION") |
491 | | - .put("changeLogClass", "io.flamingock.changelog.Class1") |
492 | | - .put("changeSetMethod", "method1") |
| 597 | + .put("changeLogClass", changeLogClass) |
| 598 | + .put("changeSetMethod", changeSetMethod) |
493 | 599 | .putNull("metadata") |
494 | 600 | .put("executionMillis", 123L) |
495 | 601 | .put("executionHostName", "host1") |
496 | 602 | .putNull("errorTrace") |
497 | | - .put("systemChange", true) |
| 603 | + .put("systemChange", systemChange) |
498 | 604 | .put("_doctype", "mongockChangeEntry"); |
499 | 605 | return doc; |
500 | 606 | } |
|
0 commit comments