use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testRollback.
@Test
public void testRollback() {
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(m.get("3")).isEqualTo("4");
transaction.rollback();
assertThat(redisson.getKeys().count()).isEqualTo(1);
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.get("3")).isEqualTo("4");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testReplace2.
@Test
public void testReplace2() {
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", "4", "10")).isTrue();
assertThat(map.replace("1", "1", "3")).isFalse();
assertThat(map.replace("3", "10", "11")).isTrue();
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.size()).isEqualTo(2);
transaction.commit();
assertThat(m.size()).isEqualTo(2);
assertThat(m.get("3")).isEqualTo("11");
assertThat(m.get("1")).isEqualTo("2");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testRemove.
@Test
public void testRemove() {
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.remove("3")).isNull();
assertThat(map.remove("3")).isNull();
assertThat(m.get("3")).isEqualTo("4");
transaction.commit();
assertThat(m.get("1")).isEqualTo("2");
assertThat(m.get("3")).isNull();
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalBucketTest method testRollback.
@Test
public void testRollback() {
RBucket<Object> b = redisson.getBucket("test");
b.set("1234");
RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
RBucket<Object> bucket = transaction.getBucket("test");
assertThat(bucket.get()).isEqualTo("1234");
assertThat(bucket.getAndDelete()).isEqualTo("1234");
assertThat(b.get()).isEqualTo("1234");
transaction.rollback();
assertThat(redisson.getKeys().count()).isEqualTo(1);
assertThat(b.get()).isEqualTo("1234");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalBucketTest method testTimeout.
@Test
public void testTimeout() throws InterruptedException {
RBucket<String> b = redisson.getBucket("test");
b.set("123");
RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(3, TimeUnit.SECONDS));
RBucket<String> bucket = transaction.getBucket("test");
bucket.set("234");
Thread.sleep(4000);
try {
transaction.commit();
Assertions.fail();
} catch (TransactionException e) {
// skip
}
Thread.sleep(1000);
assertThat(b.get()).isEqualTo("123");
}
Aggregations