Skip to content

Conversation

@jonenst
Copy link
Contributor

@jonenst jonenst commented Sep 25, 2025

No longer block the tomcat thread when waiting for import or export (servlet 3.0+ AsyncContext)

Add no timeout configuration to behave like before this change

Spring forces us to adapt the tests with boilerplate code (asyncStarted() and asyncDispatch()) as per
https://docs.spring.io/spring-framework/reference/testing/mockmvc/hamcrest/async-requests.html
to mimic the servlet 3.0 redispatch

We avoid to store the return of the first perform in an MvcResult variable to avoid confusion (
The two mvc result represent the same request, inside they hold the same request/response
objects, but some other fields are different (asyncResult for example) and tests may
be unreliable if they use the first one (representing the state before the async split)
)

…er the computations

This requires to reorganize the code and the transactions the fully load the data,
hence the changes in NetworkModificationRepository with the new intermediate methods.

Add testInsertCompositeModifications for symmetry with other code paths duplicate/move/
in the switch/case of ModificationController ?action=...
…servlet 3.0+ AsyncContext)

Add no timeout configuration to behave like before this change

Spring forces us to adapt the tests with boilerplate code (asyncStarted() and asyncDispatch()) as per
https://docs.spring.io/spring-framework/reference/testing/mockmvc/hamcrest/async-requests.html
to mimic the servlet 3.0 redispatch
Add more andReturn and assignement to variables to avoid potential mistakes
The two mvc result represent the same request, inside they hold the same request/response
objects, but some other fields are different (asyncResult for example) and tests may
be unreliable if they use the first one (representing the state before the async split)
@jonenst
Copy link
Contributor Author

jonenst commented Oct 14, 2025

example of parallel schedule in NetworkModificationService (drop in replacement in scheduleApplyModifications)

private static CompletableFuture<Void> scheduleApplyModifications(
        Function<ModificationApplicationContext, CompletableFuture<Optional<NetworkModificationResult>>> func,
        List<ModificationApplicationContext> applicationContexts,
        List<CompletableFuture<Optional<NetworkModificationResult>>> results) {
    return CompletableFuture.completedFuture(null).thenCompose(unused -> {
        for (ModificationApplicationContext applicationContext : applicationContexts) {
            var cf = func.apply(applicationContext);
            results.add(cf);
        }
        return CompletableFuture.allOf(results.toArray(new CompletableFuture[0]));
    });
}

Behaves the same with respect to exceptions (completes execeptionally, doesn't throw)

@jonenst jonenst force-pushed the applysamethreadflush branch from 621c489 to 7d5828e Compare October 15, 2025 08:49
Base automatically changed from applysamethreadflush to main October 15, 2025 13:25
@SlimaneAmar
Copy link
Contributor

when waiting for import or export ?

}
}

public NetworkModificationResult applyModificationsBlocking(ModificationApplicationGroup modificationInfosGroup, NetworkInfos networkInfos) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this code in a test class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch thanks

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants