-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix CustomTaskRollback twice call rollback bug #6266
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
fix CustomTaskRollback twice call rollback bug #6266
Conversation
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()); | ||
} | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@MalloD12 |
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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?
There was a problem hiding this 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!
Impact
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