|
|
|
@ -1,23 +1,32 @@
|
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatNoException;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.redisson.RedisRunner.FailedToStartRedisException;
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
import org.redisson.api.RList;
|
|
|
|
|
import org.redisson.api.RSet;
|
|
|
|
|
import org.redisson.api.RTransaction;
|
|
|
|
|
import org.redisson.api.SortOrder;
|
|
|
|
|
import org.redisson.api.TransactionOptions;
|
|
|
|
|
import org.redisson.client.codec.IntegerCodec;
|
|
|
|
|
import org.redisson.client.codec.StringCodec;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
|
|
|
|
|
public static class SimpleBean implements Serializable {
|
|
|
|
@ -98,21 +107,21 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Integer> descSort = list.readSort(SortOrder.DESC);
|
|
|
|
|
assertThat(descSort).containsExactly(3, 2, 1);
|
|
|
|
|
|
|
|
|
|
Set<Integer> ascSort = list.readSort(SortOrder.ASC);
|
|
|
|
|
assertThat(ascSort).containsExactly(1, 2, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSortOrderLimit() {
|
|
|
|
|
RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Integer> descSort = list.readSort(SortOrder.DESC, 1, 2);
|
|
|
|
|
assertThat(descSort).containsExactly(2, 1);
|
|
|
|
|
|
|
|
|
@ -126,29 +135,29 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
|
|
|
|
|
redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
|
|
|
|
|
redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Integer> descSort = list.readSort("test*", SortOrder.DESC);
|
|
|
|
|
assertThat(descSort).containsExactly(1, 2, 3);
|
|
|
|
|
|
|
|
|
|
Set<Integer> ascSort = list.readSort("test*", SortOrder.ASC);
|
|
|
|
|
assertThat(ascSort).containsExactly(3, 2, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSortOrderByPatternLimit() {
|
|
|
|
|
RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
|
|
|
|
|
redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
|
|
|
|
|
redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Integer> descSort = list.readSort("test*", SortOrder.DESC, 1, 2);
|
|
|
|
|
assertThat(descSort).containsExactly(2, 3);
|
|
|
|
|
|
|
|
|
@ -162,37 +171,37 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("2");
|
|
|
|
|
list.add("3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("test1", IntegerCodec.INSTANCE).set(1);
|
|
|
|
|
redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
|
|
|
|
|
redisson.getBucket("test3", IntegerCodec.INSTANCE).set(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("tester1", StringCodec.INSTANCE).set("obj1");
|
|
|
|
|
redisson.getBucket("tester2", StringCodec.INSTANCE).set("obj2");
|
|
|
|
|
redisson.getBucket("tester3", StringCodec.INSTANCE).set("obj3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Collection<String> descSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.DESC);
|
|
|
|
|
assertThat(descSort).containsExactly("obj3", "obj2", "obj1");
|
|
|
|
|
|
|
|
|
|
Collection<String> ascSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.ASC);
|
|
|
|
|
assertThat(ascSort).containsExactly("obj1", "obj2", "obj3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSortOrderByPatternGetLimit() {
|
|
|
|
|
RSet<String> list = redisson.getSet("list", StringCodec.INSTANCE);
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("2");
|
|
|
|
|
list.add("3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("test1", IntegerCodec.INSTANCE).set(1);
|
|
|
|
|
redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
|
|
|
|
|
redisson.getBucket("test3", IntegerCodec.INSTANCE).set(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("tester1", StringCodec.INSTANCE).set("obj1");
|
|
|
|
|
redisson.getBucket("tester2", StringCodec.INSTANCE).set("obj2");
|
|
|
|
|
redisson.getBucket("tester3", StringCodec.INSTANCE).set("obj3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Collection<String> descSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.DESC, 1, 2);
|
|
|
|
|
assertThat(descSort).containsExactly("obj2", "obj1");
|
|
|
|
|
|
|
|
|
@ -324,7 +333,7 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
assertThat(list.sortTo("test3", SortOrder.DESC)).isEqualTo(3);
|
|
|
|
|
RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list2).containsExactly("3", "2", "1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(list.sortTo("test4", SortOrder.ASC)).isEqualTo(3);
|
|
|
|
|
RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list3).containsExactly("1", "2", "3");
|
|
|
|
@ -337,11 +346,11 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(list.sortTo("test3", SortOrder.DESC, 1, 2)).isEqualTo(2);
|
|
|
|
|
RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list2).containsExactly("2", "1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(list.sortTo("test4", SortOrder.ASC, 1, 2)).isEqualTo(2);
|
|
|
|
|
RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list3).containsExactly("2", "3");
|
|
|
|
@ -353,21 +362,21 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
|
|
|
|
|
redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
|
|
|
|
|
redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(list.sortTo("tester3", "test*", SortOrder.DESC, 1, 2)).isEqualTo(2);
|
|
|
|
|
RList<String> list2 = redisson.getList("tester3", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list2).containsExactly("2", "3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(list.sortTo("tester4", "test*", SortOrder.ASC, 1, 2)).isEqualTo(2);
|
|
|
|
|
RList<String> list3 = redisson.getList("tester4", StringCodec.INSTANCE);
|
|
|
|
|
assertThat(list3).containsExactly("2", "1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRemoveRandom() {
|
|
|
|
|
RSet<Integer> set = redisson.getSet("simple");
|
|
|
|
@ -380,7 +389,7 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
assertThat(set.removeRandom()).isIn(1, 2, 3);
|
|
|
|
|
assertThat(set.removeRandom()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRemoveRandomAmount() {
|
|
|
|
|
RSet<Integer> set = redisson.getSet("simple");
|
|
|
|
@ -403,11 +412,11 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
set.add(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(set.random(3)).containsAnyElementsOf(set.readAll()).hasSize(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRandom() {
|
|
|
|
|
RSet<Integer> set = redisson.getSet("simple");
|
|
|
|
@ -571,7 +580,7 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
assertThat(keys).hasSize(size);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIteratorRemoveHighVolume() throws InterruptedException {
|
|
|
|
|
Set<Integer> set = redisson.getSet("set") /*new HashSet<Integer>()*/;
|
|
|
|
@ -789,7 +798,7 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
assertThat(set).containsOnly(6, 5, 7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testMove() throws Exception {
|
|
|
|
|
RSet<Integer> set = redisson.getSet("set");
|
|
|
|
@ -819,8 +828,8 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
Assertions.assertEquals(1, set.size());
|
|
|
|
|
Assertions.assertEquals(0, otherSet.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRemoveAllEmpty() {
|
|
|
|
|
Set<Integer> list = redisson.getSet("list");
|
|
|
|
@ -890,4 +899,22 @@ public class RedissonSetTest extends RedisDockerTest {
|
|
|
|
|
assertThat(strings).containsAll(stringsOne);
|
|
|
|
|
assertThat(strings).hasSize(stringsOne.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testAddAndContainsInTransactionShouldNotShowResourceLeak() {
|
|
|
|
|
int arbitraryElementsCount = 1000;
|
|
|
|
|
|
|
|
|
|
RTransaction tx = redisson.createTransaction(TransactionOptions.defaults());
|
|
|
|
|
RSet<Integer> testSet = tx.getSet("testSet");
|
|
|
|
|
// Should check the log when we run this test and see if there is any resource leak error
|
|
|
|
|
assertThatNoException().isThrownBy(()->{
|
|
|
|
|
for (int index = 0; index < arbitraryElementsCount; index++) {
|
|
|
|
|
testSet.add(index);
|
|
|
|
|
if (testSet.contains(index)) {
|
|
|
|
|
System.out.println("Element " + index + " is in the set");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
tx.commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|