From 1da56f57d82386bdea6041eeac7459181c6ff0da Mon Sep 17 00:00:00 2001 From: Jeremyhi Date: Wed, 31 Jul 2024 10:19:32 +0800 Subject: [PATCH] chore: change hint prexfix to x-greptime-hint- (#44) --- .../src/main/java/io/greptime/rpc/Context.java | 13 ++++++++++++- .../src/test/java/io/greptime/rpc/ContextTest.java | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/Context.java b/ingester-rpc/src/main/java/io/greptime/rpc/Context.java index c195c12..f1d0ea2 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/Context.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/Context.java @@ -28,7 +28,7 @@ @SuppressWarnings({"unchecked", "unused"}) public class Context implements Copiable { - private static final String HINT_PREFIX = "x-greptime-hint:"; + private static final String HINT_PREFIX = "x-greptime-hint-"; private final Map ctx = new HashMap<>(); @@ -99,6 +99,17 @@ public T get(String key) { } } + /** + * Gets the value of the specified hint key. + * + * @param key the hint key + * @return the value + * @param the type of the value + */ + public T getHint(String key) { + return get(HINT_PREFIX + key); + } + /** * Removes the specified key and its value form this {@link Context}. * diff --git a/ingester-rpc/src/test/java/io/greptime/rpc/ContextTest.java b/ingester-rpc/src/test/java/io/greptime/rpc/ContextTest.java index 5a52b79..63fbb1a 100644 --- a/ingester-rpc/src/test/java/io/greptime/rpc/ContextTest.java +++ b/ingester-rpc/src/test/java/io/greptime/rpc/ContextTest.java @@ -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 @@ -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")); }