Skip to content

Commit

Permalink
Polishing to integration test, added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Apr 22, 2024
1 parent 279d78d commit 0e867eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/test/java/io/lettuce/core/RedisCommandBuilderUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import static org.assertj.core.api.Assertions.*;

import java.nio.charset.StandardCharsets;
import java.util.Collections;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.EmptyByteBuf;
import org.junit.jupiter.api.Test;

import io.lettuce.core.codec.StringCodec;
Expand All @@ -16,6 +19,8 @@
* @author Mark Paluch
*/
class RedisCommandBuilderUnitTests {
public static final String MY_KEY = "hKey";
public static final String MY_FIELD = "hField";

RedisCommandBuilder<String, String> sut = new RedisCommandBuilder<>(StringCodec.UTF8);

Expand All @@ -29,4 +34,14 @@ void shouldCorrectlyConstructXreadgroup() {
.isEqualTo("stream");
}

@Test
void shouldCorrectlyConstructHexpire() {

Command<String, String, ?> command = sut.hexpire(MY_KEY, 1, ExpireArgs.Builder.nx(), Collections.singletonList(MY_FIELD));
ByteBuf buf = Unpooled.directBuffer();
command.encode(buf);

assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*6\r\n" + "$7\r\n" + "HEXPIRE\r\n" + "$4\r\n" + "hKey\r\n"
+ "$1\r\n" + "1\r\n" + "$2\r\n" + "NX\r\n" + "$1\r\n" + "1\r\n" + "$6\r\n" + "hField\r\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void hexpire() {
assertThat(redis.configSet("hash-max-listpack-entries","0")).isEqualTo("OK");
assertThat(redis.configSet("set-max-listpack-value","0")).isEqualTo("OK");

assertThat(redis.hexpire("myKey", 1, Collections.singletonList("myField"))).isTrue();
assertThat(redis.hexpire(MY_KEY, 1, Collections.singletonList(MY_FIELD))).isTrue();

await().until(() -> redis.hget("myKey", "myField") == null);
await().until(() -> redis.hget(MY_KEY, MY_FIELD) == null);
}

@Test
Expand All @@ -217,24 +217,24 @@ void hexpireExpireArgs() {
assertThat(redis.configSet("hash-max-listpack-entries","0")).isEqualTo("OK");
assertThat(redis.configSet("set-max-listpack-value","0")).isEqualTo("OK");

assertThat(redis.hexpire("myKey",
assertThat(redis.hexpire(MY_KEY,
Duration.ofSeconds(1),
ExpireArgs.Builder.nx(),
Collections.singletonList("myField"))).isTrue();
assertThat(redis.hexpire("myKey",
Collections.singletonList(MY_FIELD))).isTrue();
assertThat(redis.hexpire(MY_KEY,
Duration.ofSeconds(1),
ExpireArgs.Builder.xx(),
Collections.singletonList("myField"))).isTrue();
assertThat(redis.hexpire("myKey",
Collections.singletonList(MY_FIELD))).isTrue();
assertThat(redis.hexpire(MY_KEY,
Duration.ofSeconds(10),
ExpireArgs.Builder.gt(),
Collections.singletonList("myField"))).isTrue();
assertThat(redis.hexpire("myKey",
Collections.singletonList(MY_FIELD))).isTrue();
assertThat(redis.hexpire(MY_KEY,
Duration.ofSeconds(1),
ExpireArgs.Builder.lt(),
Collections.singletonList("myField"))).isTrue();
Collections.singletonList(MY_FIELD))).isTrue();

await().until(() -> redis.hget("myKey", "myField") == null);
await().until(() -> redis.hget(MY_KEY, MY_FIELD) == null);
}

@Test
Expand Down

0 comments on commit 0e867eb

Please sign in to comment.