diff --git a/pom.xml b/pom.xml index be8ee579e..193132c66 100644 --- a/pom.xml +++ b/pom.xml @@ -178,6 +178,40 @@ test + + + org.jetbrains.kotlin + kotlin-stdlib + true + + + + org.jetbrains.kotlin + kotlin-reflect + true + + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${kotlin-coroutines} + true + + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + ${kotlin-coroutines} + true + + + + io.mockk + mockk + ${mockk} + test + + diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensions.kt new file mode 100644 index 000000000..f028ab8cc --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensions.kt @@ -0,0 +1,131 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import org.springframework.data.geo.Distance +import org.springframework.data.geo.Metric +import org.springframework.data.geo.Point +import org.springframework.data.redis.connection.RedisGeoCommands + +/** + * Coroutines variant of [ReactiveGeoOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.addAndAwait(key: K, point: Point, member: M): Long = + add(key, point, member).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.addAndAwait(key: K, location: RedisGeoCommands.GeoLocation): Long = + add(key, location).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.addAndAwait(key: K, memberCoordinateMap: Map): Long = + add(key, memberCoordinateMap).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.addAndAwait(key: K, locations: Iterable>): Long = + add(key, locations).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.distance]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.distanceAndAwait(key: K, member1: M, member2: M): Distance = + distance(key, member1, member2).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.distance]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.distanceAndAwait(key: K, member1: M, member2: M, metric: Metric): Distance = + distance(key, member1, member2, metric).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.hash]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.hashAndAwait(key: K, member: M): String = + hash(key, member).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.hash]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.hashAndAwait(key: K, vararg member: M): List = + hash(key, *member).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.position]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.positionAndAwait(key: K, member: M): Point? = + position(key, member).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveGeoOperations.position]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.positionAndAwait(key: K, vararg members: M): List = + position(key, *members).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.remove]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.removeAndAwait(key: K, vararg member: M): Long = + remove(key, *member).awaitSingle() + +/** + * Coroutines variant of [ReactiveGeoOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveGeoOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensions.kt new file mode 100644 index 000000000..934982d81 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensions.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitSingle + +/** + * Coroutines variant of [ReactiveHashOperations.hasKey]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.hasKeyAndAwait(key: H, hashKey: HK): Boolean = + hasKey(key, hashKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.get]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.getAndAwait(key: H, hashKey: HK): HV = + get(key, hashKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.multiGet]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.multiGetAndAwait(key: H, vararg hashKeys: HK): List = + multiGet(key, hashKeys.toCollection(ArrayList())).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.increment]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.incrementAndAwait(key: H, hashKey: HK, delta: Long): Long = + increment(key, hashKey, delta).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.increment]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.incrementAndAwait(key: H, hashKey: HK, delta: Double): Double = + increment(key, hashKey, delta).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.sizeAndAwait(key: H): Long = + size(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.putAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.putAllAndAwait(key: H, map: Map): Boolean = + putAll(key, map).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.put]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.putAndAwait(key: H, hashKey: HK, hashValue: HV): Boolean = + put(key, hashKey, hashValue).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.putIfAbsent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.putIfAbsentAndAwait(key: H, hashKey: HK, hashValue: HV): Boolean = + putIfAbsent(key, hashKey, hashValue).awaitSingle() + +/** + * Coroutines variant of [ReactiveHashOperations.remove]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHashOperations.removeAndAwait(key: H, vararg hashKeys: Any): Long = + remove(key, *hashKeys).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensions.kt new file mode 100644 index 000000000..ad794ed06 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensions.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitSingle + +/** + * Coroutines variant of [ReactiveHyperLogLogOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHyperLogLogOperations.addAndAwait(key: K, vararg values: V): Long = + add(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveHyperLogLogOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHyperLogLogOperations.sizeAndAwait(vararg keys: K): Long = + size(*keys).awaitSingle() + +/** + * Coroutines variant of [ReactiveHyperLogLogOperations.union]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHyperLogLogOperations.unionAndAwait(destination: K, vararg sourceKeys: K): Boolean = + union(destination, *sourceKeys).awaitSingle() + +/** + * Coroutines variant of [ReactiveHyperLogLogOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveHyperLogLogOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensions.kt new file mode 100644 index 000000000..2282735e9 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensions.kt @@ -0,0 +1,200 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import java.time.Duration + +/** + * Coroutines variant of [ReactiveListOperations.trim]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.trimAndAwait(key: K, start: Long, end: Long): Boolean = + trim(key, start, end).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.sizeAndAwait(key: K): Long = + size(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.leftPush]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPushAndAwait(key: K, value: V): Long = + leftPush(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.leftPushAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPushAllAndAwait(key: K, vararg values: V): Long = + leftPushAll(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.leftPushAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPushAllAndAwait(key: K, values: Collection): Long = + leftPushAll(key, values).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.leftPushIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPushIfPresentAndAwait(key: K, value: V): Long = + leftPushIfPresent(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.leftPushIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPushAndAwait(key: K, pivot: V, value: V): Long = + leftPush(key, pivot, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.rightPush]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPushAndAwait(key: K, value: V): Long = + rightPush(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.rightPushAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPushAllAndAwait(key: K, vararg values: V): Long = + rightPushAll(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.rightPushAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPushAllAndAwait(key: K, values: Collection): Long = + rightPushAll(key, values).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.rightPushIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPushIfPresentAndAwait(key: K, value: V): Long = + rightPushIfPresent(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.rightPushIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPushAndAwait(key: K, pivot: V, value: V): Long = + rightPush(key, pivot, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.set]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.setAndAwait(key: K, index: Long, value: V): Boolean = + set(key, index, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.remove]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.removeAndAwait(key: K, count: Long, value: V): Long = + remove(key, count, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveListOperations.index]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.indexAndAwait(key: K, index: Long): V? = + index(key, index).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveListOperations.leftPop]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPopAndAwait(key: K): V? = + leftPop(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveListOperations.leftPop]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.leftPopAndAwait(key: K, timeout: Duration): V? = + leftPop(key, timeout).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveListOperations.rightPop]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPopAndAwait(key: K): V? = + rightPop(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveListOperations.rightPop]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.rightPopAndAwait(key: K, timeout: Duration): V? = + rightPop(key, timeout).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveListOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveListOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensions.kt new file mode 100644 index 000000000..ac7620d61 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensions.kt @@ -0,0 +1,137 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import org.springframework.data.redis.connection.DataType +import java.time.Duration +import java.time.Instant + +/** + * Coroutines variant of [ReactiveRedisOperations.convertAndSend]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.sendAndAwait(destination: String, message: V): Long = + convertAndSend(destination, message).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.hasKey]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.hasKeyAndAwait(key: K): Boolean = + hasKey(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.type]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.typeAndAwait(key: K): DataType = + type(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.randomKey]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.randomKeyAndAwait(): K? = + randomKey().awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveRedisOperations.rename]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.renameAndAwait(oldKey: K, newKey: K): Boolean = + rename(oldKey, newKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.renameIfAbsent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.renameIfAbsentAndAwait(oldKey: K, newKey: K): Boolean = + renameIfAbsent(oldKey, newKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.deleteAndAwait(vararg key: K): Long = + delete(*key).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.unlink]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.unlinkAndAwait(vararg key: K): Long = + unlink(*key).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.expire]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.expireAndAwait(key: K, timeout: Duration): Boolean = + expire(key, timeout).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.expireAt]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.expireAtAndAwait(key: K, expireAt: Instant): Boolean = expireAt(key, expireAt).awaitSingle() + + +/** + * Coroutines variant of [ReactiveRedisOperations.persist]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.persistAndAwait(key: K): Boolean = + persist(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.move]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.moveAndAwait(key: K, dbIndex: Int): Boolean = move(key, dbIndex).awaitSingle() + +/** + * Coroutines variant of [ReactiveRedisOperations.getExpire]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveRedisOperations.getExpireAndAwait(key: K): Duration? = getExpire(key).awaitFirstOrNull() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensions.kt new file mode 100644 index 000000000..24a97fe99 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensions.kt @@ -0,0 +1,147 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle + +/** + * Coroutines variant of [ReactiveSetOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.addAndAwait(key: K, vararg values: V): Long = + add(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.remove]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.removeAndAwait(key: K, vararg values: V): Long = + remove(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.pop]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.popAndAwait(key: K): V? = + pop(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveSetOperations.move]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.moveAndAwait(sourceKey: K, value: V, destKey: K): Boolean = + move(sourceKey, value, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.sizeAndAwait(key: K): Long = + size(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.isMember]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.isMemberAndAwait(key: K, value: V): Boolean = + isMember(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.intersectAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long = + intersectAndStore(key, otherKey, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.intersectAndStoreAndAwait(keys: Collection, destKey: K): Long = + intersectAndStore(keys, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.unionAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long = + unionAndStore(key, otherKey, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.unionAndStoreAndAwait(keys: Collection, destKey: K): Long = + unionAndStore(keys, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.differenceAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.differenceAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long = + differenceAndStore(key, otherKey, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.differenceAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.differenceAndStoreAndAwait(keys: Collection, destKey: K): Long = + differenceAndStore(keys, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveSetOperations.randomMember]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.randomMemberAndAwait(key: K): V? = + randomMember(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveSetOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveSetOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() + + diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensions.kt new file mode 100644 index 000000000..5feafa497 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensions.kt @@ -0,0 +1,145 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitSingle +import org.springframework.data.redis.connection.stream.* + +/** + * Coroutines variant of [ReactiveStreamOperations.acknowledge]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.acknowledgeAndAwait(key: K, group: String, vararg recordIds: String): Long = + acknowledge(key, group, *recordIds).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.acknowledge]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.acknowledgeAndAwait(key: K, group: String, vararg recordIds: RecordId): Long = + acknowledge(key, group, *recordIds).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.acknowledge]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.acknowledgeAndAwait(group: String, record: Record): Long = + acknowledge(group, record).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.addAndAwait(record: MapRecord): RecordId = + add(record).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.addAndAwait(record: Record): RecordId = + add(record).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.deleteAndAwait(key: K, vararg recordIds: String): Long = + delete(key, *recordIds).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.deleteAndAwait(record: Record): Long = + delete(record).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.deleteAndAwait(key: K, vararg recordIds: RecordId): Long = + delete(key, *recordIds).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.createGroup]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.createGroupAndAwait(key: K, group: String): String = + createGroup(key, group).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.createGroup]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.createGroupAndAwait(key: K, readOffset: ReadOffset, group: String): String = + createGroup(key, readOffset, group).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.deleteConsumer]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.deleteConsumerAndAwait(key: K, consumer: Consumer): String = + deleteConsumer(key, consumer).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.destroyGroup]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.destroyGroupAndAwait(key: K, group: String): String = + destroyGroup(key, group).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.sizeAndAwait(key: K): Long = + size(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveStreamOperations.trim]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveStreamOperations.trimAndAwait(key: K, count: Long): Long = + trim(key, count).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensions.kt new file mode 100644 index 000000000..db88967ba --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensions.kt @@ -0,0 +1,246 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import org.springframework.data.redis.connection.BitFieldSubCommands +import java.time.Duration + +/** + * Coroutines variant of [ReactiveValueOperations.set]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setAndAwait(key: K, value: V): Boolean = + set(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.set]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setAndAwait(key: K, value: V, timeout: Duration): Boolean = + set(key, value, timeout).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.setIfAbsent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setIfAbsentAndAwait(key: K, value: V): Boolean = + setIfAbsent(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.setIfAbsent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setIfAbsentAndAwait(key: K, value: V, timeout: Duration): Boolean = + setIfAbsent(key, value, timeout).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.setIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setIfPresentAndAwait(key: K, value: V): Boolean = + setIfPresent(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.setIfPresent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setIfPresentAndAwait(key: K, value: V, timeout: Duration): Boolean = + setIfPresent(key, value, timeout).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.multiSet]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.multiSetAndAwait(map: Map): Boolean = + multiSet(map).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.multiSetIfAbsent]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.multiSetIfAbsentAndAwait(map: Map): Boolean = + multiSetIfAbsent(map).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.get]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.getAndAwait(key: K): V? = + get(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveValueOperations.getAndSet]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.getAndSetAndAwait(key: K, value: V): V? = + getAndSet(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.multiGet]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.multiGetAndAwait(vararg keys: K): List = + multiGet(keys.toCollection(ArrayList())).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.multiGet]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.multiGetAndAwait(keys: Collection): List = + multiGet(keys).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.increment]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.incrementAndAwait(key: K): Long = + increment(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.increment]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.incrementAndAwait(key: K, delta: Long): Long = + increment(key, delta).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.increment]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.incrementAndAwait(key: K, delta: Double): Double = + increment(key, delta).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.decrement]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.decrementAndAwait(key: K): Long = + decrement(key).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.decrement]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.decrementAndAwait(key: K, delta: Long): Long = + decrement(key, delta).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.append]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.appendAndAwait(key: K, value: String): Long = + append(key, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.get]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.getAndAwait(key: K, start: Long, end: Long): String? = + get(key, start, end).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveValueOperations.set]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setAndAwait(key: K, value: V, offset: Long): Long = + set(key, value, offset).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.size]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.sizeAndAwait(key: K): Long? = + size(key).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveValueOperations.setBit]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.setBitAndAwait(key: K, offset: Long, value: Boolean): Boolean = + setBit(key, offset, value).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.getBit]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.getBitAndAwait(key: K, offset: Long): Boolean = + getBit(key, offset).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.bitField]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.bitFieldAndAwait(key: K, commands: BitFieldSubCommands): List = + bitField(key, commands).awaitSingle() + +/** + * Coroutines variant of [ReactiveValueOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveValueOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() diff --git a/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt b/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt new file mode 100644 index 000000000..16ad572c1 --- /dev/null +++ b/src/main/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensions.kt @@ -0,0 +1,192 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import org.springframework.data.domain.Range +import org.springframework.data.redis.connection.RedisZSetCommands + +/** + * Coroutines variant of [ReactiveZSetOperations.add]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.addAndAwait(key: K, value: V, score: Double): Boolean = + add(key, value, score).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.addAll]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.addAllAndAwait(key: K, values: Collection>): Long = + addAll(key, values).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.remove]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.removeAndAwait(key: K, vararg values: Any): Long = + remove(key, *values).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.incrementScore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.incrementScoreAndAwait(key: K, value: V, score: Double): Double = + incrementScore(key, value, score).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.rank]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.rankAndAwait(key: K, value: V): Long? = + rank(key, value).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveZSetOperations.reverseRank]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.reverseRankAndAwait(key: K, value: V): Long? = + reverseRank(key, value).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveZSetOperations.count]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.countAndAwait(key: K, range: Range): Long = + count(key, range).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.score]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.scoreAndAwait(key: K, value: V): Double? = + score(key, value).awaitFirstOrNull() + +/** + * Coroutines variant of [ReactiveZSetOperations.removeRange]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.removeRangeAndAwait(key: K, range: Range): Long = + removeRange(key, range).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.removeRangeByScore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.removeRangeByScoreAndAwait(key: K, range: Range): Long = + removeRangeByScore(key, range).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.unionAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long = + unionAndStore(key, otherKey, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.unionAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K): Long = + unionAndStore(key, otherKeys, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.unionAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate): Long = + unionAndStore(key, otherKeys, destKey, aggregate).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.unionAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.unionAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate, weights: RedisZSetCommands.Weights): Long = + unionAndStore(key, otherKeys, destKey, aggregate, weights).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.intersectAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long = + intersectAndStore(key, otherKey, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.intersectAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K): Long = + intersectAndStore(key, otherKeys, destKey).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.intersectAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate): Long = + intersectAndStore(key, otherKeys, destKey, aggregate).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.intersectAndStore]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.intersectAndStoreAndAwait(key: K, otherKeys: Collection, destKey: K, aggregate: RedisZSetCommands.Aggregate, weights: RedisZSetCommands.Weights): Long = + intersectAndStore(key, otherKeys, destKey, aggregate, weights).awaitSingle() + +/** + * Coroutines variant of [ReactiveZSetOperations.delete]. + * + * @author Mark Paluch + * @since 2.2 + */ +suspend inline fun ReactiveZSetOperations.deleteAndAwait(key: K): Boolean = + delete(key).awaitSingle() diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..d4dd973d5 --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveGeoOperationsExtensionsUnitTests.kt @@ -0,0 +1,217 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.springframework.data.geo.Distance +import org.springframework.data.geo.Metrics +import org.springframework.data.geo.Point +import org.springframework.data.redis.connection.RedisGeoCommands +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveGeoOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveGeoOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun addPoint() { + + val operations = mockk>() + every { operations.add(any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", Point(1.0, 2.0), "bar")).isEqualTo(1) + } + + verify { + operations.add("foo", Point(1.0, 2.0), "bar") + } + } + + @Test // DATAREDIS-937 + fun addGeoLocation() { + + val operations = mockk>() + every { operations.add(any(), any>()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", RedisGeoCommands.GeoLocation("bar", Point(1.0, 2.0)))).isEqualTo(1) + } + + verify { + operations.add("foo", RedisGeoCommands.GeoLocation("bar", Point(1.0, 2.0))) + } + } + + @Test // DATAREDIS-937 + fun addLocationMap() { + + val operations = mockk>() + every { operations.add(any(), any>()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", mapOf("foo" to Point(1.0, 2.0)))).isEqualTo(1) + } + + verify { + operations.add("foo", mapOf("foo" to Point(1.0, 2.0))) + } + } + + @Test // DATAREDIS-937 + fun addGeoLocationList() { + + val operations = mockk>() + every { operations.add(any(), any>>()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", listOf(RedisGeoCommands.GeoLocation("bar", Point(1.0, 2.0))))).isEqualTo(1) + } + + verify { + operations.add("foo", listOf(RedisGeoCommands.GeoLocation("bar", Point(1.0, 2.0)))) + } + } + + @Test // DATAREDIS-937 + fun distance() { + + val operations = mockk>() + every { operations.distance(any(), any(), any()) } returns Mono.just(Distance(2.0)) + + runBlocking { + assertThat(operations.distanceAndAwait("foo", "from", "to")).isEqualTo(Distance(2.0)) + } + + verify { + operations.distance("foo", "from", "to") + } + } + + @Test // DATAREDIS-937 + fun distanceWithMetric() { + + val operations = mockk>() + every { operations.distance(any(), any(), any(), any()) } returns Mono.just(Distance(2.0)) + + runBlocking { + assertThat(operations.distanceAndAwait("foo", "from", "to", Metrics.KILOMETERS)).isEqualTo(Distance(2.0)) + } + + verify { + operations.distance("foo", "from", "to", Metrics.KILOMETERS) + } + } + + @Test // DATAREDIS-937 + fun hash() { + + val operations = mockk>() + every { operations.hash(any(), any()) } returns Mono.just("baz") + + runBlocking { + assertThat(operations.hashAndAwait("foo", "bar")).isEqualTo("baz") + } + + verify { + operations.hash("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun hashVararg() { + + val operations = mockk>() + every { operations.hash(any(), any(), any()) } returns Mono.just(listOf("baz1", "baz2")) + + runBlocking { + assertThat(operations.hashAndAwait("foo", "bar", "baz")).isEqualTo(listOf("baz1", "baz2")) + } + + verify { + operations.hash("foo", "bar", "baz") + } + } + + + @Test // DATAREDIS-937 + fun position() { + + val operations = mockk>() + every { operations.position(any(), any()) } returns Mono.just(Point(1.0, 2.0)) + + runBlocking { + assertThat(operations.positionAndAwait("foo", "bar")).isEqualTo(Point(1.0, 2.0)) + } + + verify { + operations.position("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun positionVararg() { + + val operations = mockk>() + every { operations.position(any(), any(), any()) } returns Mono.just(listOf(Point(1.0, 2.0), Point(2.0, 3.0))) + + runBlocking { + assertThat(operations.positionAndAwait("foo", "bar", "baz")).isEqualTo(listOf(Point(1.0, 2.0), Point(2.0, 3.0))) + } + + verify { + operations.position("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.remove(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.remove("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + every { operations.delete(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.deleteAndAwait("foo")).isTrue() + } + + verify { + operations.delete("foo") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..4c0e3ac7c --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveHashOperationsExtensionsUnitTests.kt @@ -0,0 +1,182 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveHashOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveHashOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun hasKey() { + + val operations = mockk>() + every { operations.hasKey(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.hasKeyAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.hasKey("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun get() { + + val operations = mockk>() + every { operations.get(any(), any()) } returns Mono.just("baz") + + runBlocking { + assertThat(operations.getAndAwait("foo", "bar")).isEqualTo("baz") + } + + verify { + operations.get("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun multiGet() { + + val operations = mockk>() + every { operations.multiGet(any(), any()) } returns Mono.just(listOf("baz1", "baz2")) + + runBlocking { + assertThat(operations.multiGetAndAwait("foo", "bar", "joe")).isEqualTo(listOf("baz1", "baz2")) + } + + verify { + operations.multiGet("foo", listOf("bar", "joe")) + } + } + + @Test // DATAREDIS-937 + fun increment() { + + val operations = mockk>() + every { operations.increment(any(), any(), 1) } returns Mono.just(2) + + runBlocking { + assertThat(operations.incrementAndAwait("foo", "bar", 1)).isEqualTo(2) + } + + verify { + operations.increment("foo", "bar", 1) + } + } + + @Test // DATAREDIS-937 + fun incrementDouble() { + + val operations = mockk>() + every { operations.increment(any(), any(), 1.0) } returns Mono.just(2.0) + + runBlocking { + assertThat(operations.incrementAndAwait("foo", "bar", 1.0)).isEqualTo(2.0) + } + + verify { + operations.increment("foo", "bar", 1.0) + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun put() { + + val operations = mockk>() + every { operations.put(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.putAndAwait("foo", "bar", "baz")).isTrue() + } + + verify { + operations.put("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun putAll() { + + val operations = mockk>() + every { operations.putAll(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.putAllAndAwait("foo", mapOf("bar" to "baz"))).isTrue() + } + + verify { + operations.putAll("foo", mapOf("bar" to "baz")) + } + } + + @Test // DATAREDIS-937 + fun putIfAbsent() { + + val operations = mockk>() + every { operations.putIfAbsent(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.putIfAbsentAndAwait("foo", "bar", "baz")).isTrue() + } + + verify { + operations.putIfAbsent("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.remove(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.remove("foo", "bar") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..fe69dfb8f --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveHyperLogLogOperationsExtensionsUnitTests.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveHyperLogLogOperationsExtensions] + * + * @author Mark Paluch + */ +class ReactiveHyperLogLogOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun add() { + + val operations = mockk>() + every { operations.add(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.add("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size("foo") } returns Mono.just(1) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun union() { + + val operations = mockk>() + every { operations.union("foo", "bar", "baz") } returns Mono.just(true) + + runBlocking { + assertThat(operations.unionAndAwait("foo", "bar", "baz")).isTrue() + } + + verify { + operations.union("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.delete(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.deleteAndAwait("foo")).isTrue() + } + + verify { + operations.delete("foo") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..d6a20e74b --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensionsUnitTests.kt @@ -0,0 +1,334 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import reactor.core.publisher.Mono +import java.time.Duration + +/** + * Unit tests for [ReactiveHyperLogLogOperationsExtensions] + * + * @author Mark Paluch + */ +class ReactiveListOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun trim() { + + val operations = mockk>() + every { operations.trim(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.trimAndAwait("foo", 2, 3)).isTrue() + } + + verify { + operations.trim("foo", 2, 3) + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size(any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(2) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun leftPush() { + + val operations = mockk>() + every { operations.leftPush(any(), any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.leftPushAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.leftPush("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun leftPushAll() { + + val operations = mockk>() + every { operations.leftPushAll("foo", "bar", "baz") } returns Mono.just(2) + + runBlocking { + assertThat(operations.leftPushAllAndAwait("foo", "bar", "baz")).isEqualTo(2) + } + + verify { + operations.leftPushAll("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun leftPushAllCollection() { + + val operations = mockk>() + every { operations.leftPushAll("foo", listOf("bar", "baz")) } returns Mono.just(2) + + runBlocking { + assertThat(operations.leftPushAllAndAwait("foo", listOf("bar", "baz"))).isEqualTo(2) + } + + verify { + operations.leftPushAll("foo", listOf("bar", "baz")) + } + } + + @Test // DATAREDIS-937 + fun leftPushIfPresent() { + + val operations = mockk>() + every { operations.leftPushIfPresent(any(), any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.leftPushIfPresentAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.leftPushIfPresent("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun leftPushPivot() { + + val operations = mockk>() + every { operations.leftPush("foo", "bar", "baz") } returns Mono.just(2) + + runBlocking { + assertThat(operations.leftPushAndAwait("foo", "bar", "baz")).isEqualTo(2) + } + + verify { + operations.leftPush("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun rightPush() { + + val operations = mockk>() + every { operations.rightPush(any(), any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.rightPushAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.rightPush("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun rightPushAll() { + + val operations = mockk>() + every { operations.rightPushAll("foo", "bar", "baz") } returns Mono.just(2) + + runBlocking { + assertThat(operations.rightPushAllAndAwait("foo", "bar", "baz")).isEqualTo(2) + } + + verify { + operations.rightPushAll("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun rightPushAllCollection() { + + val operations = mockk>() + every { operations.rightPushAll("foo", listOf("bar", "baz")) } returns Mono.just(2) + + runBlocking { + assertThat(operations.rightPushAllAndAwait("foo", listOf("bar", "baz"))).isEqualTo(2) + } + + verify { + operations.rightPushAll("foo", listOf("bar", "baz")) + } + } + + @Test // DATAREDIS-937 + fun rightPushIfPresent() { + + val operations = mockk>() + every { operations.rightPushIfPresent(any(), any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.rightPushIfPresentAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.rightPushIfPresent("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun rightPushPivot() { + + val operations = mockk>() + every { operations.rightPush("foo", "bar", "baz") } returns Mono.just(2) + + runBlocking { + assertThat(operations.rightPushAndAwait("foo", "bar", "baz")).isEqualTo(2) + } + + verify { + operations.rightPush("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun set() { + + val operations = mockk>() + every { operations.set(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setAndAwait("foo", 1, "baz")).isTrue() + } + + verify { + operations.set("foo", 1, "baz") + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.remove(any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeAndAwait("foo", 1, "baz")).isEqualTo(1) + } + + verify { + operations.remove("foo", 1, "baz") + } + } + + @Test // DATAREDIS-937 + fun index() { + + val operations = mockk>() + every { operations.index(any(), any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.indexAndAwait("foo", 1)).isEqualTo("foo") + } + + verify { + operations.index("foo", 1) + } + } + + @Test // DATAREDIS-937 + fun leftPop() { + + val operations = mockk>() + every { operations.leftPop(any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.leftPopAndAwait("foo")).isEqualTo("foo") + } + + verify { + operations.leftPop("foo") + } + } + + @Test // DATAREDIS-937 + fun blockingLeftPop() { + + val operations = mockk>() + every { operations.leftPop(any(), any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.leftPopAndAwait("foo", Duration.ofDays(1))).isEqualTo("foo") + } + + verify { + operations.leftPop("foo", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun rightPop() { + + val operations = mockk>() + every { operations.rightPop(any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.rightPopAndAwait("foo")).isEqualTo("foo") + } + + verify { + operations.rightPop("foo") + } + } + + @Test // DATAREDIS-937 + fun blockingRightPop() { + + val operations = mockk>() + every { operations.rightPop(any(), any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.rightPopAndAwait("foo", Duration.ofDays(1))).isEqualTo("foo") + } + + verify { + operations.rightPop("foo", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + every { operations.delete(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.deleteAndAwait("foo")).isTrue() + } + + verify { + operations.delete("foo") + } + } + +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..444b3897d --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveRedisOperationsExtensionsUnitTests.kt @@ -0,0 +1,231 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.springframework.data.redis.connection.DataType +import reactor.core.publisher.Mono +import java.time.Duration +import java.time.Instant + +/** + * Unit tests for [ReactiveRedisOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveRedisOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun convertAndSend() { + + val operations = mockk>() + every { operations.convertAndSend(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.sendAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.convertAndSend("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun hasKey() { + + val operations = mockk>() + every { operations.hasKey(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.hasKeyAndAwait("foo")).isTrue() + } + + verify { + operations.hasKey("foo") + } + } + + @Test // DATAREDIS-937 + fun type() { + + val operations = mockk>() + every { operations.type(any()) } returns Mono.just(DataType.HASH) + + runBlocking { + assertThat(operations.typeAndAwait("foo")).isEqualTo(DataType.HASH) + } + + verify { + operations.type("foo") + } + } + + @Test // DATAREDIS-937 + fun randomKey() { + + val operations = mockk>() + every { operations.randomKey() } returns Mono.just("foo") + + runBlocking { + assertThat(operations.randomKeyAndAwait()).isEqualTo("foo") + } + + verify { + operations.randomKey() + } + } + + @Test // DATAREDIS-937 + fun rename() { + + val operations = mockk>() + every { operations.rename(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.renameAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.rename("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun renameIfAbsent() { + + val operations = mockk>() + every { operations.renameIfAbsent(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.renameIfAbsentAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.renameIfAbsent("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + every { operations.delete("foo", "bar") } returns Mono.just(2) + + runBlocking { + assertThat(operations.deleteAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.delete("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun unlink() { + + val operations = mockk>() + every { operations.unlink("foo", "bar") } returns Mono.just(2) + + runBlocking { + assertThat(operations.unlinkAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.unlink("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun expire() { + + val operations = mockk>() + every { operations.expire(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.expireAndAwait("foo", Duration.ofDays(1))).isTrue() + } + + verify { + operations.expire("foo", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun expireAt() { + + val operations = mockk>() + every { operations.expireAt(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.expireAtAndAwait("foo", Instant.ofEpochSecond(2))).isTrue() + } + + verify { + operations.expireAt("foo", Instant.ofEpochSecond(2)) + } + } + + @Test // DATAREDIS-937 + fun persist() { + + val operations = mockk>() + every { operations.persist(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.persistAndAwait("foo")).isTrue() + } + + verify { + operations.persist("foo") + } + } + + + @Test // DATAREDIS-937 + fun move() { + + val operations = mockk>() + every { operations.move(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.moveAndAwait("foo", 2)).isTrue() + } + + verify { + operations.move("foo", 2) + } + } + + @Test // DATAREDIS-937 + fun getExpire() { + + val operations = mockk>() + every { operations.getExpire(any()) } returns Mono.just(Duration.ofDays(1)) + + runBlocking { + assertThat(operations.getExpireAndAwait("foo")).isEqualTo(Duration.ofDays(1)) + } + + verify { + operations.getExpire("foo") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..2bbed882f --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveSetOperationsExtensionsUnitTests.kt @@ -0,0 +1,242 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveSetOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveSetOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun add() { + + val operations = mockk>() + every { operations.add("foo", "bar", "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAndAwait("foo", "bar", "baz")).isEqualTo(1) + } + + verify { + operations.add("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.remove("foo", "bar", "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeAndAwait("foo", "bar", "baz")).isEqualTo(1) + } + + verify { + operations.remove("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun pop() { + + val operations = mockk>() + every { operations.pop(any()) } returns Mono.just("bar") + + runBlocking { + assertThat(operations.popAndAwait("foo")).isEqualTo("bar") + } + + verify { + operations.pop("foo") + } + } + + @Test // DATAREDIS-937 + fun move() { + + val operations = mockk>() + every { operations.move(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.moveAndAwait("foo", "from", "to")).isTrue() + } + + verify { + operations.move("foo", "from", "to") + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun isMember() { + + val operations = mockk>() + every { operations.isMember("foo", "bar") } returns Mono.just(true) + + runBlocking { + assertThat(operations.isMemberAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.isMember("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun intersectAndStore() { + + val operations = mockk>() + every { operations.intersectAndStore("foo", "bar", "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait("foo", "bar", "baz")).isEqualTo(3) + } + + verify { + operations.intersectAndStore("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun intersectAndStoreCollection() { + + val operations = mockk>() + every { operations.intersectAndStore(listOf("foo", "bar"), "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait(listOf("foo", "bar"), "baz")).isEqualTo(3) + } + + verify { + operations.intersectAndStore(listOf("foo", "bar"), "baz") + } + } + + @Test // DATAREDIS-937 + fun unionAndStore() { + + val operations = mockk>() + every { operations.unionAndStore("foo", "bar", "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait("foo", "bar", "baz")).isEqualTo(3) + } + + verify { + operations.unionAndStore("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun unionAndStoreCollection() { + + val operations = mockk>() + every { operations.unionAndStore(listOf("foo", "bar"), "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait(listOf("foo", "bar"), "baz")).isEqualTo(3) + } + + verify { + operations.unionAndStore(listOf("foo", "bar"), "baz") + } + } + + @Test // DATAREDIS-937 + fun differenceAndStore() { + + val operations = mockk>() + every { operations.differenceAndStore("foo", "bar", "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.differenceAndStoreAndAwait("foo", "bar", "baz")).isEqualTo(3) + } + + verify { + operations.differenceAndStore("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun differenceAndStoreCollection() { + + val operations = mockk>() + every { operations.differenceAndStore(listOf("foo", "bar"), "baz") } returns Mono.just(3) + + runBlocking { + assertThat(operations.differenceAndStoreAndAwait(listOf("foo", "bar"), "baz")).isEqualTo(3) + } + + verify { + operations.differenceAndStore(listOf("foo", "bar"), "baz") + } + } + + @Test // DATAREDIS-937 + fun randomMember() { + + val operations = mockk>() + every { operations.randomMember(any()) } returns Mono.just("bar") + + runBlocking { + assertThat(operations.randomMemberAndAwait("foo")).isEqualTo("bar") + } + + verify { + operations.randomMember("foo") + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + every { operations.delete(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.deleteAndAwait("foo")).isTrue() + } + + verify { + operations.delete("foo") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..2e3abc676 --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensionsUnitTests.kt @@ -0,0 +1,250 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.springframework.data.redis.connection.stream.* +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveStreamOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveStreamOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun acknowledge() { + + val operations = mockk>() + every { operations.acknowledge("foo", "bar", "0-0") } returns Mono.just(1) + + runBlocking { + assertThat(operations.acknowledgeAndAwait("foo", "bar", "0-0")).isEqualTo(1) + } + + verify { + operations.acknowledge("foo", "bar", "0-0") + } + } + + @Test // DATAREDIS-937 + fun acknowledgeRecordId() { + + val operations = mockk>() + val recordId = RecordId.of("0-0") + every { operations.acknowledge("foo", "bar", recordId) } returns Mono.just(1) + + runBlocking { + assertThat(operations.acknowledgeAndAwait("foo", "bar", recordId)).isEqualTo(1) + } + + verify { + operations.acknowledge("foo", "bar", recordId) + } + } + + @Test // DATAREDIS-937 + fun acknowledgeRecord() { + + val operations = mockk>() + every { operations.acknowledge(any(), any>()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.acknowledgeAndAwait("foo", Record.of("bar"))).isEqualTo(1) + } + + verify { + operations.acknowledge("foo", Record.of("bar")) + } + } + + @Test // DATAREDIS-937 + fun add() { + + val operations = mockk>() + val record = MapRecord.create("foo", mapOf("a" to "b")) + val redordId = RecordId.of("0-0") + every { operations.add(record) } returns Mono.just(redordId) + + runBlocking { + assertThat(operations.addAndAwait(record)).isEqualTo(redordId) + } + + verify { + operations.add(record) + } + } + + @Test // DATAREDIS-937 + fun addRecord() { + + val operations = mockk>() + val record = Record.of("foo").withStreamKey("bar") + val recordId = RecordId.of("0-0") + every { operations.add(record) } returns Mono.just(recordId) + + runBlocking { + assertThat(operations.addAndAwait(record)).isEqualTo(recordId) + } + + verify { + operations.add(record) + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + val recordId = RecordId.of("0-0") + every { operations.delete("foo", recordId) } returns Mono.just(1) + + runBlocking { + assertThat(operations.deleteAndAwait("foo", recordId)).isEqualTo(1) + } + + verify { + operations.delete("foo", recordId) + } + } + + @Test // DATAREDIS-937 + fun deleteRecord() { + + val operations = mockk>() + val record = Record.of("foo").withStreamKey("bar") + every { operations.delete(record) } returns Mono.just(1) + + runBlocking { + assertThat(operations.deleteAndAwait(record)).isEqualTo(1) + } + + verify { + operations.delete(record) + } + } + + @Test // DATAREDIS-937 + fun deleteRecordIds() { + + val operations = mockk>() + every { operations.delete("foo", "0-0") } returns Mono.just(1) + + runBlocking { + assertThat(operations.deleteAndAwait("foo", "0-0")).isEqualTo(1) + } + + verify { + operations.delete("foo", "0-0") + } + } + + @Test // DATAREDIS-937 + fun createGroup() { + + val operations = mockk>() + every { operations.createGroup(any(), any()) } returns Mono.just("OK") + + runBlocking { + assertThat(operations.createGroupAndAwait("foo", "bar")).isEqualTo("OK") + } + + verify { + operations.createGroup("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun createGroupWithOffset() { + + val operations = mockk>() + every { operations.createGroup(any(), ReadOffset.lastConsumed(), any()) } returns Mono.just("OK") + + runBlocking { + assertThat(operations.createGroupAndAwait("foo", ReadOffset.lastConsumed(), "bar")).isEqualTo("OK") + } + + verify { + operations.createGroup("foo", ReadOffset.lastConsumed(), "bar") + } + } + + @Test // DATAREDIS-937 + fun deleteConsumer() { + + val operations = mockk>() + every { operations.deleteConsumer(any(), any()) } returns Mono.just("OK") + + runBlocking { + assertThat(operations.deleteConsumerAndAwait("foo", Consumer.from("bar", "baz"))).isEqualTo("OK") + } + + verify { + operations.deleteConsumer("foo", Consumer.from("bar", "baz")) + } + } + + @Test // DATAREDIS-937 + fun destroyGroup() { + + val operations = mockk>() + every { operations.destroyGroup(any(), any()) } returns Mono.just("OK") + + runBlocking { + assertThat(operations.destroyGroupAndAwait("foo", "bar")).isEqualTo("OK") + } + + verify { + operations.destroyGroup("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun trim() { + + val operations = mockk>() + every { operations.trim(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.trimAndAwait("foo", 1)).isEqualTo(1) + } + + verify { + operations.trim("foo", 1) + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..6be671334 --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveValueOperationsExtensionsUnitTests.kt @@ -0,0 +1,395 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.springframework.data.redis.connection.BitFieldSubCommands +import reactor.core.publisher.Mono +import java.time.Duration + +/** + * Unit tests for [ReactiveValueOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveValueOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun set() { + + val operations = mockk>() + every { operations.set(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.set("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun setWithDuration() { + + val operations = mockk>() + every { operations.set(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setAndAwait("foo", "bar", Duration.ofDays(1))).isTrue() + } + + verify { + operations.set("foo", "bar", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun setIfAbsent() { + + val operations = mockk>() + every { operations.setIfAbsent(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setIfAbsentAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.setIfAbsent("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun setIfAbsentWithDuration() { + + val operations = mockk>() + every { operations.setIfAbsent(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setIfAbsentAndAwait("foo", "bar", Duration.ofDays(1))).isTrue() + } + + verify { + operations.setIfAbsent("foo", "bar", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun setIfPresent() { + + val operations = mockk>() + every { operations.setIfPresent(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setIfPresentAndAwait("foo", "bar")).isTrue() + } + + verify { + operations.setIfPresent("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun setIfPresentWithDuration() { + + val operations = mockk>() + every { operations.setIfPresent(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setIfPresentAndAwait("foo", "bar", Duration.ofDays(1))).isTrue() + } + + verify { + operations.setIfPresent("foo", "bar", Duration.ofDays(1)) + } + } + + @Test // DATAREDIS-937 + fun multiSet() { + + val operations = mockk>() + every { operations.multiSet(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.multiSetAndAwait(mapOf("foo" to "bar"))).isTrue() + } + + verify { + operations.multiSet(mapOf("foo" to "bar")) + } + } + + @Test // DATAREDIS-937 + fun multiSetIfAbsent() { + + val operations = mockk>() + every { operations.multiSetIfAbsent(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.multiSetIfAbsentAndAwait(mapOf("foo" to "bar"))).isTrue() + } + + verify { + operations.multiSetIfAbsent(mapOf("foo" to "bar")) + } + } + + @Test // DATAREDIS-937 + fun get() { + + val operations = mockk>() + every { operations.get(any()) } returns Mono.just("bar") + + runBlocking { + assertThat(operations.getAndAwait("foo")).isEqualTo("bar") + } + + verify { + operations.get("foo") + } + } + + @Test // DATAREDIS-937 + fun getAndSet() { + + val operations = mockk>() + every { operations.getAndSet(any(), any()) } returns Mono.just("baz") + + runBlocking { + assertThat(operations.getAndSetAndAwait("foo", "bar")).isEqualTo("baz") + } + + verify { + operations.getAndSet("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun multiGet() { + + val operations = mockk>() + every { operations.multiGet(any()) } returns Mono.just(listOf("baz")) + + runBlocking { + assertThat(operations.multiGetAndAwait("foo", "bar")).isEqualTo(listOf("baz")) + } + + verify { + operations.multiGet(listOf("foo", "bar")) + } + } + + @Test // DATAREDIS-937 + fun increment() { + + val operations = mockk>() + every { operations.increment(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.incrementAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.increment("foo") + } + } + + @Test // DATAREDIS-937 + fun incrementWithDelta() { + + val operations = mockk>() + every { operations.increment(any(), 2) } returns Mono.just(1) + + runBlocking { + assertThat(operations.incrementAndAwait("foo", 2)).isEqualTo(1) + } + + verify { + operations.increment("foo", 2) + } + } + + @Test // DATAREDIS-937 + fun incrementWithDoubleDelta() { + + val operations = mockk>() + every { operations.increment(any(), 2.0) } returns Mono.just(1.0) + + runBlocking { + assertThat(operations.incrementAndAwait("foo", 2.0)).isEqualTo(1.0) + } + + verify { + operations.increment("foo", 2.0) + } + } + + @Test // DATAREDIS-937 + fun decrement() { + + val operations = mockk>() + every { operations.decrement(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.decrementAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.decrement("foo") + } + } + + @Test // DATAREDIS-937 + fun decrementWithDelta() { + + val operations = mockk>() + every { operations.decrement(any(), 2) } returns Mono.just(1) + + runBlocking { + assertThat(operations.decrementAndAwait("foo", 2)).isEqualTo(1) + } + + verify { + operations.decrement("foo", 2) + } + } + + @Test // DATAREDIS-937 + fun append() { + + val operations = mockk>() + every { operations.append(any(), any()) } returns Mono.just(2) + + runBlocking { + assertThat(operations.appendAndAwait("foo", "bar")).isEqualTo(2) + } + + verify { + operations.append("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun getSubstring() { + + val operations = mockk>() + every { operations.get(any(), any(), any()) } returns Mono.just("foo") + + runBlocking { + assertThat(operations.getAndAwait("foo", 1, 2)).isEqualTo("foo") + } + + verify { + operations.get("foo", 1, 2) + } + } + + @Test // DATAREDIS-937 + fun setSubstring() { + + val operations = mockk>() + every { operations.set(any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.setAndAwait("foo", "bar", 2)).isEqualTo(1) + } + + verify { + operations.set("foo", "bar", 2) + } + } + + @Test // DATAREDIS-937 + fun size() { + + val operations = mockk>() + every { operations.size(any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.sizeAndAwait("foo")).isEqualTo(1) + } + + verify { + operations.size("foo") + } + } + + @Test // DATAREDIS-937 + fun setBit() { + + val operations = mockk>() + every { operations.setBit(any(), any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.setBitAndAwait("foo", 1, true)).isTrue() + } + + verify { + operations.setBit("foo", 1, true) + } + } + + @Test // DATAREDIS-937 + fun getBit() { + + val operations = mockk>() + every { operations.getBit(any(), any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.getBitAndAwait("foo", 1)).isTrue() + } + + verify { + operations.getBit("foo", 1) + } + } + + @Test // DATAREDIS-937 + fun bitField() { + + val operations = mockk>() + val commands = BitFieldSubCommands.create(); + every { operations.bitField(any(), any()) } returns Mono.just(listOf(1L)) + + runBlocking { + assertThat(operations.bitFieldAndAwait("foo", commands)).isEqualTo(listOf(1L)) + } + + verify { + operations.bitField("foo", commands) + } + } + + @Test // DATAREDIS-937 + fun delete() { + + val operations = mockk>() + every { operations.delete(any()) } returns Mono.just(true) + + runBlocking { + assertThat(operations.deleteAndAwait("foo")).isTrue() + } + + verify { + operations.delete("foo") + } + } +} diff --git a/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt b/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt new file mode 100644 index 000000000..76b8f5dbb --- /dev/null +++ b/src/test/kotlin/org/springframework/data/redis/core/ReactiveZSetOperationsExtensionsUnitTests.kt @@ -0,0 +1,305 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.springframework.data.domain.Range +import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate +import org.springframework.data.redis.connection.RedisZSetCommands.Weights +import reactor.core.publisher.Mono + +/** + * Unit tests for [ReactiveZSetOperationsExtensions]. + * + * @author Mark Paluch + */ +class ReactiveZSetOperationsExtensionsUnitTests { + + @Test // DATAREDIS-937 + fun add() { + + val operations = mockk>() + every { operations.add(any(), any(), 1.0) } returns Mono.just(true) + + runBlocking { + assertThat(operations.addAndAwait("foo", "bar", 1.0)).isTrue() + } + + verify { + operations.add("foo", "bar", 1.0) + } + } + + @Test // DATAREDIS-937 + fun addAll() { + + val operations = mockk>() + every { operations.addAll(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.addAllAndAwait("foo", listOf(DefaultTypedTuple("v", 1.0)))).isEqualTo(1) + } + + verify { + operations.addAll("foo", listOf(DefaultTypedTuple("v", 1.0))) + } + } + + @Test // DATAREDIS-937 + fun remove() { + + val operations = mockk>() + every { operations.remove("foo", "bar") } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.remove("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun incrementScore() { + + val operations = mockk>() + every { operations.incrementScore(any(), any(), 1.0) } returns Mono.just(1.0) + + runBlocking { + assertThat(operations.incrementScoreAndAwait("foo", "bar", 1.0)).isEqualTo(1.0) + } + + verify { + operations.incrementScore("foo", "bar", 1.0) + } + } + + @Test // DATAREDIS-937 + fun rank() { + + val operations = mockk>() + every { operations.rank(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.rankAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.rank("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun reverseRank() { + + val operations = mockk>() + every { operations.reverseRank(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.reverseRankAndAwait("foo", "bar")).isEqualTo(1) + } + + verify { + operations.reverseRank("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun count() { + + val operations = mockk>() + every { operations.count(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.countAndAwait("foo", Range.unbounded())).isEqualTo(1) + } + + verify { + operations.count("foo", Range.unbounded()) + } + } + + @Test // DATAREDIS-937 + fun score() { + + val operations = mockk>() + every { operations.score(any(), any()) } returns Mono.just(1.0) + + runBlocking { + assertThat(operations.scoreAndAwait("foo", "bar")).isEqualTo(1.0) + } + + verify { + operations.score("foo", "bar") + } + } + + @Test // DATAREDIS-937 + fun removeRange() { + + val operations = mockk>() + every { operations.removeRange(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeRangeAndAwait("foo", Range.unbounded())).isEqualTo(1) + } + + verify { + operations.removeRange("foo", Range.unbounded()) + } + } + + @Test // DATAREDIS-937 + fun removeRangeByScore() { + + val operations = mockk>() + every { operations.removeRangeByScore(any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.removeRangeByScoreAndAwait("foo", Range.unbounded())).isEqualTo(1) + } + + verify { + operations.removeRangeByScore("foo", Range.unbounded()) + } + } + + @Test // DATAREDIS-937 + fun unionAndStore() { + + val operations = mockk>() + every { operations.unionAndStore("foo", "bar", "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait("foo", "bar", "baz")).isEqualTo(1) + } + + verify { + operations.unionAndStore("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun unionAndStoreListOfKeys() { + + val operations = mockk>() + every { operations.unionAndStore("foo", listOf("bar"), "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait("foo", listOf("bar"), "baz")).isEqualTo(1) + } + + verify { + operations.unionAndStore("foo", listOf("bar"), "baz") + } + } + + @Test // DATAREDIS-937 + fun unionAndStoreAggregate() { + + val operations = mockk>() + every { operations.unionAndStore(any(), any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait("foo", listOf("bar"), "baz", Aggregate.MAX)).isEqualTo(1) + } + + verify { + operations.unionAndStore("foo", listOf("bar"), "baz", Aggregate.MAX) + } + } + + @Test // DATAREDIS-937 + fun unionAndStoreWeights() { + + val operations = mockk>() + every { operations.unionAndStore(any(), any(), any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.unionAndStoreAndAwait("foo", listOf("bar"), "baz", Aggregate.MAX, Weights.fromSetCount(1))).isEqualTo(1) + } + + verify { + operations.unionAndStore("foo", listOf("bar"), "baz", Aggregate.MAX, Weights.fromSetCount(1)) + } + } + + @Test // DATAREDIS-937 + fun intersectAndStore() { + + val operations = mockk>() + every { operations.intersectAndStore("foo", "bar", "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait("foo", "bar", "baz")).isEqualTo(1) + } + + verify { + operations.intersectAndStore("foo", "bar", "baz") + } + } + + @Test // DATAREDIS-937 + fun intersectAndStoreListOfKeys() { + + val operations = mockk>() + every { operations.intersectAndStore("foo", listOf("bar"), "baz") } returns Mono.just(1) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait("foo", listOf("bar"), "baz")).isEqualTo(1) + } + + verify { + operations.intersectAndStore("foo", listOf("bar"), "baz") + } + } + + @Test // DATAREDIS-937 + fun intersectAndStoreAggregate() { + + val operations = mockk>() + every { operations.intersectAndStore(any(), any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait("foo", listOf("bar"), "baz", Aggregate.MAX)).isEqualTo(1) + } + + verify { + operations.intersectAndStore("foo", listOf("bar"), "baz", Aggregate.MAX) + } + } + + @Test // DATAREDIS-937 + fun intersectAndStoreWeights() { + + val operations = mockk>() + every { operations.intersectAndStore(any(), any(), any(), any(), any()) } returns Mono.just(1) + + runBlocking { + assertThat(operations.intersectAndStoreAndAwait("foo", listOf("bar"), "baz", Aggregate.MAX, Weights.fromSetCount(1))).isEqualTo(1) + } + + verify { + operations.intersectAndStore("foo", listOf("bar"), "baz", Aggregate.MAX, Weights.fromSetCount(1)) + } + } +}