Skip to content

Commit

Permalink
chore: change hint prexfix to x-greptime-hint- (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored Jul 31, 2024
1 parent 83096a0 commit 1da56f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion ingester-rpc/src/main/java/io/greptime/rpc/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings({"unchecked", "unused"})
public class Context implements Copiable<Context> {

private static final String HINT_PREFIX = "x-greptime-hint:";
private static final String HINT_PREFIX = "x-greptime-hint-";

private final Map<String, Object> ctx = new HashMap<>();

Expand Down Expand Up @@ -99,6 +99,17 @@ public <T> T get(String key) {
}
}

/**
* Gets the value of the specified hint key.
*
* @param key the hint key
* @return the value
* @param <T> the type of the value
*/
public <T> T getHint(String key) {
return get(HINT_PREFIX + key);
}

/**
* Removes the specified key and its value form this {@link Context}.
*
Expand Down
6 changes: 4 additions & 2 deletions ingester-rpc/src/test/java/io/greptime/rpc/ContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void ofShouldReturnContextWithOneEntryTest() {
@Test
public void hintShouldReturnContextWithHintEntryTest() {
Context context = Context.hint("key", "value");
Assert.assertEquals("value", context.get("x-greptime-hint:key"));
Assert.assertEquals("value", context.getHint("key"));
Assert.assertEquals("value", context.get("x-greptime-hint-key"));
}

@Test
Expand All @@ -52,7 +53,8 @@ public void withShouldAddEntryToContextTest() {
public void withHintShouldAddHintEntryToContextTest() {
Context context = Context.newDefault();
context.withHint("key", "value").with("key2", "value");
Assert.assertEquals("value", context.get("x-greptime-hint:key"));
Assert.assertEquals("value", context.get("x-greptime-hint-key"));
Assert.assertEquals("value", context.getHint("key"));
Assert.assertEquals("value", context.get("key2"));
}

Expand Down

0 comments on commit 1da56f5

Please sign in to comment.