Ma77Ball opened a new issue, #5717:
URL: https://github.com/apache/texera/issues/5717
### Task Summary
Add a ScalaTest spec for `GlobalPortIdentitySerde`, which currently has no
test coverage. This is a good first issue: the target is small, pure (no I/O,
no mocks, no DB), and has clearly documented behavior, so it is a
self-contained way to get familiar with the repo's Scala test workflow.
**What this class does**
`GlobalPortIdentitySerde` converts a `GlobalPortIdentity` to and from a
compact, human-readable string. The string is embedded in VFS URIs and file
paths, so the format deliberately avoids underscores and rejects negative port
ids. Round-tripping (serialize then deserialize) must return an equal object.
**Where the code lives**
Source:
`common/workflow-core/src/main/scala/org/apache/texera/amber/util/serde/GlobalPortIdentitySerde.scala`
- `serializeAsString` (an implicit `SerdeOps` on `GlobalPortIdentity`)
produces:
`(logicalOpId=...,layerName=...,portId=...,isInternal=...,isInput=...)`
It calls `require(...)` to reject an underscore in `logicalOpId` or
`layerName`, and a negative `portId`.
- `deserializeFromString` parses that string back into a
`GlobalPortIdentity` via a regex, rejecting a negative `portId` and any
malformed input with `IllegalArgumentException`.
**Where the test goes**
Create:
`common/workflow-core/src/test/scala/org/apache/texera/amber/util/serde/GlobalPortIdentitySerdeSpec.scala`
(test path mirrors the source path; file name is `<ClassName>Spec.scala`).
**What to cover**
- Format correctness: serializing a known `GlobalPortIdentity` yields the
exact expected string, and the `isInternal` / `isInput` flags are rendered
correctly.
- Underscore validation: an underscore in `logicalOpId` throws
`IllegalArgumentException`; same for `layerName`.
- Negative-portId rejection: on the serialize path, and on the deserialize
path (a `portId=-1` in the input string).
- Malformed input: a string that does not match the format throws
`IllegalArgumentException`.
- Round-trip: for several combinations of `internal` (true/false), `input`
(true/false), and `portId` (0, 1, 42),
`deserializeFromString(x.serializeAsString)` equals `x`.
**How to write it (conventions)**
- Use `AnyFlatSpec with Matchers`, the style used by neighboring specs. A
good reference to copy structure from is
`common/workflow-core/src/test/scala/org/apache/texera/amber/util/VirtualIdentityUtilsSpec.scala`.
- Build inputs with `GlobalPortIdentity(opId =
PhysicalOpIdentity(OperatorIdentity("op"), "layer"), portId = PortIdentity(id =
0, internal = false), input = false)`. These are protobuf-generated case
classes (defined in
`common/workflow-core/src/main/protobuf/org/apache/texera/amber/core/{workflow,virtualidentity}.proto`).
- Bring the extension method into scope with `import
org.apache.texera.amber.util.serde.GlobalPortIdentitySerde.SerdeOps` so
`.serializeAsString` is available.
- Add the standard Apache license header at the top of the file (copy it
from any existing `*Spec.scala`).
**How to run it**
`sbt "WorkflowCore/testOnly
org.apache.texera.amber.util.serde.GlobalPortIdentitySerdeSpec"`
Note: the sbt build runs JaCoCo coverage instrumentation, and JaCoCo 0.8.11
cannot read Java 25 bytecode. If you hit `Unsupported class file major version
69`, build under JDK 17 (the version the project targets), for example by
setting `JAVA_HOME` to a JDK 17 install before running sbt.
**Definition of done**
A new `GlobalPortIdentitySerdeSpec.scala` exists at the path above, covers
all cases listed, and passes locally. Run `sbt scalafmtAll` before committing.
### Task Type
- [x] Testing / QA
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]