Java SDK: add unit tests for TargetKey

Open Beginner friendly
#5,034 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
testing

Research direction

Read TargetKey.java under foreign/java/java-sdk/src/main/java/org/apache/iggy/client/async/tcp/, paying attention to of(byte[]), topic(), startsWith and equals/hashCode, which compare only the first length bytes. Use BigIntegerMessageIdTest.java as the style reference, then add TargetKeyTest.java in the same package under src/test. Done when the four listed cases pass with ./gradlew :iggy:test --tests '*TargetKeyTest' and ./gradlew spotlessCheck passes in foreign/java.

Written by the indexing model from the issue text.

Description

good first issue java test
Description

TargetKey in foreign/java/java-sdk/src/main/java/org/apache/iggy/client/async/tcp/TargetKey.java has no unit test. It holds the target bytes of a partition request, or their stream and topic prefix, and PollRouter uses it as a map key. It has of(byte[]), topic() (the same bytes without the trailing four-byte partition id), startsWith(TargetKey), equals and hashCode. Equality compares only the first length bytes, so a change to the prefix handling would break route lookups without any test failing.

Affected area / component

Java SDK

Proposed solution

Add TargetKeyTest.java under foreign/java/java-sdk/src/test/java/org/apache/iggy/client/async/tcp/, in the same package so it can reach the package-private class. BigIntegerMessageIdTest.java shows the JUnit 5 and AssertJ style. Use small hand-built byte arrays.

  • Two keys over equal arrays are equal and have equal hash codes, and keys over different arrays are not equal.
  • topic() of a key built from the stream and topic bytes plus four bytes equals of over the stream and topic bytes alone.
  • startsWith is true for a prefix and for the key itself, and false for a longer key or a different prefix.
  • equals returns false for null and for another type.

How to test: ./gradlew :iggy:test --tests '*TargetKeyTest' and ./gradlew spotlessCheck pass in foreign/java.

Good first issue
  • I think this could be a good first issue for a new contributor
Dominant language
Rust
Stars
5.3k
Forks
548
Avg merge
2d 20h
Merged PRs (30d)
194

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/iggy

All issues in apache/iggy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.