Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ttl not being set for keyvalue redis #153

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class RedisKeyValueEntry implements RedisDataEntry {

@Override
public void pushMessage(Pipeline jedisPipelined, RedisTtl redisTTL) {
redisTTL.setTtl(jedisPipelined, key);
instrumentation.logDebug("key: {}, value: {}", key, value);
jedisPipelined.set(key, value);
redisTTL.setTtl(jedisPipelined, key);
}

@Override
public void pushMessage(JedisCluster jedisCluster, RedisTtl redisTTL) {
redisTTL.setTtl(jedisCluster, key);
instrumentation.logDebug("key: {}, value: {}", key, value);
jedisCluster.set(key, value);
redisTTL.setTtl(jedisCluster, key);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.odpf.firehose.sink.redis.ttl.NoRedisTtl;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
Expand All @@ -24,9 +26,15 @@ public class RedisKeyValueEntryTest {
@Mock
private JedisCluster jedisCluster;

private InOrder inOrderPipeline;
private InOrder inOrderJedis;


@Before
public void setup() {
MockitoAnnotations.initMocks(this);
inOrderPipeline = Mockito.inOrder(pipeline);
inOrderJedis = Mockito.inOrder(jedisCluster);

}

Expand All @@ -36,8 +44,8 @@ public void pushMessageWithNoTtl() {
String value = "value";
RedisKeyValueEntry redisKeyValueEntry = new RedisKeyValueEntry(key, value, instrumentation);
redisKeyValueEntry.pushMessage(pipeline, new NoRedisTtl());
verify(pipeline, times(1)).set(key, value);
verify(pipeline, times(0)).expireAt(any(String.class), any(Long.class));
inOrderPipeline.verify(pipeline, times(1)).set(key, value);
inOrderPipeline.verify(pipeline, times(0)).expireAt(any(String.class), any(Long.class));

}

Expand All @@ -47,8 +55,8 @@ public void pushMessageWithTtl() {
String value = "value";
RedisKeyValueEntry redisKeyValueEntry = new RedisKeyValueEntry(key, value, instrumentation);
redisKeyValueEntry.pushMessage(pipeline, new DurationTtl(100));
verify(pipeline, times(1)).set(key, value);
verify(pipeline, times(1)).expire(key, 100);
inOrderPipeline.verify(pipeline, times(1)).set(key, value);
inOrderPipeline.verify(pipeline, times(1)).expire(key, 100);
}

@Test
Expand All @@ -67,8 +75,8 @@ public void pushMessageWithNoTtlUsingJedisCluster() {
String value = "value";
RedisKeyValueEntry redisKeyValueEntry = new RedisKeyValueEntry(key, value, instrumentation);
redisKeyValueEntry.pushMessage(jedisCluster, new NoRedisTtl());
verify(jedisCluster, times(1)).set(key, value);
verify(jedisCluster, times(0)).expireAt(any(String.class), any(Long.class));
inOrderJedis.verify(jedisCluster, times(1)).set(key, value);
inOrderJedis.verify(jedisCluster, times(0)).expireAt(any(String.class), any(Long.class));

}

Expand All @@ -78,8 +86,8 @@ public void pushMessageWithTtlUsingJedisCluster() {
String value = "value";
RedisKeyValueEntry redisKeyValueEntry = new RedisKeyValueEntry(key, value, instrumentation);
redisKeyValueEntry.pushMessage(jedisCluster, new DurationTtl(100));
verify(jedisCluster, times(1)).set(key, value);
verify(jedisCluster, times(1)).expire(key, 100);
inOrderJedis.verify(jedisCluster, times(1)).set(key, value);
inOrderJedis.verify(jedisCluster, times(1)).expire(key, 100);
}

@Test
Expand Down