Skip to content

test(amber): add unit test coverage for InputManager - #5451

Merged
aglinxinyuan merged 2 commits into
apache:mainfrom
aglinxinyuan:test-input-manager-spec
Jun 7, 2026
Merged

aglinxinyuan merged 2 commits into
apache:mainfrom
aglinxinyuan:test-input-manager-spec

Conversation

@aglinxinyuan

@aglinxinyuan aglinxinyuan commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Pin behavior of InputManager — the per-worker input broker that was the only previously-uncovered module in the messaginglayer package (every sibling — WorkerPort, OutputManager, AmberFIFOChannel, CongestionControl, FlowControl, NetworkInputGateway, OrderingEnforcer, RangeBasedShuffle — already has a spec). No production-code changes.

Spec Source class Tests
InputManagerSpec InputManager 15

Spec file name follows the <srcClassName>Spec.scala one-to-one convention.

Behavior pinned

Surface Contract
getAllPorts (fresh) empty Set
addPort(portId, schema, Nil, Nil) registers a fresh WorkerPort with the supplied schema; no reader threads attached
second addPort for the same portId silently no-ops (first call wins; the prior WorkerPort survives, including any mutation to completed)
addPort with mismatched URI / partitioning sizes throws AssertionError
getPort(portId) is a pure lookup — successive calls return the same WorkerPort instance
getInputPortReaderThreads empty Map when every port was added with urisToRead = List.empty
hasUnfinishedInput (fresh) false (no batch initialized)
getCurrentTuple (fresh) null
getCurrentTuple (empty batch) null
hasUnfinishedInput (empty batch) false
initBatch(channelId, batch) replaces inputBatch, resets the cursor, surfaces the channel id via currentChannelId
getNextTuple over a batch yields each element in order; getCurrentTuple tracks the last yielded value; hasUnfinishedInput flips to false once the last element is consumed
initBatch called a second time replaces the prior batch entirely and restarts the cursor (proven by yielding the new batch's first element fresh)
isPortCompleted (non-materialized) reads through to WorkerPort.completed — false initially, true once flipped
startInputPortReaderThreads (no threads) safe no-op

Notes

Materialization-reader-thread paths (non-empty urisToRead) are deliberately left out of this characterization. Constructing an InputPortMaterializationReaderThread eagerly evaluates toPartitioner(partitioning, workerActorId) and pulls in document-factory plumbing that is out of scope for a unit spec — those code paths are exercised in higher-level worker / replay tests.

Any related issues, documentation, discussions?

Closes #5450.

How was this PR tested?

Pure unit-test addition; verified locally with:

  • sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.messaginglayer.InputManagerSpec" — 15 tests, all green
  • sbt scalafmtCheckAll — clean
  • CI to confirm

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Sonnet 4.5)

Pins behavior of `InputManager` — the per-worker input broker that
tracks WorkerPort registration, the active input batch cursor, and
port-completion status. Was the only previously-uncovered module in
the `messaginglayer` package.

Closes apache#5450
Copilot AI review requested due to automatic review settings June 7, 2026 04:42
@github-actions github-actions Bot added the engine label Jun 7, 2026

Copilot AI 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.

Pull request overview

Adds missing unit-test coverage for InputManager in the Amber messaging layer, aligning it with the rest of the package’s existing specs and pinning expected port-registration and batch-cursor behavior.

Changes:

  • Introduces InputManagerSpec.scala with a focused suite of unit tests covering port registration/lookup, reader-thread bookkeeping (empty URI path), batch initialization/cursor behavior, and non-materialized completion semantics.
  • Verifies addPort idempotency (first call wins) and input validation (URI/partitioning size mismatch).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

codecov-commenter commented Jun 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.90%. Comparing base (f2f0564) to head (343e720).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5451      +/-   ##
============================================
+ Coverage     51.85%   51.90%   +0.05%     
- Complexity     2468     2473       +5     
============================================
  Files          1067     1067              
  Lines         41258    41258              
  Branches       4437     4437              
============================================
+ Hits          21394    21415      +21     
+ Misses        18607    18580      -27     
- Partials       1257     1263       +6     
Flag Coverage Δ *Carryforward flag
access-control-service 42.22% <ø> (ø) Carriedforward from d863ec8
agent-service 33.76% <ø> (ø) Carriedforward from d863ec8
amber 52.89% <ø> (+0.13%) ⬆️
computing-unit-managing-service 1.65% <ø> (ø) Carriedforward from d863ec8
config-service 56.06% <ø> (ø) Carriedforward from d863ec8
file-service 38.32% <ø> (ø) Carriedforward from d863ec8
frontend 46.40% <ø> (ø) Carriedforward from d863ec8
pyamber 90.69% <ø> (ø) Carriedforward from d863ec8
python 90.83% <ø> (ø) Carriedforward from d863ec8
workflow-compiling-service 58.69% <ø> (ø) Carriedforward from d863ec8

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Address Copilot review feedback on apache#5451 — the test description says
"reset the cursor" but the body only asserted `currentChannelId` and
`hasUnfinishedInput`. Add the missing assertion by invoking
`getNextTuple` and verifying it returns the first element of the
new batch, which directly proves `currentInputIdx` was reset.
@aglinxinyuan
aglinxinyuan requested a review from Yicong-Huang June 7, 2026 07:12
@aglinxinyuan
aglinxinyuan added this pull request to the merge queue Jun 7, 2026
Merged via the queue into apache:main with commit dd8ab8a Jun 7, 2026
18 checks passed
@aglinxinyuan
aglinxinyuan deleted the test-input-manager-spec branch June 7, 2026 23:41
ELin2025 pushed a commit to ELin2025/texera that referenced this pull request Jun 16, 2026
### What changes were proposed in this PR?

Pin behavior of `InputManager` — the per-worker input broker that was
the only previously-uncovered module in the `messaginglayer` package
(every sibling — `WorkerPort`, `OutputManager`, `AmberFIFOChannel`,
`CongestionControl`, `FlowControl`, `NetworkInputGateway`,
`OrderingEnforcer`, `RangeBasedShuffle` — already has a spec). No
production-code changes.

| Spec | Source class | Tests |
| --- | --- | --- |
| `InputManagerSpec` | `InputManager` | 15 |

Spec file name follows the `<srcClassName>Spec.scala` one-to-one
convention.

**Behavior pinned**

| Surface | Contract |
| --- | --- |
| `getAllPorts` (fresh) | empty `Set` |
| `addPort(portId, schema, Nil, Nil)` | registers a fresh `WorkerPort`
with the supplied schema; no reader threads attached |
| second `addPort` for the same `portId` | silently no-ops (first call
wins; the prior `WorkerPort` survives, including any mutation to
`completed`) |
| `addPort` with mismatched URI / partitioning sizes | throws
`AssertionError` |
| `getPort(portId)` | is a pure lookup — successive calls return the
same `WorkerPort` instance |
| `getInputPortReaderThreads` | empty `Map` when every port was added
with `urisToRead = List.empty` |
| `hasUnfinishedInput` (fresh) | `false` (no batch initialized) |
| `getCurrentTuple` (fresh) | `null` |
| `getCurrentTuple` (empty batch) | `null` |
| `hasUnfinishedInput` (empty batch) | `false` |
| `initBatch(channelId, batch)` | replaces `inputBatch`, resets the
cursor, surfaces the channel id via `currentChannelId` |
| `getNextTuple` over a batch | yields each element in order;
`getCurrentTuple` tracks the last yielded value; `hasUnfinishedInput`
flips to `false` once the last element is consumed |
| `initBatch` called a second time | replaces the prior batch entirely
and restarts the cursor (proven by yielding the new batch's first
element fresh) |
| `isPortCompleted` (non-materialized) | reads through to
`WorkerPort.completed` — `false` initially, `true` once flipped |
| `startInputPortReaderThreads` (no threads) | safe no-op |

**Notes**

Materialization-reader-thread paths (non-empty `urisToRead`) are
deliberately left out of this characterization. Constructing an
`InputPortMaterializationReaderThread` eagerly evaluates
`toPartitioner(partitioning, workerActorId)` and pulls in
document-factory plumbing that is out of scope for a unit spec — those
code paths are exercised in higher-level worker / replay tests.

### Any related issues, documentation, discussions?

Closes apache#5450.

### How was this PR tested?

Pure unit-test addition; verified locally with:

- `sbt "WorkflowExecutionService/testOnly
org.apache.texera.amber.engine.architecture.messaginglayer.InputManagerSpec"`
— 15 tests, all green
- `sbt scalafmtCheckAll` — clean
- CI to confirm

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Sonnet 4.5)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
### What changes were proposed in this PR?

Pin behavior of `InputManager` — the per-worker input broker that was
the only previously-uncovered module in the `messaginglayer` package
(every sibling — `WorkerPort`, `OutputManager`, `AmberFIFOChannel`,
`CongestionControl`, `FlowControl`, `NetworkInputGateway`,
`OrderingEnforcer`, `RangeBasedShuffle` — already has a spec). No
production-code changes.

| Spec | Source class | Tests |
| --- | --- | --- |
| `InputManagerSpec` | `InputManager` | 15 |

Spec file name follows the `<srcClassName>Spec.scala` one-to-one
convention.

**Behavior pinned**

| Surface | Contract |
| --- | --- |
| `getAllPorts` (fresh) | empty `Set` |
| `addPort(portId, schema, Nil, Nil)` | registers a fresh `WorkerPort`
with the supplied schema; no reader threads attached |
| second `addPort` for the same `portId` | silently no-ops (first call
wins; the prior `WorkerPort` survives, including any mutation to
`completed`) |
| `addPort` with mismatched URI / partitioning sizes | throws
`AssertionError` |
| `getPort(portId)` | is a pure lookup — successive calls return the
same `WorkerPort` instance |
| `getInputPortReaderThreads` | empty `Map` when every port was added
with `urisToRead = List.empty` |
| `hasUnfinishedInput` (fresh) | `false` (no batch initialized) |
| `getCurrentTuple` (fresh) | `null` |
| `getCurrentTuple` (empty batch) | `null` |
| `hasUnfinishedInput` (empty batch) | `false` |
| `initBatch(channelId, batch)` | replaces `inputBatch`, resets the
cursor, surfaces the channel id via `currentChannelId` |
| `getNextTuple` over a batch | yields each element in order;
`getCurrentTuple` tracks the last yielded value; `hasUnfinishedInput`
flips to `false` once the last element is consumed |
| `initBatch` called a second time | replaces the prior batch entirely
and restarts the cursor (proven by yielding the new batch's first
element fresh) |
| `isPortCompleted` (non-materialized) | reads through to
`WorkerPort.completed` — `false` initially, `true` once flipped |
| `startInputPortReaderThreads` (no threads) | safe no-op |

**Notes**

Materialization-reader-thread paths (non-empty `urisToRead`) are
deliberately left out of this characterization. Constructing an
`InputPortMaterializationReaderThread` eagerly evaluates
`toPartitioner(partitioning, workerActorId)` and pulls in
document-factory plumbing that is out of scope for a unit spec — those
code paths are exercised in higher-level worker / replay tests.

### Any related issues, documentation, discussions?

Closes apache#5450.

### How was this PR tested?

Pure unit-test addition; verified locally with:

- `sbt "WorkflowExecutionService/testOnly
org.apache.texera.amber.engine.architecture.messaginglayer.InputManagerSpec"`
— 15 tests, all green
- `sbt scalafmtCheckAll` — clean
- CI to confirm

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Sonnet 4.5)
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Aug 4, 2026
### What changes were proposed in this PR?

Adds `test_input_manager.py` (new, 20 tests) for the Python worker's
`InputManager`
(`amber/src/main/python/core/architecture/packaging/input_manager.py`),
which had no direct unit tests — the Scala `InputManager` is covered by
apache#5451, but the Python counterpart was only exercised indirectly through
`MainLoop`. Uses a real `InternalQueue`, in-memory `Schema`/`pyarrow`
tables, and stubbed reader runnables, so no engine or storage is needed.

The suite covers:
- **Registration** — `add_input_port` / `register_input`: `None`
`id`/`internal` fields are normalized to `0`/`False`, re-adding an
existing port is ignored, and channel-to-port bindings are checked in
both directions.
- **Completion tracking** — completing a channel marks its port;
`all_ports_completed` is vacuously `True` with zero ports; completing
one channel completes the whole port even if its other channels are
still open (safe today because the `EndChannel` ECM is port-aligned —
documented in a test comment).
- **Channel filtering** — `get_all_data_channel_ids` excludes control
channels.
- **Materialization readers** — mismatched `uris`/`partitionings` raise;
one reader is created per URI with the right pairing; a second setup
replaces the readers instead of appending; finished readers are not
restarted, and unfinished ones run on daemon threads.
- **`process_data_payload`** — a DataFrame becomes `Tuple`s carrying the
port's schema; an empty table yields nothing; a StateFrame passes
through unchanged; a DataFrame from an unregistered channel fails only
when the generator is consumed; unknown payload types raise
`NotImplementedError`.

### Any related issues, documentation, discussions?

Closes apache#6486

### How was this PR tested?

```
cd amber/src/main/python
PYTHONPATH=. python -m pytest ../../test/python/core/architecture/packaging/ -v
# 28 passed (20 new InputManager tests + 8 existing OutputManager tests)
```

### Was this PR authored or co-authored using generative AI tooling?

Co-authored by: Claude Code (Fable 5)

---------

Co-authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
aglinxinyuan added a commit that referenced this pull request Aug 20, 2026
The cherry-pick of #7804 hit modify/delete on all three of its spec files:
each already existed on `main` (added by #7018, #7219 and #5451, none of
which were backported) but is absent here, so git could not apply a diff
and the automation committed `main`'s whole file. Two of the three compile
and pass against this branch unchanged; `PekkoActorRefMappingServiceSpec`
does not, because it is written against `main` names this branch predates:

  - `virtualidentity.util.COORDINATOR` is `CONTROLLER` here, so the import
    did not resolve at all;
  - the scaladoc pointed at `PekkoMessageTransferServiceSpec`, a sibling
    that does not exist on this branch, leaving a dangling `[[link]]`.

The assertions are untouched: every method the suite drives is identical
on this branch, and the production hunks of #7804 applied cleanly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test coverage for InputManager

4 participants