jdeppe-pivotal commented on a change in pull request #6877:
URL: https://github.com/apache/geode/pull/6877#discussion_r716631240
##########
File path:
geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/key/AbstractRenameIntegrationTest.java
##########
@@ -188,38 +244,39 @@ public void
shouldNotDeadlock_concurrentRenames_givenStripeContention()
}
@Test
- public void shouldThrowError_givenKeyDeletedDuringRename()
- throws ExecutionException, InterruptedException {
- CyclicBarrier startCyclicBarrier = new CyclicBarrier(2);
- ExecutorService pool = Executors.newFixedThreadPool(2);
-
- for (int i = 0; i < 100; i++) {
- jedis.set("{user1}oldKey", "foo");
+ public void shouldError_givenKeyDeletedDuringRename() {
+ int iterations = 2000;
- Runnable renameOldKeyToNewKey = () -> {
- cyclicBarrierAwait(startCyclicBarrier);
+ final AtomicReference<RuntimeException> renameException = new
AtomicReference<>(null);
- jedis.rename("{user1}oldKey", "{user1}newKey");
- };
+ jedis.set("{user1}oldKey", "foo");
- Runnable deleteOldKey = () -> {
- cyclicBarrierAwait(startCyclicBarrier);
- jedis.del("{user1}oldKey");
- };
-
- Future<?> future1 = pool.submit(renameOldKeyToNewKey);
- Future<?> future2 = pool.submit(deleteOldKey);
-
- try {
- future1.get();
- assertThat(jedis.get("{user1}newKey")).isEqualTo("foo");
- } catch (Exception e) {
- assertThat(e).hasMessageContaining("no such key");
- }
- future2.get();
-
- assertThat(jedis.get("{user1}oldKey")).isNull();
+ try {
+ new ConcurrentLoopingThreads(iterations,
+ i -> {
+ try {
+ jedis.rename("{user1}oldKey", "{user1}newKey");
+ } catch (RuntimeException e) {
+ renameException.set(e);
+ }
+ },
+ i -> jedis.del("{user1}oldKey"))
+ .runWithAction(() -> {
+ RuntimeException e = renameException.get();
+ if (e != null) {
+ throw e;
+ }
+ assertThat(jedis.get("{user1}newKey")).isEqualTo("foo");
+ assertThat(jedis.exists("{user1}oldKey")).isFalse();
+ jedis.set("{user1}oldKey", "foo");
+ });
+ } catch (RuntimeException e) {
+ assertThat(e).hasMessageContaining(ERROR_NO_SUCH_KEY);
Review comment:
I'm not sure that catching these exceptions and re-throwing from the
`runWithAction` is necessary. This sample never runs the 'action':
```
new ConcurrentLoopingThreads(1,
i -> {throw new RuntimeException("BANG!");}
).runWithAction(() -> System.out.println("running action"));
```
Regardless, this change also causes the loop to bail out after only 1 or 2
iterations instead of the full 2000.
I do think that the original code should include a
`jedis.del("{user1}newKey")` so as to get to a consistent state between loop
iterations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]