Skip to content

Commit

Permalink
DATAREDIS-1196 - Polishing.
Browse files Browse the repository at this point in the history
Tweak Redis 6.0.6 requirement wording. Join assertions where possible and use more concise assertions.

Original pull request: #563.
  • Loading branch information
mp911de committed Sep 16, 2020
1 parent 76cbe51 commit c72a848
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum Position {

/**
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
* Requires Redis 6.0.6.
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param element must not be {@literal null}.
Expand All @@ -64,7 +64,7 @@ default Long lPos(byte[] key, byte[] element) {

/**
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
* Requires Redis 6.0.6.
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param element must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ default Long bitPos(String key, boolean bit) {

/**
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
* Requires Redis 6.0.6.
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param element must not be {@literal null}.
Expand All @@ -703,7 +703,7 @@ default Long lPos(String key, String element) {

/**
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
* Requires Redis 6.0.6.
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param element must not be {@literal null}.
Expand Down Expand Up @@ -2059,7 +2059,7 @@ default RecordId xAdd(StringRecord record) {

/**
* Append the given {@link StringRecord} to the stream stored at {@link StringRecord#getStream()}.
*
*
* @param record must not be {@literal null}.
* @param options must not be {@literal null}, use {@link XAddOptions#none()} instead.
* @return the record Id. {@literal null} when used in pipeline / transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {

/**
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param value must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction or when not contained in list.
Expand All @@ -182,7 +182,7 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {

/**
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param value must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction or when not contained in list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public interface ListOperations<K, V> {

/**
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
Expand All @@ -227,7 +227,7 @@ public interface ListOperations<K, V> {

/**
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public interface ReactiveListOperations<K, V> {

/**
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
Expand All @@ -210,7 +210,7 @@ public interface ReactiveListOperations<K, V> {

/**
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
* Requires Redis 6.0.6
* Requires Redis 6.0.6 or newer.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.redis.support.collections;

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -24,10 +25,10 @@
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.assertj.core.api.Assumptions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
Expand Down Expand Up @@ -168,7 +169,7 @@ public void addAllIndexCollectionMiddle() {
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void testIndexOfObject() {

Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);

T t1 = getT();
T t2 = getT();
Expand Down Expand Up @@ -249,10 +250,10 @@ public void testRange() {
T t1 = getT();
T t2 = getT();

assertThat(list.range(0, -1).isEmpty()).isTrue();
assertThat(list.range(0, -1)).isEmpty();
list.add(t1);
list.add(t2);
assertThat(list.range(0, -1).size()).isEqualTo(2);
assertThat(list.range(0, -1)).hasSize(2);
assertThat(list.range(0, 0).get(0)).isEqualTo(t1);
assertThat(list.range(1, 1).get(0)).isEqualTo(t2);
}
Expand Down Expand Up @@ -285,12 +286,12 @@ public void testTrim() {
T t1 = getT();
T t2 = getT();

assertThat(list.trim(0, 0).isEmpty()).isTrue();
assertThat(list.trim(0, 0)).isEmpty();
list.add(t1);
list.add(t2);
assertThat(list.size()).isEqualTo(2);
assertThat(list.trim(0, 0).size()).isEqualTo(1);
assertThat(list.size()).isEqualTo(1);
assertThat(list).hasSize(2);
assertThat(list.trim(0, 0)).hasSize(1);
assertThat(list).hasSize(1);
assertThat(list.get(0)).isEqualTo(t1);
}

Expand All @@ -300,12 +301,12 @@ public void testCappedCollection() throws Exception {
RedisList<T> cappedList = new DefaultRedisList<T>(template.boundListOps(collection.getKey() + ":capped"), 1);
T first = getT();
cappedList.offer(first);
assertThat(cappedList.size()).isEqualTo(1);
assertThat(cappedList).hasSize(1);
cappedList.add(getT());
assertThat(cappedList.size()).isEqualTo(1);
assertThat(cappedList).hasSize(1);
T last = getT();
cappedList.add(last);
assertThat(cappedList.size()).isEqualTo(1);
assertThat(cappedList).hasSize(1);
assertThat(cappedList.get(0)).isEqualTo(first);
}

Expand Down Expand Up @@ -361,10 +362,8 @@ public void testDrainToCollectionWithMaxElements() {
List<T> c = new ArrayList<>();

list.drainTo(c, 2);
assertThat(list.size()).isEqualTo(1);
assertThat(list).contains(t3);
assertThat(c.size()).isEqualTo(2);
assertThat(c).contains(t1, t2);
assertThat(list).hasSize(1).contains(t3);
assertThat(c).hasSize(2).contains(t1, t2);
}

@SuppressWarnings("unchecked")
Expand All @@ -381,9 +380,8 @@ public void testDrainToCollection() {
List<T> c = new ArrayList<>();

list.drainTo(c);
assertThat(list.isEmpty()).isTrue();
assertThat(c.size()).isEqualTo(3);
assertThat(c).contains(t1, t2, t3);
assertThat(list).isEmpty();
assertThat(c).hasSize(3).contains(t1, t2, t3);
}

@Test
Expand Down Expand Up @@ -426,7 +424,7 @@ public void testPeekLast() {
list.add(t2);

assertThat(list.peekLast()).isEqualTo(t2);
assertThat(list.size()).isEqualTo(2);
assertThat(list).hasSize(2);
}

@Test
Expand All @@ -444,8 +442,7 @@ public void testPollLast() {

T last = list.pollLast();
assertThat(last).isEqualTo(t2);
assertThat(list.size()).isEqualTo(1);
assertThat(list).contains(t1);
assertThat(list).hasSize(1).contains(t1);
}

@Test
Expand All @@ -459,8 +456,7 @@ public void testPollLastTimeout() throws InterruptedException {

T last = list.pollLast(1, TimeUnit.MILLISECONDS);
assertThat(last).isEqualTo(t2);
assertThat(list.size()).isEqualTo(1);
assertThat(list).contains(t1);
assertThat(list).hasSize(1).contains(t1);
}

@Test
Expand Down Expand Up @@ -500,6 +496,7 @@ public void testRemoveLast() {

@Test
public void testRmoveLastOccurrence() {

T t1 = getT();
T t2 = getT();

Expand All @@ -509,11 +506,7 @@ public void testRmoveLastOccurrence() {
list.add(t2);

list.removeLastOccurrence(t2);
assertThat(list.size()).isEqualTo(3);
Iterator<T> iterator = list.iterator();
assertThat(iterator.next()).isEqualTo(t1);
assertThat(iterator.next()).isEqualTo(t2);
assertThat(iterator.next()).isEqualTo(t1);
assertThat(list).hasSize(3).containsExactly(t1, t2, t1);
}

@Test
Expand All @@ -535,7 +528,7 @@ public void testTakeLast() {
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lastIndexOf() {

Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);

T t1 = getT();
T t2 = getT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
* @param factory
* @param connFactory
*/
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate template) {
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate<Object, Object> template) {
super(factory, template);
}

RedisStore copyStore(RedisStore store) {
return new DefaultRedisList(store.getKey().toString(), store.getOperations());
return new DefaultRedisList<>(store.getKey(), store.getOperations());
}

AbstractRedisCollection<Object> createCollection() {
String redisName = getClass().getName();
return new DefaultRedisList(redisName, template);
return new DefaultRedisList<>(redisName, template);
}
}

0 comments on commit c72a848

Please sign in to comment.