Search in sources :

Example 36 with RTransaction

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

the class RedissonTransactionalBucketTest method testGetAndRemove.

@Test
public void testGetAndRemove() {
    RBucket<String> m = redisson.getBucket("test");
    m.set("123");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> set = transaction.getBucket("test");
    assertThat(set.get()).isEqualTo("123");
    assertThat(set.size()).isEqualTo(6);
    assertThat(set.getAndDelete()).isEqualTo("123");
    assertThat(set.size()).isEqualTo(0);
    assertThat(set.get()).isNull();
    assertThat(set.getAndDelete()).isNull();
    transaction.commit();
    assertThat(redisson.getKeys().count()).isEqualTo(0);
    assertThat(m.get()).isNull();
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 37 with RTransaction

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

the class RedissonTransactionalLocalCachedMapTest method testPut.

@Test
public void testPut() throws InterruptedException {
    RLocalCachedMap<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m1.put("1", "2");
    m1.put("3", "4");
    RLocalCachedMap<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m2.get("1");
    m2.get("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = transaction.getLocalCachedMap(m1);
    assertThat(map.put("3", "5")).isEqualTo("4");
    assertThat(map.get("3")).isEqualTo("5");
    assertThat(m1.get("3")).isEqualTo("4");
    assertThat(m2.get("3")).isEqualTo("4");
    transaction.commit();
    assertThat(m1.get("3")).isEqualTo("5");
    assertThat(m2.get("3")).isEqualTo("5");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 38 with RTransaction

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

the class TransactionalBean method testCommitAfterRollback.

@Transactional
public void testCommitAfterRollback() {
    RTransaction transaction = transactionManager.getCurrentTransaction();
    transaction.getMap("test2").put("1", "2");
}
Also used : RTransaction(org.redisson.api.RTransaction) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with RTransaction

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

the class TransactionalBean method testNestedNewTransaction.

@Transactional
public void testNestedNewTransaction() {
    RTransaction transaction = transactionManager.getCurrentTransaction();
    transaction.getMap("tr1").put("1", "0");
    transactionalBean2.testInNewTransaction();
}
Also used : RTransaction(org.redisson.api.RTransaction) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with RTransaction

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

the class TransactionalBean method testTransactionIsNotNull.

@Transactional
public void testTransactionIsNotNull() {
    RTransaction transaction = transactionManager.getCurrentTransaction();
    assertThat(transaction).isNotNull();
}
Also used : RTransaction(org.redisson.api.RTransaction) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RTransaction (org.redisson.api.RTransaction)49 Test (org.junit.jupiter.api.Test)38 BaseTest (org.redisson.BaseTest)37 Transactional (org.springframework.transaction.annotation.Transactional)9 HashSet (java.util.HashSet)5 RBuckets (org.redisson.api.RBuckets)3 LinkedHashMap (java.util.LinkedHashMap)2 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 TransactionOptions (org.redisson.api.TransactionOptions)1 NoTransactionException (org.springframework.transaction.NoTransactionException)1