Search in sources :

Example 41 with RTransaction

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

the class RedissonBaseTransactionalMapTest method testFastPut.

@Test
public void testFastPut() throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(2000);
    for (int i = 0; i < 2000; i++) {
        executor.submit(() -> {
            for (int j = 0; j < 100; j++) {
                RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
                RMap<String, String> map = getTransactionalMap(t);
                map.fastPut("1", "1");
                t.commit();
            }
        });
    }
    executor.shutdown();
    assertThat(executor.awaitTermination(2, TimeUnit.MINUTES)).isTrue();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) RTransaction(org.redisson.api.RTransaction) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 42 with RTransaction

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

the class RedissonBaseTransactionalMapTest method testReplace.

@Test
public void testReplace() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.replace("3", "10")).isEqualTo("4");
    assertThat(map.replace("5", "0")).isNull();
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.size()).isEqualTo(2);
    transaction.commit();
    assertThat(m.size()).isEqualTo(2);
    assertThat(m.get("3")).isEqualTo("10");
    assertThat(m.get("5")).isNull();
    RTransaction transaction2 = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map2 = getTransactionalMap(transaction2);
    assertThat(map2.replace("3", "20")).isEqualTo("10");
    assertThat(map2.replace("3", "30")).isEqualTo("20");
    assertThat(m.get("3")).isEqualTo("10");
    assertThat(m.size()).isEqualTo(2);
    transaction2.commit();
    assertThat(m.get("3")).isEqualTo("30");
}
Also used : RTransaction(org.redisson.api.RTransaction) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 43 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testAdd.

@Test
public void testAdd() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.add("4")).isTrue();
    assertThat(set.add("3")).isFalse();
    assertThat(set.contains("4")).isTrue();
    assertThat(s.contains("4")).isFalse();
    transaction.commit();
    assertThat(s.size()).isEqualTo(3);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isTrue();
    assertThat(s.contains("4")).isTrue();
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 44 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testKeySet.

@Test
public void testKeySet() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = t.getSetCache("test");
    set.remove("3");
    assertThat(set).containsOnly("1");
    assertThat(s).containsOnly("1", "3");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 45 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testRemove.

@Test
public void testRemove() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.contains("1")).isTrue();
    assertThat(set.remove("3")).isTrue();
    assertThat(set.remove("3")).isFalse();
    assertThat(set.remove("3")).isFalse();
    assertThat(s.contains("3")).isTrue();
    transaction.commit();
    assertThat(s.size()).isEqualTo(1);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isFalse();
}
Also used : RTransaction(org.redisson.api.RTransaction) 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