Skip to content

CAMEL-24189: camel-smb - Fix SmbStreamDownloadIT reading stream after close#24818

Merged
davsclaus merged 1 commit into
mainfrom
fix/CAMEL-24189
Jul 16, 2026
Merged

CAMEL-24189: camel-smb - Fix SmbStreamDownloadIT reading stream after close#24818
davsclaus merged 1 commit into
mainfrom
fix/CAMEL-24189

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

Claude Code on behalf of davsclaus

Summary

The SmbStreamDownloadIT.testStreamDownload test was reading the InputStream body after mock.assertIsSatisfied(), but by that point GenericFileOnCompletion has already fired processStrategy.commit() which calls releaseRetrievedFileResources() — closing the SmbFileClosingInputStream and its underlying SMB file handle. Reading a closed stream returns empty content.

Fix: move the stream reading and assertions into a process() step inside the route where the stream is still open. The content is stashed in a header and verified after assertIsSatisfied().

Test plan

  • SmbStreamDownloadIT passes (was failing consistently with expected: <World\n> but was: <>)

🤖 Generated with Claude Code

… close

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, well-targeted fix. The root cause analysis is spot-on.

Analysis

The issue is a lifecycle timing problem: GenericFileOnCompletion.onComplete() fires after the route completes (via processStrategyCommit()processStrategy.commit()), which for stream-downloaded files closes the underlying SMB file handle. By the time the test calls mock.getExchanges().get(0).getIn().getBody(InputStream.class), the stream is already closed — IOHelper.loadText() reads zero bytes, producing an empty string.

The fix correctly moves stream consumption into a .process() step within the route, where the stream is guaranteed to be open. Stashing the content in a header for post-route verification is a well-established pattern in Camel tests.

Verified

  • GenericFileOnCompletion.processStrategyCommit() calls processStrategy.commit(operations, endpoint, exchange, file) at line 137 — confirmed this closes the file resources
  • assertInstanceOf calls inside process() properly verify body types (SmbFile wrapping InputStream)
  • ✅ No Thread.sleep() introduced
  • ✅ Imports are clean — removed unused Assertions/assertNotNull, added used assertEquals/assertInstanceOf
  • ✅ This likely resolves the camel-smb integration test failures observed in CI runs for other recent PRs

Checklist

Check Status
Tests ✅ This IS the test fix
Thread.sleep() ✅ None
Commit convention CAMEL-24189: format
Public API N/A (test-only)
Documentation N/A

Reviewed with Claude Code on behalf of gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

@davsclaus davsclaus added this to the 4.22.0 milestone Jul 16, 2026
@davsclaus davsclaus added the bug Something isn't working label Jul 16, 2026
@davsclaus davsclaus self-assigned this Jul 16, 2026
@davsclaus
davsclaus merged commit 5998b5f into main Jul 16, 2026
5 checks passed
@davsclaus
davsclaus deleted the fix/CAMEL-24189 branch July 16, 2026 20:49
@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-smb

🔬 Scalpel shadow comparison — Scalpel: 1 tested, 0 compile-only — current: 9 all tested

Maveniverse Scalpel detected 1 affected modules (current approach: 9).

Modules only in current approach (8)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin

Skip-tests mode would test 1 modules (1 direct + 0 downstream), skip tests for 0 (generated code, meta-modules)

Modules Scalpel would test (1)
  • camel-smb

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (9 modules)
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher :: Container
  • Camel :: SMB
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

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

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants