Skip to content

feat: Add integration test: Capabilities reconnect after router restart#85

Open
matheusandre1 wants to merge 3 commits into
wanaku-ai:mainfrom
matheusandre1:issue66
Open

feat: Add integration test: Capabilities reconnect after router restart#85
matheusandre1 wants to merge 3 commits into
wanaku-ai:mainfrom
matheusandre1:issue66

Conversation

@matheusandre1
Copy link
Copy Markdown

@matheusandre1 matheusandre1 commented Apr 2, 2026

Closes: #66

Summary by Sourcery

Add a new cross-capability integration test module that verifies Wanaku capabilities reconnect after a router restart and update documentation to describe the new tests and test structure.

New Features:

  • Introduce a cross-capability test module that exercises HTTP, file provider, and Camel capabilities together.
  • Add RouterReconnectionITCase to validate that all capabilities and their tools/resources persist and reconnect after a router restart.

Enhancements:

  • Refine HTTP capability, resources, and root README files to document the new cross-capability tests and clarify existing test classes and infrastructure.

Tests:

  • Add CrossCapabilityTestBase to manage lifecycles of multiple capabilities and router restarts for shared cross-capability tests.

Copy link
Copy Markdown
Contributor

@orpiske orpiske left a comment

Choose a reason for hiding this comment

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

LGTM, although I'd prefer smaller test methods ... but let's wait for the review from @lnearlol

@lnearlol
Copy link
Copy Markdown
Contributor

lnearlol commented Apr 4, 2026

Hi @matheusandre1
Thanks a lot for your contribution! It's much appreciated.

I can see that your branch is behind main. Can you please rebase it?

Here are a few things I noticed during the review:

  1. The test uses TestFixtures.load("simple-tool", ...) but the simple-tool fixtures live in camel-integration-capability-tests/src/test/resources/fixtures/, not in http-capability-tests. Running the test gives: IllegalArgumentException: Fixture directory not found on classpath: fixtures/simple-tool To fix this add please fixtures/simple-tool to resources

  2. This test exercises HTTP capability, resource provider, and Camel integration capability together. It doesn't belong in http-capability-tests which is scoped to HTTP-only scenarios.
    We should create a new cross-capability-tests module for tests like this, with its own CrossCapabilityTestBase that manages lifecycle and cleanup of all capability types.

  3. Can you please confirm that capabilities will reconnect when the router restarts on different ports? prepare() allocates new ports, but capabilities were configured with the old ones. So seems reconnect should fail this way. Probably router should start on the same port.

  4. Since we want to create new module, we can leave old Readme.md for http-capability-tests and just add new one to cross-capability-tests module.

Regarding smaller test size, I think we can reduce it little bit by putting #all cleaning methods to CrossCapabilityTestBase.

Also, the test could be split into separate test methods, like this:

      startAllCapabilities();                                                                                                                                                                                
      registerToolsAndResources();                                                                                                                                                                           
      verifyAllRegistered();                                                                                                                                                                                                                                                                                                                                                              
      restartRouter();                                                                                                                                                                                                                                                                                                                                                                                      
      verifyAllReconnected();  

to make it more readable.
But I'd prefer to keep it in one test because it has a clear logical flow. Connect all types of capabilities to router - crush the router - run router again - check everything is reconnected. I think that it's important not to split it into more tests with just one capability, because it provides a more comprehensive scenario for the router.

The test scenario itself is great and we definitely need reconnection testing! Thank you @matheusandre1!
Let me know if you have any questions.

@matheusandre1
Copy link
Copy Markdown
Author

Thanks for feedback, That's pretty self-explanatory, I'll adjust that this week.

@lnearlol
Copy link
Copy Markdown
Contributor

Hi @matheusandre1 because PR is Draft, I've just noticed that it was changed. PR is almost perfect now. For me it fails because keycloak configuration (wanaku-realm.json) is missing in the new module.

Put please those 2 files (wanaku-realm.json and logback-test.xml) in the new module.

Also I think PR need to be changed little bit to follow those changes #91 and it also needs to be rebased one more time. And test could be merged after that. So you can change the status from Draft to Open.

Thank you for the contribution! It's a really needed one ;)

@matheusandre1 matheusandre1 marked this pull request as ready for review April 10, 2026 17:19
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 10, 2026

Reviewer's Guide

Adds a new cross-capability test module that verifies HTTP, file, and Camel capabilities automatically reconnect to the Wanaku router after a router restart, and updates documentation to describe the new tests and infrastructure.

Sequence diagram for router restart and capabilities reconnection test

sequenceDiagram
    participant JUnitRunner
    participant RouterReconnectionITCase
    participant CrossCapabilityTestBase
    participant WanakuRouter
    participant HttpCapability
    participant ResourceCapability
    participant CamelCapability

    JUnitRunner->>RouterReconnectionITCase: runTests()
    RouterReconnectionITCase->>CrossCapabilityTestBase: setUpEnvironment()
    CrossCapabilityTestBase->>WanakuRouter: startRouter()
    CrossCapabilityTestBase->>HttpCapability: connectToRouter()
    CrossCapabilityTestBase->>ResourceCapability: connectToRouter()
    CrossCapabilityTestBase->>CamelCapability: connectToRouter()

    RouterReconnectionITCase->>HttpCapability: verifyInitialHttpToolInvocation()
    RouterReconnectionITCase->>ResourceCapability: verifyInitialResourceAccess()
    RouterReconnectionITCase->>CamelCapability: verifyInitialCamelToolInvocation()

    RouterReconnectionITCase->>WanakuRouter: restartRouter()
    WanakuRouter-->>HttpCapability: connectionLost()
    WanakuRouter-->>ResourceCapability: connectionLost()
    WanakuRouter-->>CamelCapability: connectionLost()

    HttpCapability->>WanakuRouter: reconnect()
    ResourceCapability->>WanakuRouter: reconnect()
    CamelCapability->>WanakuRouter: reconnect()

    RouterReconnectionITCase->>HttpCapability: verifyHttpToolInvocationAfterRestart()
    RouterReconnectionITCase->>ResourceCapability: verifyResourceAccessAfterRestart()
    RouterReconnectionITCase->>CamelCapability: verifyCamelToolInvocationAfterRestart()

    RouterReconnectionITCase->>CrossCapabilityTestBase: tearDownEnvironment()
    CrossCapabilityTestBase->>WanakuRouter: stopRouter()
    RouterReconnectionITCase-->>JUnitRunner: reportSuccess()
Loading

Updated class diagram for cross-capability router reconnection tests

classDiagram
    class CrossCapabilityTestBase {
        <<abstract>>
        - WanakuRouter router
        - HttpCapabilityClient httpClient
        - ResourceCapabilityClient resourceClient
        - CamelCapabilityClient camelClient
        + setUpEnvironment()
        + tearDownEnvironment()
        + startRouter()
        + stopRouter()
        + createHttpClient()
        + createResourceClient()
        + createCamelClient()
    }

    class RouterReconnectionITCase {
        + RouterReconnectionITCase()
        + verifyHttpReconnection()
        + verifyResourceReconnection()
        + verifyCamelReconnection()
        + verifyMixedFlowAfterRestart()
    }

    class WanakuRouter {
        + start()
        + stop()
        + restart()
    }

    class HttpCapabilityClient {
        + connect()
        + invokeTool(toolName, payload)
    }

    class ResourceCapabilityClient {
        + connect()
        + listResources()
        + readResource(path)
    }

    class CamelCapabilityClient {
        + connect()
        + invokeRoute(routeId, payload)
    }

    CrossCapabilityTestBase <|-- RouterReconnectionITCase
    CrossCapabilityTestBase --> WanakuRouter
    CrossCapabilityTestBase --> HttpCapabilityClient
    CrossCapabilityTestBase --> ResourceCapabilityClient
    CrossCapabilityTestBase --> CamelCapabilityClient
Loading

File-Level Changes

Change Details Files
Introduce shared cross-capability test base to manage file provider and Camel capability lifecycles and router restart semantics.
  • Create CrossCapabilityTestBase extending BaseIntegrationTest with setup/teardown hooks for multi-capability scenarios.
  • Add helper methods to start/stop the file resource provider and Camel capability, including Awaitility-based registration checks.
  • Implement router restart helper that enforces restart on the same ports and reinitializes RouterClient.
  • Provide utilities for clearing router state, creating test files, checking artifact availability, and retrieving OIDC tokens.
  • Override logging profile to use a dedicated cross-capability profile.
cross-capability-tests/src/test/java/ai/wanaku/test/cross/CrossCapabilityTestBase.java
Add RouterReconnection integration test that exercises router restart and verifies reconnection and state persistence for HTTP, file, and Camel capabilities.
  • Guard test execution with availability assumptions for router, HTTP capability, file provider, and Camel capability artifacts.
  • Start file provider and Camel capability using the shared base helpers and register an HTTP tool plus file resource via RouterClient.
  • Assert initial registration of all relevant capabilities, tools, and resources using Awaitility and AssertJ.
  • Restart the router on the same ports and rebuild RouterClient using CrossCapabilityTestBase helper.
  • Verify all capabilities reconnect and previously registered tools and resources remain available after restart.
cross-capability-tests/src/test/java/ai/wanaku/test/cross/RouterReconnectionITCase.java
Create new Maven module and resources for cross-capability tests driven by a simple Camel fixture.
  • Add cross-capability-tests module to the parent POM modules list.
  • Define cross-capability-tests/pom.xml with test-common, Quarkus JUnit, AssertJ, and Logback dependencies plus Surefire configuration and artifacts dir property.
  • Add Camel fixture files (routes.camel.yaml and rules.yaml) under src/test/resources/fixtures/simple-tool for simple-greeting and parameterized tools.
  • Configure CrossCapabilityTestBase to load fixtures into target/test-fixtures via TestFixtures utility.
pom.xml
cross-capability-tests/pom.xml
cross-capability-tests/src/test/resources/fixtures/simple-tool/routes.camel.yaml
cross-capability-tests/src/test/resources/fixtures/simple-tool/rules.yaml
Document the new cross-capability tests and expand existing test READMEs to describe the new scenarios and infrastructure.
  • Retitle http-capability-tests README and replace content with detailed descriptions of each test class, especially RouterReconnectionITCase and its reconnection steps, expected behavior, scope, prerequisites, and infrastructure.
  • Update top-level README to add cross-capability-tests module, describe router restart flows, and link to its README, replacing the previous "planned" integration tests note.
  • Extend resources-tests README to document test-specific resources and clarify lifecycle details.
  • Create cross-capability-tests/README.md documenting prerequisites, execution commands, architecture, lifecycle, and fixtures used by the new tests.
http-capability-tests/README.md
README.md
resources-tests/README.md
cross-capability-tests/README.md

Assessment against linked issues

Issue Objective Addressed Explanation
#66 Implement an integration test that starts the Wanaku router, HTTP capability, resource provider, and Camel integration capability, then restarts the router and verifies that all capabilities/tools/resources automatically reconnect and remain available.
#66 Integrate the new router-reconnection integration test into the test suite and documentation so it can be built and run as part of the project.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The README and test descriptions say the router is restarted on new ports, but restartRouterWithSamePorts explicitly enforces reuse of the same ports and throws if they change—consider aligning the documentation with the actual behavior or adjusting the implementation to truly support a port change scenario.
  • CrossCapabilityTestBase assumes a fresh ResourceProviderManager/CamelCapabilityManager per test; if these methods are ever called multiple times within a single test, prior instances could be overwritten without being stopped—consider adding guards or explicit stop logic before reassigning the managers to make the lifecycle more robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The README and test descriptions say the router is restarted on new ports, but `restartRouterWithSamePorts` explicitly enforces reuse of the same ports and throws if they change—consider aligning the documentation with the actual behavior or adjusting the implementation to truly support a port change scenario.
- `CrossCapabilityTestBase` assumes a fresh `ResourceProviderManager`/`CamelCapabilityManager` per test; if these methods are ever called multiple times within a single test, prior instances could be overwritten without being stopped—consider adding guards or explicit stop logic before reassigning the managers to make the lifecycle more robust.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Add integration test: Capabilities reconnect after router restart

3 participants