DATAREDIS-784 - Polishing.
Rename incrementBy and decrementBy to increment respective decrement. Use INCR and DECR for increment() and decrement() instead of INCRBY 1/INCRYBY -1. Rearrange method order to align with method order in ReactiveValueOperations. Tweak Javadoc, add since tags. Introduce increment() and decrement(…) (as of INCR/DECR) to ValueOperations and BoundValueOperations and use ValueOperations.increment()/decrement() from RedisAtomicInteger. ValueOperations used INCRBY and DECRBY to increment and now we use the native command if methods without delta are invoked. Original pull request: #322.
This commit is contained in:
@@ -384,7 +384,7 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
|
||||
StepVerifier.create(valueOperations.size(key)).expectNext(0L).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
public void increment() {
|
||||
|
||||
@@ -400,11 +400,11 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, 2L)).expectNext(2L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, 2L)).expectNext(2L).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, -3L)).expectNext(-1L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, -3L)).expectNext(-1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, 1L)).expectNext(0L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, 1L)).expectNext(0L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
@@ -412,11 +412,11 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, 0.1)).expectNext(0.1).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, 0.1)).expectNext(0.1).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, -0.3)).expectNext(-0.2).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, -0.3)).expectNext(-0.2).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.incrementBy(key, 0.2)).expectNext(0.0).verifyComplete();
|
||||
StepVerifier.create(valueOperations.increment(key, 0.2)).expectNext(0.0).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
@@ -434,10 +434,10 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
|
||||
StepVerifier.create(valueOperations.decrementBy(key, 2L)).expectNext(-2L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.decrement(key, 2L)).expectNext(-2L).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.decrementBy(key, -3L)).expectNext(1L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.decrement(key, -3L)).expectNext(1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(valueOperations.decrementBy(key, 1L)).expectNext(0L).verifyComplete();
|
||||
StepVerifier.create(valueOperations.decrement(key, 1L)).expectNext(0L).verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
* @author David Liu
|
||||
* @author Thomas Darimont
|
||||
* @author Jiahe Cai
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DefaultValueOperationsTests<K, V> {
|
||||
@@ -94,8 +95,18 @@ public class DefaultValueOperationsTests<K, V> {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
public void testIncrement() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
assumeTrue(v1 instanceof Long);
|
||||
valueOps.set(key, v1);
|
||||
assertEquals(Long.valueOf((Long) v1 + 1), valueOps.increment(key));
|
||||
assertEquals(Long.valueOf((Long) v1 + 1), valueOps.get(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementLong() throws Exception {
|
||||
public void testIncrementLong() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
assumeTrue(v1 instanceof Long);
|
||||
@@ -122,6 +133,26 @@ public class DefaultValueOperationsTests<K, V> {
|
||||
assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4 - 10d)), valueOps.get(key));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
public void testDecrement() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
assumeTrue(v1 instanceof Long);
|
||||
valueOps.set(key, v1);
|
||||
assertEquals(Long.valueOf((Long) v1 - 1), valueOps.decrement(key));
|
||||
assertEquals(Long.valueOf((Long) v1 - 1), valueOps.get(key));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-784
|
||||
public void testDecrementByLong() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
assumeTrue(v1 instanceof Long);
|
||||
valueOps.set(key, v1);
|
||||
assertEquals(Long.valueOf((Long) v1 - 5), valueOps.decrement(key, 5));
|
||||
assertEquals(Long.valueOf((Long) v1 - 5), valueOps.get(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiSetIfAbsent() {
|
||||
Map<K, V> keysAndValues = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user