use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testPutRemove.
@Test
public void testPutRemove() {
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.get("1")).isEqualTo("2");
assertThat(map.remove("3")).isEqualTo("4");
assertThat(map.put("3", "5")).isNull();
assertThat(map.get("3")).isEqualTo("5");
assertThat(m.get("3")).isEqualTo("4");
transaction.commit();
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.get("3")).isEqualTo("5");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testPutIfAbsentRemove.
@Test
public void testPutIfAbsentRemove() {
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.putIfAbsent("3", "2")).isEqualTo("4");
assertThat(map.putIfAbsent("5", "6")).isNull();
assertThat(map.putIfAbsent("5", "7")).isEqualTo("6");
assertThat(map.remove("5")).isEqualTo("6");
assertThat(map.putIfAbsent("5", "8")).isNull();
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.size()).isEqualTo(2);
transaction.commit();
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.get("5")).isEqualTo("8");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testParallel.
@Test
public void testParallel() {
Assertions.assertThrows(TransactionTimeoutException.class, () -> {
RMap<Integer, String> m = redisson.getMap("test");
m.put(1, "test");
RTransaction transaction1 = redisson.createTransaction(TransactionOptions.defaults().timeout(10, TimeUnit.SECONDS));
RMap<Integer, String> map1 = transaction1.getMap("put_test");
map1.remove(1);
RTransaction transaction2 = redisson.createTransaction(TransactionOptions.defaults());
RMap<Integer, String> map2 = transaction2.getMap("put_test");
map2.put(1, "aryan");
try {
transaction2.commit();
Assertions.fail();
} catch (TransactionTimeoutException e) {
// skip
}
transaction1.commit();
assertThat(m.size()).isZero();
});
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testKeySet.
@Test
public void testKeySet() {
RMap<String, String> m = getMap();
m.put("1", "2");
m.put("3", "4");
RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
RMap<String, String> map = getTransactionalMap(t);
map.remove("3");
assertThat(map.keySet()).containsOnly("1");
assertThat(m.keySet()).containsOnly("1", "3");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testPutIfAbsent.
@Test
public void testPutIfAbsent() {
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.putIfAbsent("3", "2")).isEqualTo("4");
assertThat(map.putIfAbsent("5", "6")).isNull();
assertThat(map.putIfAbsent("5", "7")).isEqualTo("6");
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.size()).isEqualTo(2);
transaction.commit();
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.get("5")).isEqualTo("6");
}
Aggregations