Skip to content

Commit

Permalink
GEODE-8362: add redis tests that access binary data (#5374)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal committed Jul 21, 2020
1 parent 6fa5dcb commit 4b91664
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
Expand Up @@ -699,6 +699,28 @@ public void testConcurrentHGetAll() {
assertThat(successCount.get()).isEqualTo(ITERATION_COUNT * 2);
}

@Test
public void testHset_canStoreBinaryData() {
byte[] blob = new byte[256];
for (int i = 0; i < 256; i++) {
blob[i] = (byte) i;
}

jedis.hset("key".getBytes(), blob, blob);
Map<byte[], byte[]> result = jedis.hgetAll("key".getBytes());

assertThat(result.keySet()).containsExactly(blob);
assertThat(result.values()).containsExactly(blob);
}

@Test
public void testHstrlen_withBinaryData() {
byte[] zero = new byte[] {0};
jedis.hset(zero, zero, zero);

assertThat(jedis.hstrlen(zero, zero)).isEqualTo(1);
}

private void doABunchOfHSets(String key, Map<String, String> record, Jedis jedis) {
String field;
String fieldValue;
Expand Down
Expand Up @@ -111,6 +111,16 @@ public void testConcurrentDel_differentClients() {
}
}

@Test
public void testDel_withBinaryKey() {
byte[] key = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

jedis.set(key, "foo".getBytes());
jedis.del(key);

assertThat(jedis.get(key)).isNull();
}

private String randString() {
return Long.toHexString(Double.doubleToLongBits(Math.random()));
}
Expand Down
Expand Up @@ -106,16 +106,26 @@ public void testSAdd_withExistingKey_ofWrongType_shouldNotOverWriteExistingKey()

jedis.set(key, stringValue);

try {
jedis.sadd(key, setValue);
} catch (JedisDataException exception) {
}
assertThatThrownBy(() -> jedis.sadd(key, setValue)).isInstanceOf(JedisDataException.class);

String result = jedis.get(key);

assertThat(result).isEqualTo(stringValue);
}

@Test
public void testSAdd_canStoreBinaryData() {
byte[] blob = new byte[256];
for (int i = 0; i < 256; i++) {
blob[i] = (byte) i;
}

jedis.sadd("key".getBytes(), blob, blob);
Set<byte[]> result = jedis.smembers("key".getBytes());

assertThat(result).containsExactly(blob);
}

@Test
public void testConcurrentSAddSCard_sameKeyPerClient()
throws InterruptedException, ExecutionException {
Expand Down
Expand Up @@ -93,6 +93,23 @@ public void testAppend_concurrent() {
}
}

@Test
public void testAppend_withBinaryKeyAndValue() {
byte[] blob = new byte[256];
byte[] doubleBlob = new byte[512];
for (int i = 0; i < 256; i++) {
blob[i] = (byte) i;
doubleBlob[i] = (byte) i;
doubleBlob[i + 256] = (byte) i;
}

jedis.set(blob, blob);
jedis.append(blob, blob);
byte[] result = jedis.get(blob);

assertThat(result).isEqualTo(doubleBlob);
}

private String randString() {
return Long.toHexString(Double.doubleToLongBits(Math.random()));
}
Expand Down
Expand Up @@ -497,4 +497,18 @@ public void testSET_withInvalidOptions() {

soft.assertAll();
}

@Test
public void testSET_withBinaryKeyAndValue() {
byte[] blob = new byte[256];
for (int i = 0; i < 256; i++) {
blob[i] = (byte) i;
}

jedis.set(blob, blob);
byte[] result = jedis.get(blob);

assertThat(result).isEqualTo(blob);
}

}
Expand Up @@ -75,4 +75,13 @@ public void testStrlen_requestWrongType_shouldReturnError() {
.isInstanceOf(JedisDataException.class)
.hasMessageContaining(RedisConstants.ERROR_WRONG_TYPE);
}

@Test
public void testStrlen_withBinaryData() {
byte[] zero = new byte[] {0};
jedis.set(zero, zero);

assertThat(jedis.strlen(zero)).isEqualTo(1);
}

}

0 comments on commit 4b91664

Please sign in to comment.