|
|
|
@ -15,13 +15,11 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testLong() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Long> list = redisson.getList("list");
|
|
|
|
|
list.add(1L);
|
|
|
|
|
list.add(2L);
|
|
|
|
|
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(1L, 2L));
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
@ -38,7 +36,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
|
public void testListIteratorSetFail() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
|
|
|
|
@ -46,11 +43,7 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
iterator.next();
|
|
|
|
|
iterator.add(2);
|
|
|
|
|
try {
|
|
|
|
|
iterator.set(3);
|
|
|
|
|
} finally {
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
iterator.set(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -81,7 +74,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testListIteratorGetSet() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -104,8 +96,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(3, 2, 31, 3, 4, 71));
|
|
|
|
|
iterator.add(8);
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(3, 2, 31, 3, 4, 71, 8));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -178,7 +168,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testListIteratorIndex() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -208,13 +197,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertTrue(10 == iterator.next());
|
|
|
|
|
Assert.assertTrue(9 == iterator.previousIndex());
|
|
|
|
|
Assert.assertTrue(10 == iterator.nextIndex());
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testListIteratorPrevious() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -246,13 +232,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertTrue(iterator.hasPrevious());
|
|
|
|
|
Assert.assertTrue(1 == iterator.previous());
|
|
|
|
|
Assert.assertFalse(iterator.hasPrevious());
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testLastIndexOf2() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -267,13 +250,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
int index = list.lastIndexOf(3);
|
|
|
|
|
Assert.assertEquals(2, index);
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testLastIndexOf1() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -288,13 +268,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
int index = list.lastIndexOf(3);
|
|
|
|
|
Assert.assertEquals(5, index);
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testLastIndexOf() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -309,8 +286,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
int index = list.lastIndexOf(3);
|
|
|
|
|
Assert.assertEquals(8, index);
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -352,7 +327,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSubList() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -367,13 +341,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
List<Integer> subList = list.subList(3, 7);
|
|
|
|
|
Assert.assertThat(subList, Matchers.contains(4, 5, 6, 7));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIndexOf() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
for (int i = 1; i < 200; i++) {
|
|
|
|
|
list.add(i);
|
|
|
|
@ -383,14 +354,11 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertTrue(99 == list.indexOf(100));
|
|
|
|
|
Assert.assertTrue(-1 == list.indexOf(200));
|
|
|
|
|
Assert.assertTrue(-1 == list.indexOf(0));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRemove() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -402,13 +370,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertTrue(1 == val);
|
|
|
|
|
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(2, 3, 4, 5));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSet() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -419,12 +384,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.set(4, 6);
|
|
|
|
|
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(1, 2, 3, 4, 6));
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = IndexOutOfBoundsException.class)
|
|
|
|
|
public void testSetFail() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -432,11 +395,7 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.add(4);
|
|
|
|
|
list.add(5);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
list.set(5, 6);
|
|
|
|
|
} finally {
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
list.set(5, 6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -456,7 +415,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRemoveAll() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -475,14 +433,11 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.removeAll(Arrays.asList(1, 5, 1, 5));
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(list.isEmpty());
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testAddAllIndex() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -501,8 +456,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.addAll(list.size(), Arrays.asList(0, 5));
|
|
|
|
|
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(1, 2, 7, 8, 9, 3, 4, 9, 1, 9, 5, 0, 5));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -528,7 +481,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testAddAll() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
list.add(1);
|
|
|
|
|
list.add(2);
|
|
|
|
@ -541,13 +493,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.addAll(Arrays.asList(9, 1, 9));
|
|
|
|
|
|
|
|
|
|
Assert.assertThat(list, Matchers.contains(1, 2, 3, 4, 5, 7, 8, 9, 9, 1, 9));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testContainsAll() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<Integer> list = redisson.getList("list");
|
|
|
|
|
for (int i = 0; i < 200; i++) {
|
|
|
|
|
list.add(i);
|
|
|
|
@ -555,13 +504,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(list.containsAll(Arrays.asList(30, 11)));
|
|
|
|
|
Assert.assertFalse(list.containsAll(Arrays.asList(30, 711, 11)));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testToArray() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("4");
|
|
|
|
@ -573,14 +519,11 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
String[] strs = list.toArray(new String[0]);
|
|
|
|
|
Assert.assertArrayEquals(strs, new String[] {"1", "4", "2", "5", "3"});
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIteratorRemove() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("4");
|
|
|
|
@ -608,13 +551,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(0, list.size());
|
|
|
|
|
Assert.assertTrue(list.isEmpty());
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIteratorSequence() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("4");
|
|
|
|
@ -625,8 +565,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
checkIterator(list);
|
|
|
|
|
// to test "memory effect" absence
|
|
|
|
|
checkIterator(list);
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkIterator(List<String> list) {
|
|
|
|
@ -644,7 +582,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testContains() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("4");
|
|
|
|
@ -655,13 +592,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
Assert.assertTrue(list.contains("3"));
|
|
|
|
|
Assert.assertFalse(list.contains("31"));
|
|
|
|
|
Assert.assertTrue(list.contains("1"));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = IndexOutOfBoundsException.class)
|
|
|
|
|
public void testGetFail2() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
|
|
|
|
|
list.get(0);
|
|
|
|
@ -669,7 +603,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test(expected = IndexOutOfBoundsException.class)
|
|
|
|
|
public void testGetFail() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
|
|
|
|
|
list.get(0);
|
|
|
|
@ -677,7 +610,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testAddGet() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
list.add("1");
|
|
|
|
|
list.add("4");
|
|
|
|
@ -690,13 +622,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
String val2 = list.get(3);
|
|
|
|
|
Assert.assertEquals("5", val2);
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDuplicates() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<TestObject> list = redisson.getList("list");
|
|
|
|
|
|
|
|
|
|
list.add(new TestObject("1", "2"));
|
|
|
|
@ -706,13 +635,10 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
list.add(new TestObject("5", "6"));
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(5, list.size());
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSize() {
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
List<String> list = redisson.getList("list");
|
|
|
|
|
|
|
|
|
|
list.add("1");
|
|
|
|
@ -728,8 +654,6 @@ public class RedissonListTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
list.remove("4");
|
|
|
|
|
Assert.assertThat(list, Matchers.contains("1", "3", "5", "6"));
|
|
|
|
|
|
|
|
|
|
clear(list, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|