Skip to content

Commit

Permalink
Add test for transactions using the reactive API
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Nov 10, 2015
1 parent 4fc6bbc commit 24b04cc
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/test/java/com/lambdaworks/redis/ReactiveConnectionTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, String> 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<Object> {

private final List<Object> result;
Expand Down

0 comments on commit 24b04cc

Please sign in to comment.