From e4aa4d0ce068cccd3944d292bb8fdd8e1e495982 Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Fri, 10 Oct 2025 06:57:34 +0100 Subject: [PATCH 1/5] feat: add test to assert dependency injection in rollback --- .../core/e2e/CoreStrategiesE2ETest.java | 49 ++++++++++++++++--- ...SimpleNonTransactionalChangeWithError.java | 45 +++++++++++++++++ .../flamingock/core/e2e/helpers/Counter.java | 22 +++++++++ 3 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java create mode 100644 e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java index bd7f01b90..f4f61280d 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java @@ -17,12 +17,8 @@ import io.flamingock.common.test.pipeline.CodeChangeTestDefinition; import io.flamingock.common.test.pipeline.PipelineTestHelper; -import io.flamingock.core.e2e.changes._006__FailingTransactionalChange; -import io.flamingock.core.e2e.changes._003__MultiTest1NonTransactionalChange; -import io.flamingock.core.e2e.changes._004__MultiTest2TransactionalChange; -import io.flamingock.core.e2e.changes._005__SecondRunNonTransactionalChange; -import io.flamingock.core.e2e.changes._001__SimpleNonTransactionalChange; -import io.flamingock.core.e2e.changes._002__SimpleTransactionalChange; +import io.flamingock.core.e2e.changes.*; +import io.flamingock.core.e2e.helpers.Counter; import io.flamingock.core.kit.audit.AuditTestHelper; import io.flamingock.core.kit.inmemory.InMemoryTestKit; import io.flamingock.core.processor.util.Deserializer; @@ -42,8 +38,7 @@ import static io.flamingock.core.kit.audit.AuditEntryExpectation.FAILED; import static io.flamingock.core.kit.audit.AuditEntryExpectation.ROLLED_BACK; import static io.flamingock.core.kit.audit.AuditEntryExpectation.STARTED; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; class CoreStrategiesE2ETest { @@ -230,4 +225,42 @@ void testAlreadyAppliedChangesSkipping() { APPLIED("test5-second-run-change") ); } + + @Test + @DisplayName("Should inject dependencies in rollback for NON-TX change") + void testDependencyInjectionInRollbackForNonTxChange() { + InMemoryTestKit testKit = InMemoryTestKit.create(); + AuditTestHelper auditHelper = testKit.getAuditHelper(); + + Counter counter = new Counter(); + + NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem( "kafka") + .addDependency(counter); + + try (MockedStatic mocked = Mockito.mockStatic(Deserializer.class)) { + mocked.when(Deserializer::readPreviewPipelineFromFile).thenReturn( + PipelineTestHelper.getPreviewPipeline( + new CodeChangeTestDefinition(_007__SimpleNonTransactionalChangeWithError.class, Collections.emptyList()) + ) + ); + + try { + testKit.createBuilder() + .addTargetSystem(targetSystem) + .build() + .run(); + } catch (PipelineExecutionException e) { + // Exception is expected, do not fail the test + } + } + + assertTrue(counter.executed, "Counter.executed should be true after execution"); + assertTrue(counter.rollbacked, "Counter.rollbacked should be true after rollback"); + + auditHelper.verifyAuditSequenceStrict( + STARTED("test1-non-tx-change"), + FAILED("test1-non-tx-change"), + ROLLED_BACK("test1-non-tx-change") + ); + } } diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java new file mode 100644 index 000000000..45850d2b1 --- /dev/null +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java @@ -0,0 +1,45 @@ +/* + * Copyright 2025 Flamingock (https://www.flamingock.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.flamingock.core.e2e.changes; + +import io.flamingock.api.annotations.Apply; +import io.flamingock.api.annotations.Change; +import io.flamingock.api.annotations.Rollback; +import io.flamingock.api.annotations.TargetSystem; +import io.flamingock.core.e2e.helpers.Counter; + +import javax.inject.Named; + +/** + * Simple non-transactional change for testing core execution strategies. + * Does not require any external dependencies. + */ +@Change(id = "test1-non-tx-change", transactional = false, author = "aperezdieppa") +@TargetSystem(id = "kafka") +public class _007__SimpleNonTransactionalChangeWithError { + + @Apply + public void execution(Counter counter) { + counter.executed = true; + throw new RuntimeException("Intentional failure"); + } + + @Rollback + public void rollback(Counter counter) { + counter.rollbacked = true; + System.out.println("Rolling back failing transactional change"); + } +} \ No newline at end of file diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java new file mode 100644 index 000000000..6a390daf9 --- /dev/null +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java @@ -0,0 +1,22 @@ +/* + * Copyright 2025 Flamingock (https://oss.flamingock.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.flamingock.core.e2e.helpers; + +public class Counter { + public boolean executed = false; + public boolean rollbacked = false; +} From 3ab2b2b186f1f25c29d40d73632246f700f92739 Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Fri, 10 Oct 2025 08:02:48 +0100 Subject: [PATCH 2/5] feat: add test to assert dependency injection in rollback --- .../core/e2e/CoreStrategiesE2ETest.java | 4 ++-- ...SimpleNonTransactionalChangeWithError.java | 4 ++-- .../flamingock/core/e2e/helpers/Counter.java | 21 +++++++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java index f4f61280d..2ecaac776 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java @@ -254,8 +254,8 @@ void testDependencyInjectionInRollbackForNonTxChange() { } } - assertTrue(counter.executed, "Counter.executed should be true after execution"); - assertTrue(counter.rollbacked, "Counter.rollbacked should be true after rollback"); + assertTrue(counter.isExecuted(), "Counter.executed should be true after execution"); + assertTrue(counter.isRollbacked(), "Counter.rollbacked should be true after rollback"); auditHelper.verifyAuditSequenceStrict( STARTED("test1-non-tx-change"), diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java index 45850d2b1..8192c3e21 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java @@ -33,13 +33,13 @@ public class _007__SimpleNonTransactionalChangeWithError { @Apply public void execution(Counter counter) { - counter.executed = true; + counter.setExecuted(true); throw new RuntimeException("Intentional failure"); } @Rollback public void rollback(Counter counter) { - counter.rollbacked = true; + counter.setRollbacked(true); System.out.println("Rolling back failing transactional change"); } } \ No newline at end of file diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java index 6a390daf9..959af4e08 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java @@ -17,6 +17,23 @@ package io.flamingock.core.e2e.helpers; public class Counter { - public boolean executed = false; - public boolean rollbacked = false; + private boolean executed = false; + private boolean rollbacked = false; + + public boolean isExecuted() { + return executed; + } + + public void setExecuted(boolean executed) { + this.executed = executed; + } + + public boolean isRollbacked() { + return rollbacked; + } + + public void setRollbacked(boolean rollbacked) { + this.rollbacked = rollbacked; + } } + From 0fea26589a69c18c43f5a171f2dd43a5ee93a7ce Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Fri, 10 Oct 2025 10:07:32 +0100 Subject: [PATCH 3/5] feat: add test to assert dependency injection in rollback --- .../_007__SimpleNonTransactionalChangeWithError.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java index 8192c3e21..40b062ed4 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/changes/_007__SimpleNonTransactionalChangeWithError.java @@ -15,10 +15,7 @@ */ package io.flamingock.core.e2e.changes; -import io.flamingock.api.annotations.Apply; -import io.flamingock.api.annotations.Change; -import io.flamingock.api.annotations.Rollback; -import io.flamingock.api.annotations.TargetSystem; +import io.flamingock.api.annotations.*; import io.flamingock.core.e2e.helpers.Counter; import javax.inject.Named; @@ -32,13 +29,13 @@ public class _007__SimpleNonTransactionalChangeWithError { @Apply - public void execution(Counter counter) { + public void execution(@NonLockGuarded Counter counter) { counter.setExecuted(true); throw new RuntimeException("Intentional failure"); } @Rollback - public void rollback(Counter counter) { + public void rollback(@NonLockGuarded Counter counter) { counter.setRollbacked(true); System.out.println("Rolling back failing transactional change"); } From 6929e0c598975e3e695eb2a59ad0c7a8454e24cb Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Fri, 10 Oct 2025 10:19:01 +0100 Subject: [PATCH 4/5] feat: add test to assert dependency injection in rollback --- .../src/test/java/io/flamingock/core/e2e/helpers/Counter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java index 959af4e08..69035d225 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/helpers/Counter.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 Flamingock (https://oss.flamingock.io) + * Copyright 2025 Flamingock (https://www.flamingock.io) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.flamingock.core.e2e.helpers; public class Counter { From 7a99dc66b29dba4df908cfc2c05d623d97153954 Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Fri, 10 Oct 2025 10:48:55 +0100 Subject: [PATCH 5/5] feat: add test to assert dependency injection in rollback --- .../io/flamingock/core/e2e/CoreStrategiesE2ETest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java index 2ecaac776..e45432c50 100644 --- a/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java +++ b/e2e/core-e2e/src/test/java/io/flamingock/core/e2e/CoreStrategiesE2ETest.java @@ -234,7 +234,7 @@ void testDependencyInjectionInRollbackForNonTxChange() { Counter counter = new Counter(); - NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem( "kafka") + NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem("kafka") .addDependency(counter); try (MockedStatic mocked = Mockito.mockStatic(Deserializer.class)) { @@ -244,14 +244,15 @@ void testDependencyInjectionInRollbackForNonTxChange() { ) ); - try { + PipelineExecutionException exception = assertThrows(PipelineExecutionException.class, () -> { testKit.createBuilder() .addTargetSystem(targetSystem) .build() .run(); - } catch (PipelineExecutionException e) { - // Exception is expected, do not fail the test - } + }); + + assertNotNull(exception); + assertTrue(exception.getMessage().contains("Intentional failure")); } assertTrue(counter.isExecuted(), "Counter.executed should be true after execution");