Search in sources :

Example 6 with RTransactionReactive

use of org.redisson.api.RTransactionReactive in project redisson by redisson.

the class RedissonTransactionalBucketReactiveTest method testTimeout.

@Test
public void testTimeout() throws InterruptedException {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(3, TimeUnit.SECONDS));
    RBucketReactive<String> bucket = transaction.getBucket("test");
    sync(bucket.set("234"));
    Thread.sleep(3000);
    try {
        sync(transaction.commit());
        Assertions.fail();
    } catch (TransactionException e) {
    // skip
    }
    Thread.sleep(1000);
    assertThat(sync(b.get())).isEqualTo("123");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 7 with RTransactionReactive

use of org.redisson.api.RTransactionReactive in project redisson by redisson.

the class RedissonTransactionalBucketReactiveTest method testTrySet.

@Test
public void testTrySet() {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.trySet("0"))).isFalse();
    assertThat(sync(bucket.delete())).isTrue();
    assertThat(sync(bucket.trySet("324"))).isTrue();
    assertThat(sync(bucket.trySet("43"))).isFalse();
    sync(transaction.commit());
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("324");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 8 with RTransactionReactive

use of org.redisson.api.RTransactionReactive in project redisson by redisson.

the class RedissonTransactionalBucketReactiveTest method testRollback.

@Test
public void testRollback() {
    RBucketReactive<Object> b = redisson.getBucket("test");
    sync(b.set("1234"));
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<Object> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.get())).isEqualTo("1234");
    assertThat(sync(bucket.getAndDelete())).isEqualTo("1234");
    assertThat(sync(b.get())).isEqualTo("1234");
    sync(transaction.rollback());
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("1234");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 9 with RTransactionReactive

use of org.redisson.api.RTransactionReactive in project redisson by redisson.

the class RedissonTransactionalBucketReactiveTest method testSet.

@Test
public void testSet() {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> bucket = transaction.getBucket("test");
    sync(bucket.set("234"));
    assertThat(sync(bucket.get())).isEqualTo("234");
    sync(transaction.commit());
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("234");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Aggregations

RTransactionReactive (org.redisson.api.RTransactionReactive)9 Test (org.junit.jupiter.api.Test)8 BaseReactiveTest (org.redisson.BaseReactiveTest)8 TransactionOptions (org.redisson.api.TransactionOptions)1