Skip to content

Conversation

momosetkn
Copy link
Contributor

@momosetkn momosetkn commented Aug 27, 2024

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

#5422
#6061

this bug is CustomTaskRollback twice call rollback.
fix to call once by this PR.

Things to be aware of

Things to worry about

I fixed bug. but I think it's better to avoid the global variable Scope.getCurrentScope...because it's implicit.

Additional Context

Comment on lines +195 to 206
boolean shouldExecute = Scope.getCurrentScope().get(Change.SHOULD_EXECUTE, Boolean.TRUE);
try {
configureCustomChange();
if (customChange instanceof CustomSqlRollback) {
statements = ((CustomSqlRollback) customChange).generateRollbackStatements(database);
} else if (customChange instanceof CustomTaskRollback) {
((CustomTaskRollback) customChange).rollback(database);
} else {
throw new RollbackImpossibleException("Unknown rollback type: " + customChange.getClass().getName());
if (shouldExecute) {
if (customChange instanceof CustomSqlRollback) {
statements = ((CustomSqlRollback) customChange).generateRollbackStatements(database);
} else if (customChange instanceof CustomTaskRollback) {
((CustomTaskRollback) customChange).rollback(database);
} else {
throw new RollbackImpossibleException("Unknown rollback type: " + customChange.getClass().getName());
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -565,17 +566,22 @@ public void testUpdateClearUpdate() throws Exception {

@Test
@SuppressWarnings("squid:S2699") // Successful execution qualifies as test success.
public void testRollbackableChangeLog() throws Exception {
public synchronized void testRollbackableChangeLog() throws Exception {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure add synchronized, for static property executeCallCount and rollbackCallCount.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test, I'm not sure to understand why it would need a sync keyword. I don't think this is needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to care for static property?
maybe, alternative way was check call count the execute and rollback method with Mockito. I think that's the way to do it politely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found alternative way. it is Check ExampleCustomTaskChange with executed liquibase.getDatabaseChangeLog().getChangeSets().
I will try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        List<CustomChange> customChanges = liquibase.getDatabaseChangeLog().getChangeSets().stream().flatMap(changeSet ->
                changeSet.getChanges().stream().filter(change ->
                        change instanceof CustomChangeWrapper &&
                                ((CustomChangeWrapper) change).getCustomChange() instanceof ExampleCustomTaskChange
                ).map(change ->
                        ((CustomChangeWrapper) change).getCustomChange())
        ).collect(Collectors.toList());
        for (CustomChange customChange : customChanges) {
            assertEquals(1, ((ExampleCustomTaskChange)customChange).executeCallCount);
            assertEquals(0, ((ExampleCustomTaskChange)customChange).rollbackCallCount);
        }

I wrote this code. but cannot check call-count, actual value is 0. because, difference ExampleCustomTaskChange object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest making ExampleCustomTaskChange a singleton class, and then checking rollbackcount but I think this won't help with this issue. Let me ask tomorrow one of our team members with more experience/knowledge on custom changes because my guess is rollback is executing twice because there might be something else calling also this same method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @momosetkn,

I was talking about this with someone else from the team, and we agreed that synchronized keyword is not needed there. To validate counts, we think maybe what we can do here is to have a map and save your ExampleCustomTaskChange instances there, then save this map in the current scope. I was thinking of adding something like this in CustomChangeWrapper, but I'm unsure if this is the right place. It would probably be if some other custom changes implement something like this, but for now, we can probably do this in the scope you were trying to do this validation.

Thanks,
Daniel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, ThreadLocal(map in the current scope) can resolve synchronous problem.
I fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MalloD12
Sorry for the late fix.
I fixed.

@momosetkn momosetkn changed the title fix custom task rollback dupplicate call rollback bug fix CustomTaskRollback dupplicate call rollback bug Aug 27, 2024
@momosetkn momosetkn changed the title fix CustomTaskRollback dupplicate call rollback bug fix CustomTaskRollback twice call rollback bug Aug 27, 2024
@momosetkn momosetkn marked this pull request as ready for review August 27, 2024 15:00
@MalloD12 MalloD12 self-requested a review September 12, 2024 20:20
@momosetkn
Copy link
Contributor Author

@MalloD12
Run FOSSA Test is failed, What should I do? I don't know the cause for failed github-actions.

@MalloD12
Copy link
Collaborator

@MalloD12 Run FOSSA Test is failed, What should I do? I don't know the cause for failed github-actions.

Hi @momosetkn,

Don't worry by this FOSSA check failing, that's a known issue for our devOps team and it's not related to this change.

assertEquals(1, (int)executeCallCountInteger);
assertEquals(0, (int)rollbackCallCount);

liquibase = createLiquibase(rollbackChangeLog);
Copy link
Collaborator

@MalloD12 MalloD12 Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @momosetkn we don't need to create several liquibase instances if they are all using the same changelog. I would leave only one of these.

That's my only suggestion to update on this test.

Thanks,
Daniel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I fixed!

Copy link
Collaborator

@MalloD12 MalloD12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Code changes and test looks good to me.

Thank you, @momosetkn!

Copy link
Collaborator

@filipelautert filipelautert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @momosetkn !

@wwillard7800 could you review it too?

Copy link
Contributor

@tati-qalified tati-qalified left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for your contribution @momosetkn!

@filipelautert filipelautert added this to the 1NEXT milestone Oct 24, 2024
@filipelautert filipelautert merged commit c492c43 into liquibase:master Oct 24, 2024
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants