DATAREDIS-874 - Polishing.

Reformat code. Add since tags. Extend tests.

Align Javadoc tonality across RedisAtomic… types.

Original pull request: #362.
This commit is contained in:
Mark Paluch
2018-10-16 12:01:29 +02:00
parent f2107ef81b
commit 148b1ae582
6 changed files with 440 additions and 138 deletions

View File

@@ -21,8 +21,8 @@ import java.util.Collection;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.DoubleUnaryOperator;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleUnaryOperator;
import org.assertj.core.data.Offset;
import org.junit.After;
@@ -233,92 +233,174 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test // DATAREDIS-874
public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
double expectedNewValue = 10.6;
doubleCounter.set(initialValue);
DoubleUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
double result = doubleCounter.updateAndGet(updateFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(doubleCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(doubleCounter.get()).isCloseTo(expectedNewValue, Offset.offset(0.001));
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void updateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
doubleCounter.set(initialValue);
DoubleUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isCloseTo(initialValue, Offset.offset(0.001));
return -1;
};
doubleCounter.updateAndGet(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
double expectedNewValue = 10.6;
doubleCounter.set(initialValue);
DoubleUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
double result = doubleCounter.getAndUpdate(updateFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(doubleCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(doubleCounter.get()).isCloseTo(expectedNewValue, Offset.offset(0.001));
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
doubleCounter.set(initialValue);
DoubleUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isCloseTo(initialValue, Offset.offset(0.001));
return -1;
};
doubleCounter.getAndUpdate(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
double expectedNewValue = 10.6;
doubleCounter.set(initialValue);
DoubleBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
double result = doubleCounter.accumulateAndGet(15.9, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(doubleCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(doubleCounter.get()).isCloseTo(expectedNewValue, Offset.offset(0.001));
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
doubleCounter.set(initialValue);
DoubleBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isCloseTo(initialValue, Offset.offset(0.001));
assertThat(y).isCloseTo(15, Offset.offset(0.001));
return -1;
};
doubleCounter.accumulateAndGet(15, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
double expectedNewValue = 10.6;
doubleCounter.set(initialValue);
DoubleBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
double result = doubleCounter.getAndAccumulate(15.9, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(doubleCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(doubleCounter.get()).isCloseTo(expectedNewValue, Offset.offset(0.001));
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
double initialValue = 5.3;
doubleCounter.set(initialValue);
DoubleBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isCloseTo(initialValue, Offset.offset(0.001));
assertThat(y).isCloseTo(15, Offset.offset(0.001));
return -1;
};
doubleCounter.getAndAccumulate(15, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
}

View File

@@ -240,92 +240,174 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@Test // DATAREDIS-874
public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
int expectedNewValue = 10;
intCounter.set(initialValue);
IntUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
int result = intCounter.updateAndGet(updateFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(intCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void updateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
intCounter.set(initialValue);
IntUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isEqualTo(initialValue);
return -1;
};
intCounter.updateAndGet(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
int expectedNewValue = 10;
intCounter.set(initialValue);
IntUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
int result = intCounter.getAndUpdate(updateFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(intCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
intCounter.set(initialValue);
IntUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isEqualTo(initialValue);
return -1;
};
intCounter.getAndUpdate(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
int expectedNewValue = 10;
intCounter.set(initialValue);
IntBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
int result = intCounter.accumulateAndGet(15, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(intCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
intCounter.set(initialValue);
IntBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isEqualTo(initialValue);
assertThat(y).isEqualTo(15);
return -1;
};
intCounter.accumulateAndGet(15, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
int initialValue = 5;
int expectedNewValue = 10;
intCounter.set(initialValue);
IntBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
int result = intCounter.getAndAccumulate(15, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(intCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
int initialValue = 5;
intCounter.set(initialValue);
IntBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isEqualTo(initialValue);
assertThat(y).isEqualTo(15);
return -1;
};
intCounter.getAndAccumulate(15, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
}

View File

@@ -222,92 +222,174 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
@Test // DATAREDIS-874
public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
long expectedNewValue = 10;
longCounter.set(initialValue);
LongUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
long result = longCounter.updateAndGet(updateFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(longCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void updateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
longCounter.set(initialValue);
LongUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isEqualTo(initialValue);
return -1;
};
longCounter.updateAndGet(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
long expectedNewValue = 10;
longCounter.set(initialValue);
LongUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
long result = longCounter.getAndUpdate(updateFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(longCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndUpdateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
longCounter.set(initialValue);
LongUnaryOperator updateFunction = input -> {
operatorHasBeenApplied.set(true);
assertThat(input).isEqualTo(initialValue);
return -1;
};
longCounter.getAndUpdate(updateFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
long expectedNewValue = 10;
longCounter.set(initialValue);
LongBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
long result = longCounter.accumulateAndGet(15L, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(expectedNewValue);
assertThat(longCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void accumulateAndGetUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
longCounter.set(initialValue);
LongBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isEqualTo(initialValue);
assertThat(y).isEqualTo(15);
return -1;
};
longCounter.accumulateAndGet(15L, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() {
// Arrange
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false);
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
long expectedNewValue = 10;
longCounter.set(initialValue);
LongBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
return expectedNewValue;
};
// Act
long result = longCounter.getAndAccumulate(15L, accumulatorFunction);
// Assert
assertThat(result).isEqualTo(initialValue);
assertThat(longCounter.get()).isEqualTo(expectedNewValue);
assertThat(operatorHasBeenApplied.get()).isTrue();
assertThat(operatorHasBeenApplied).isTrue();
}
@Test // DATAREDIS-874
public void getAndAccumulateUsesCorrectArguments() {
AtomicBoolean operatorHasBeenApplied = new AtomicBoolean();
long initialValue = 5;
longCounter.set(initialValue);
LongBinaryOperator accumulatorFunction = (x, y) -> {
operatorHasBeenApplied.set(true);
assertThat(x).isEqualTo(initialValue);
assertThat(y).isEqualTo(15);
return -1;
};
longCounter.getAndAccumulate(15L, accumulatorFunction);
assertThat(operatorHasBeenApplied).isTrue();
}
}