jdeppe-pivotal commented on a change in pull request #6447:
URL: https://github.com/apache/geode/pull/6447#discussion_r629430538
##########
File path:
geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/key/AbstractKeysIntegrationTest.java
##########
@@ -54,68 +55,71 @@ public void errors_givenWrongNumberOfArguments() {
@Test
public void givenSplat_withASCIIdata_returnsExpectedMatches() {
- jedis.set("string1", "v1");
- jedis.sadd("set1", "member1");
- jedis.hset("hash1", "key1", "field1");
- assertThat(jedis.keys("*")).containsExactlyInAnyOrder("string1", "set1",
"hash1");
- assertThat(jedis.keys("s*")).containsExactlyInAnyOrder("string1", "set1");
- assertThat(jedis.keys("h*")).containsExactlyInAnyOrder("hash1");
- assertThat(jedis.keys("foo*")).isEmpty();
+ jedis.set("{K}string1", "v1");
+ jedis.sadd("{K}set1", "member1");
+ jedis.hset("{K}hash1", "key1", "field1");
+ assertThat(jedis.keys("{K}*")).containsExactlyInAnyOrder("{K}string1",
"{K}set1", "{K}hash1");
+ assertThat(jedis.keys("{K}s*")).containsExactlyInAnyOrder("{K}string1",
"{K}set1");
+ assertThat(jedis.keys("{K}h*")).containsExactlyInAnyOrder("{K}hash1");
+ assertThat(jedis.keys("{K}foo*")).isEmpty();
}
@Test
public void givenSplat_withBinaryData_returnsExpectedMatches() {
byte[] stringKey =
- new byte[] {(byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 's', 't', 'r', 'i',
'n', 'g', '1'};
+ new byte[] {'{', 1, '}', (byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 's',
't', 'r', 'i', 'n', 'g',
+ '1'};
byte[] value = new byte[] {'v', '1'};
jedis.set(stringKey, value);
- byte[] setKey = new byte[] {(byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 's',
'e', 't', '1'};
+ byte[] setKey =
+ new byte[] {'{', 1, '}', (byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 's',
'e', 't', '1'};
byte[] member = new byte[] {'m', '1'};
jedis.sadd(setKey, member);
- byte[] hashKey = new byte[] {(byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 'h',
'a', 's', 'h', '1'};
- byte[] key = new byte[] {'k', 'e', 'y', '1'};
+ byte[] hashKey =
+ new byte[] {'{', 1, '}', (byte) 0xac, (byte) 0xed, 0, 4, 0, 5, 'h',
'a', 's', 'h', '1'};
+ byte[] key = new byte[] {'{', 1, '}', 'k', 'e', 'y', '1'};
jedis.hset(hashKey, key, value);
assertThat(jedis.exists(stringKey));
assertThat(jedis.exists(setKey));
assertThat(jedis.exists(hashKey));
- assertThat(jedis.keys(new byte[]
{'*'})).containsExactlyInAnyOrder(stringKey, setKey, hashKey);
- assertThat(jedis.keys(new byte[] {(byte) 0xac, (byte) 0xed, 0, 4, 0, 5,
's', '*'}))
+ assertThat(jedis.keys(new byte[] {'{', 1, '}',
'*'})).containsExactlyInAnyOrder(stringKey,
+ setKey, hashKey);
+ assertThat(jedis.keys(new byte[] {'{', 1, '}', (byte) 0xac, (byte) 0xed,
0, 4, 0, 5, 's', '*'}))
.containsExactlyInAnyOrder(stringKey, setKey);
- assertThat(jedis.keys(new byte[] {(byte) 0xac, (byte) 0xed, 0, 4, 0, 5,
'h', '*'}))
+ assertThat(jedis.keys(new byte[] {'{', 1, '}', (byte) 0xac, (byte) 0xed,
0, 4, 0, 5, 'h', '*'}))
.containsExactlyInAnyOrder(hashKey);
- assertThat(jedis.keys(new byte[] {'f', '*'})).isEmpty();
+ assertThat(jedis.keys(new byte[] {'{', 1, '}', 'f', '*'})).isEmpty();
}
@Test
- public void givenBinaryValue_withExactMatch_preservesBinaryData()
- throws UnsupportedEncodingException {
- String chinese_utf16 = "子";
- byte[] utf16encodedBytes = chinese_utf16.getBytes("UTF-16");
+ public void givenBinaryValue_withExactMatch_preservesBinaryData() {
+ String chineseHashTag = "{子}";
+ byte[] utf8encodedBytes = chineseHashTag.getBytes(StandardCharsets.UTF_8);
Review comment:
I switched to UTF-8 because UTF-16 converts to at least one 16-bit
value. So even just `{}` will convert to `0x0, 0x7b, 0x0, 0x7d`. So to
calculate the hashtag correctly, we'd need to know it was UTF-16 to be able to
match what's between the braces. Without knowing, we end up matching against a
spurious `0x0` between the braces. I'm not quite sure what the original reason
was for converting to UTF-16 here.
(UTF-8 includes ASCII chars as a subset so `{}` ends up being just `0x7b,
0x7d`).
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]