DATAREDIS-937 - Polishing.

Original Pull Request: #386
This commit is contained in:
Christoph Strobl
2019-02-27 12:30:25 +01:00
parent 22698a2976
commit 3816b41dc8
11 changed files with 278 additions and 18 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.data.redis.connection;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.DoubleUnaryOperator;
import java.util.function.Function;
@@ -30,6 +29,7 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* ZSet(SortedSet)-specific commands supported by Redis.
@@ -166,19 +166,32 @@ public interface RedisZSetCommands {
return Collections.unmodifiableList(weights);
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (!(o instanceof Weights))
}
if (!(o instanceof Weights)) {
return false;
Weights weights1 = (Weights) o;
return Objects.equals(weights, weights1.weights);
}
Weights that = (Weights) o;
return ObjectUtils.nullSafeEquals(this.weights, that.weights);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return Objects.hash(weights);
return ObjectUtils.nullSafeHashCode(weights);
}
}

View File

@@ -62,28 +62,31 @@ suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M
* Coroutines variant of [ReactiveGeoOperations.distance].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.distanceAndAwait(key: K, member1: M, member2: M): Distance =
distance(key, member1, member2).awaitSingle()
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.distanceAndAwait(key: K, member1: M, member2: M): Distance? =
distance(key, member1, member2).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveGeoOperations.distance].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.distanceAndAwait(key: K, member1: M, member2: M, metric: Metric): Distance =
distance(key, member1, member2, metric).awaitSingle()
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.distanceAndAwait(key: K, member1: M, member2: M, metric: Metric): Distance? =
distance(key, member1, member2, metric).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveGeoOperations.hash].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.hashAndAwait(key: K, member: M): String =
hash(key, member).awaitSingle()
suspend inline fun <reified K : Any, reified M : Any> ReactiveGeoOperations<K, M>.hashAndAwait(key: K, member: M): String? =
hash(key, member).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveGeoOperations.hash].

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.core
import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactive.awaitSingle
/**
@@ -30,10 +31,11 @@ suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> Reactiv
* Coroutines variant of [ReactiveHashOperations.get].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> ReactiveHashOperations<H, HK, HV>.getAndAwait(key: H, hashKey: HK): HV =
get(key, hashKey).awaitSingle()
suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> ReactiveHashOperations<H, HK, HV>.getAndAwait(key: H, hashKey: HK): HV? =
get(key, hashKey).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveHashOperations.multiGet].
@@ -106,3 +108,12 @@ suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> Reactiv
*/
suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> ReactiveHashOperations<H, HK, HV>.removeAndAwait(key: H, vararg hashKeys: Any): Long =
remove(key, *hashKeys).awaitSingle()
/**
* Coroutines variant of [ReactiveListOperations.delete].
*
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified H : Any, reified HK : Any, reified HV : Any> ReactiveHashOperations<H, HK, HV>.deleteAndAwait(key: H): Boolean =
delete(key).awaitSingle()

View File

@@ -105,10 +105,11 @@ suspend inline fun <reified K : Any, reified V : Any> ReactiveValueOperations<K,
* Coroutines variant of [ReactiveValueOperations.getAndSet].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified K : Any, reified V : Any> ReactiveValueOperations<K, V>.getAndSetAndAwait(key: K, value: V): V? =
getAndSet(key, value).awaitSingle()
getAndSet(key, value).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveValueOperations.multiGet].
@@ -204,10 +205,11 @@ suspend inline fun <reified K : Any, reified V : Any> ReactiveValueOperations<K,
* Coroutines variant of [ReactiveValueOperations.size].
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.2
*/
suspend inline fun <reified K : Any, reified V : Any> ReactiveValueOperations<K, V>.sizeAndAwait(key: K): Long? =
size(key).awaitFirstOrNull()
suspend inline fun <reified K : Any, reified V : Any> ReactiveValueOperations<K, V>.sizeAndAwait(key: K): Long =
size(key).awaitSingle()
/**
* Coroutines variant of [ReactiveValueOperations.setBit].

View File

@@ -31,6 +31,7 @@ import reactor.core.publisher.Mono
* Unit tests for [ReactiveGeoOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveGeoOperationsExtensionsUnitTests {
@@ -109,6 +110,21 @@ class ReactiveGeoOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `distance returning an empty Mono`() {
val operations = mockk<ReactiveGeoOperations<String, String>>()
every { operations.distance(any(), any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.distanceAndAwait("foo", "from", "to")).isNull()
}
verify {
operations.distance("foo", "from", "to")
}
}
@Test // DATAREDIS-937
fun distanceWithMetric() {
@@ -124,6 +140,21 @@ class ReactiveGeoOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `distance with Metric returning an empty Mono`() {
val operations = mockk<ReactiveGeoOperations<String, String>>()
every { operations.distance(any(), any(), any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.distanceAndAwait("foo", "from", "to", Metrics.KILOMETERS)).isNull()
}
verify {
operations.distance("foo", "from", "to", Metrics.KILOMETERS)
}
}
@Test // DATAREDIS-937
fun hash() {
@@ -139,6 +170,21 @@ class ReactiveGeoOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `hash returning an empty Mono`() {
val operations = mockk<ReactiveGeoOperations<String, String>>()
every { operations.hash(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.hashAndAwait("foo", "bar")).isNull()
}
verify {
operations.hash("foo", "bar")
}
}
@Test // DATAREDIS-937
fun hashVararg() {
@@ -170,6 +216,21 @@ class ReactiveGeoOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `position returning an empty Mono`() {
val operations = mockk<ReactiveGeoOperations<String, String>>()
every { operations.position(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.positionAndAwait("foo", "bar")).isNull()
}
verify {
operations.position("foo", "bar")
}
}
@Test // DATAREDIS-937
fun positionVararg() {

View File

@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono
* Unit tests for [ReactiveHashOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveHashOperationsExtensionsUnitTests {
@@ -60,6 +61,21 @@ class ReactiveHashOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `get returning an empty Mono`() {
val operations = mockk<ReactiveHashOperations<String, String, String>>()
every { operations.get(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.getAndAwait("foo", "bar")).isNull()
}
verify {
operations.get("foo", "bar")
}
}
@Test // DATAREDIS-937
fun multiGet() {
@@ -179,4 +195,19 @@ class ReactiveHashOperationsExtensionsUnitTests {
operations.remove("foo", "bar")
}
}
@Test // DATAREDIS-937
fun delete() {
val operations = mockk<ReactiveHashOperations<String, String, String>>()
every { operations.delete(any()) } returns Mono.just(true)
runBlocking {
assertThat(operations.deleteAndAwait("foo")).isTrue()
}
verify {
operations.delete("foo")
}
}
}

View File

@@ -25,7 +25,7 @@ import reactor.core.publisher.Mono
import java.time.Duration
/**
* Unit tests for [ReactiveHyperLogLogOperationsExtensions]
* Unit tests for [ReactiveListOperationsExtensions]
*
* @author Mark Paluch
*/

View File

@@ -30,6 +30,7 @@ import java.time.Instant
* Unit tests for [ReactiveRedisOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveRedisOperationsExtensionsUnitTests {
@@ -93,6 +94,21 @@ class ReactiveRedisOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `randomKey returning an empty Mono`() {
val operations = mockk<ReactiveRedisOperations<String, String>>()
every { operations.randomKey() } returns Mono.empty()
runBlocking {
assertThat(operations.randomKeyAndAwait()).isNull();
}
verify {
operations.randomKey()
}
}
@Test // DATAREDIS-937
fun rename() {

View File

@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono
* Unit tests for [ReactiveSetOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveSetOperationsExtensionsUnitTests {
@@ -75,6 +76,21 @@ class ReactiveSetOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `pop returning an empty Mono`() {
val operations = mockk<ReactiveSetOperations<String, String>>()
every { operations.pop(any()) } returns Mono.empty();
runBlocking {
assertThat(operations.popAndAwait("foo")).isNull()
}
verify {
operations.pop("foo")
}
}
@Test // DATAREDIS-937
fun move() {
@@ -225,6 +241,21 @@ class ReactiveSetOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `randomMember returning an empty Mono`() {
val operations = mockk<ReactiveSetOperations<String, String>>()
every { operations.randomMember(any()) } returns Mono.empty()
runBlocking {
assertThat(operations.randomMemberAndAwait("foo")).isNull()
}
verify {
operations.randomMember("foo")
}
}
@Test // DATAREDIS-937
fun delete() {

View File

@@ -29,6 +29,7 @@ import java.time.Duration
* Unit tests for [ReactiveValueOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveValueOperationsExtensionsUnitTests {
@@ -167,6 +168,21 @@ class ReactiveValueOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `get returning an empty Mono`() {
val operations = mockk<ReactiveValueOperations<String, String>>()
every { operations.get(any()) } returns Mono.empty()
runBlocking {
assertThat(operations.getAndAwait("foo")).isNull()
}
verify {
operations.get("foo")
}
}
@Test // DATAREDIS-937
fun getAndSet() {
@@ -182,6 +198,21 @@ class ReactiveValueOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `getAndSet returning an empty Mono`() {
val operations = mockk<ReactiveValueOperations<String, String>>()
every { operations.getAndSet(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.getAndSetAndAwait("foo", "bar")).isNull()
}
verify {
operations.getAndSet("foo", "bar")
}
}
@Test // DATAREDIS-937
fun multiGet() {
@@ -302,6 +333,21 @@ class ReactiveValueOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `getSubstring returning an empty Mono`() {
val operations = mockk<ReactiveValueOperations<String, String>>()
every { operations.get(any(), any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.getAndAwait("foo", 1, 2)).isNull()
}
verify {
operations.get("foo", 1, 2)
}
}
@Test // DATAREDIS-937
fun setSubstring() {

View File

@@ -30,6 +30,7 @@ import reactor.core.publisher.Mono
* Unit tests for [ReactiveZSetOperationsExtensions].
*
* @author Mark Paluch
* @author Christoph Strobl
*/
class ReactiveZSetOperationsExtensionsUnitTests {
@@ -108,6 +109,21 @@ class ReactiveZSetOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `rank returning an empty Mono`() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.rank(any(), any()) } returns Mono.empty();
runBlocking {
assertThat(operations.rankAndAwait("foo", "bar")).isNull()
}
verify {
operations.rank("foo", "bar")
}
}
@Test // DATAREDIS-937
fun reverseRank() {
@@ -123,6 +139,21 @@ class ReactiveZSetOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `reverseRank returning an enpty Mono`() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.reverseRank(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.reverseRankAndAwait("foo", "bar")).isNull()
}
verify {
operations.reverseRank("foo", "bar")
}
}
@Test // DATAREDIS-937
fun count() {
@@ -153,6 +184,21 @@ class ReactiveZSetOperationsExtensionsUnitTests {
}
}
@Test // DATAREDIS-937
fun `score returning an empty Mono`() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.score(any(), any()) } returns Mono.empty()
runBlocking {
assertThat(operations.scoreAndAwait("foo", "bar")).isNull()
}
verify {
operations.score("foo", "bar")
}
}
@Test // DATAREDIS-937
fun removeRange() {