Search in sources :

Example 21 with RTransaction

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

the class TransactionalBean2 method testPropagationRequired.

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

Example 22 with RTransaction

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

the class TransactionalBean2 method testPropagationRequiredWithException.

@Transactional
public void testPropagationRequiredWithException() {
    RTransaction transaction = transactionManager.getCurrentTransaction();
    transaction.getMap("tr5").put("2", "4");
    throw new IllegalStateException();
}
Also used : RTransaction(org.redisson.api.RTransaction) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with RTransaction

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

the class RedissonTransactionManager method doBegin.

@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
    RedissonTransactionObject tObject = (RedissonTransactionObject) transaction;
    if (tObject.getTransactionHolder() == null) {
        int timeout = determineTimeout(definition);
        TransactionOptions options = TransactionOptions.defaults();
        if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
            options.timeout(timeout, TimeUnit.SECONDS);
        }
        RTransaction trans = redisson.createTransaction(options);
        RedissonTransactionHolder holder = new RedissonTransactionHolder();
        holder.setTransaction(trans);
        tObject.setTransactionHolder(holder);
        TransactionSynchronizationManager.bindResource(redisson, holder);
    }
}
Also used : TransactionOptions(org.redisson.api.TransactionOptions) RTransaction(org.redisson.api.RTransaction)

Example 24 with RTransaction

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

the class RedissonTransactionalBucketsTest method testSet.

@Test
public void testSet() {
    RBucket<String> b1 = redisson.getBucket("test1");
    b1.set("1");
    RBucket<String> b2 = redisson.getBucket("test2");
    b2.set("2");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBuckets buckets = transaction.getBuckets();
    Map<String, Object> bbs = new LinkedHashMap<>();
    bbs.put("test1", "11");
    bbs.put("test2", "22");
    buckets.set(bbs);
    Map<String, Object> newBuckets = buckets.get("test1", "test2");
    assertThat(newBuckets).isEqualTo(bbs);
    transaction.commit();
    assertThat(redisson.getBuckets().get("test1", "test2")).isEqualTo(bbs);
    assertThat(redisson.getKeys().count()).isEqualTo(2);
}
Also used : RBuckets(org.redisson.api.RBuckets) RTransaction(org.redisson.api.RTransaction) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 25 with RTransaction

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

the class RedissonTransactionalBucketsTest method testTrySet.

@Test
public void testTrySet() {
    redisson.getBucket("test1").set("1");
    redisson.getBucket("test2").set("2");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBuckets buckets = transaction.getBuckets();
    Map<String, Object> bbs1 = new LinkedHashMap<>();
    bbs1.put("test1", "10");
    bbs1.put("test2", "20");
    assertThat(buckets.trySet(bbs1)).isFalse();
    assertThat(redisson.getKeys().delete("test1", "test2")).isEqualTo(2);
    Map<String, Object> bbs2 = new LinkedHashMap<>();
    bbs2.put("test1", "11");
    bbs2.put("test2", "22");
    assertThat(buckets.trySet(bbs2)).isTrue();
    Map<String, Object> bbs3 = new LinkedHashMap<>();
    bbs3.put("test1", "13");
    bbs3.put("test2", "23");
    assertThat(buckets.trySet(bbs3)).isFalse();
    System.out.println("commit " + Thread.currentThread().getId());
    transaction.commit();
    redisson.getKeys().getKeys().forEach(x -> System.out.println(x));
    // assertThat(redisson.getBuckets().get("test1", "test2")).isEqualTo(bbs2);
    assertThat(redisson.getKeys().count()).isEqualTo(2);
}
Also used : RBuckets(org.redisson.api.RBuckets) RTransaction(org.redisson.api.RTransaction) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

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