Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Baggage.getEntry(String key) #6765

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ default boolean isEmpty() {
* be set to not use an implicit parent, so any parent assignment must be done manually.
*/
BaggageBuilder toBuilder();

/**
* Returns the {@code BaggageEntry} associated with the given key.
*
* @param entryKey entry key to return the {@code BaggageEntry} for, or {@code null} if no {@code
* Entry} with the given {@code entryKey} is in this {@code Baggage}.
*/
@Nullable
BaggageEntry getEntry(String entryKey);
breedx-splk marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public String getEntryValue(String entryKey) {
return entry != null ? entry.getValue() : null;
}

// Overrides the
breedx-splk marked this conversation as resolved.
Show resolved Hide resolved
@Nullable
@Override
public BaggageEntry getEntry(String entryKey) {
return get(entryKey);
}

@Override
public BaggageBuilder toBuilder() {
return new Builder(new ArrayList<>(data()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private enum State {

private boolean skipToNext;

public Parser(String baggageHeader) {
Parser(String baggageHeader) {
this.baggageHeader = baggageHeader;
reset(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ void current() {
assertThat(result.getEntryValue("foo")).isEqualTo("bar");
}
}

@Test
void getEntry() {
BaggageEntryMetadata metadata = BaggageEntryMetadata.create("flib");
try (Scope scope =
Context.root().with(Baggage.builder().put("a", "b", metadata).build()).makeCurrent()) {
Baggage result = Baggage.current();
assertThat(result.getEntry("a").getValue()).isEqualTo("b");
assertThat(result.getEntry("a").getMetadata().getValue()).isEqualTo("flib");
}
}
}
Loading