From 24b04cc48d4c1d9c8bd40a119d48f90914c518e3 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 10 Nov 2015 06:47:59 +0100 Subject: [PATCH] Add test for transactions using the reactive API --- .../redis/ReactiveConnectionTest.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/lambdaworks/redis/ReactiveConnectionTest.java b/src/test/java/com/lambdaworks/redis/ReactiveConnectionTest.java index bab16d1f06..bbbbd760c2 100644 --- a/src/test/java/com/lambdaworks/redis/ReactiveConnectionTest.java +++ b/src/test/java/com/lambdaworks/redis/ReactiveConnectionTest.java @@ -1,13 +1,11 @@ package com.lambdaworks.redis; import static com.google.code.tempusfugit.temporal.Duration.millis; -import static com.google.code.tempusfugit.temporal.Duration.seconds; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import java.util.concurrent.CountDownLatch; -import com.google.code.tempusfugit.temporal.WaitFor; -import com.lambdaworks.Wait; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -19,6 +17,7 @@ import com.google.common.collect.Lists; import com.lambdaworks.Delay; +import com.lambdaworks.Wait; import com.lambdaworks.redis.api.StatefulRedisConnection; import com.lambdaworks.redis.api.rx.RedisReactiveCommands; @@ -114,6 +113,27 @@ public void multiSubscribe() throws Exception { assertThat(redis.get(key)).isEqualTo("4"); } + @Test + public void transactional() throws Exception { + + final CountDownLatch sync = new CountDownLatch(1); + + RedisReactiveCommands reactive = client.connect().reactive(); + + reactive.multi().subscribe(multiResponse -> { + reactive.set(key, "1").subscribe(); + reactive.incr(key).subscribe(getResponse -> { + sync.countDown(); + }); + reactive.exec().subscribe(); + }); + + sync.await(); + + String result = redis.get(key); + assertThat(result).isEqualTo("2"); + } + private static class CompletionSubscriber extends Subscriber { private final List result;