Skip to content

Commit

Permalink
Remove obsolete HotrodCache remove(key, value) override.
Browse files Browse the repository at this point in the history
RemoteCache#removeAsync(key, value) doesn't throw an UnsupportedOperationException
anymore with Infinispan 11 (ISPN-11674).
Override had been added for #1977.

Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed Jul 14, 2021
1 parent 8d1e6be commit 5505c3c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public Future<V> get(final K key) {
Objects.requireNonNull(key);

return withCache(cache -> cache.getAsync(key));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

import org.infinispan.client.hotrod.RemoteCache;
Expand Down Expand Up @@ -164,26 +163,6 @@ protected boolean isStarted() {
return cacheManager.isStarted() && getCache() != null;
}

// Method overridden because RemoteCache#removeAsync(key, value) throws an UnsupportedOperationException.
@Override
public Future<Boolean> remove(final K key, final V value) {
Objects.requireNonNull(key);
Objects.requireNonNull(value);

return withCache(cache -> {
final RemoteCache<K, V> remoteCache = (RemoteCache<K, V>) cache;
return remoteCache.getWithMetadataAsync(key).thenCompose(metadataValue -> {
if (metadataValue != null && value.equals(metadataValue.getValue())) {
// If removeWithVersionAsync() returns false here (meaning that the value was updated in between),
// the updated value shall prevail and no new removal attempt with a new getWithMetadataAsync() invocation will be done.
return remoteCache.removeWithVersionAsync(key, metadataValue.getVersion());
} else {
return CompletableFuture.completedFuture(Boolean.FALSE);
}
});
});
}

@Override
protected <T> void postCacheAccess(final AsyncResult<T> cacheOperationResult) {
lastConnectionCheckResult = new ConnectionCheckResult(cacheOperationResult.cause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ abstract class AbstractBasicCacheTest {
*/
protected abstract org.infinispan.commons.api.BasicCache<Object, Object> givenAConnectedInfinispanCache();

protected void mockRemoveWithValue(
final org.infinispan.commons.api.BasicCache<Object, Object> infinispanCache,
final String key,
final Object value,
final boolean removeOperationResult) {

when(infinispanCache.removeAsync(eq(key), eq(value)))
.thenReturn(CompletableFuture.completedFuture(removeOperationResult));
}

protected void verifyRemoveWithValue(
final org.infinispan.commons.api.BasicCache<Object, Object> infinispanCache,
final String key,
final Object value,
final boolean expectedRemoveOperationResult) {

verify(infinispanCache).removeAsync(key, value);
}

/**
* Sets up the fixture.
*/
Expand Down Expand Up @@ -208,12 +189,13 @@ void testPutFails(final VertxTestContext ctx) {
@Test
void testRemoveWithValueSucceeds(final VertxTestContext ctx) {
final org.infinispan.commons.api.BasicCache<Object, Object> grid = givenAConnectedInfinispanCache();
mockRemoveWithValue(grid, "key", "value", true);
when(grid.removeAsync(eq("key"), eq((Object) "value")))
.thenReturn(CompletableFuture.completedFuture(true));
getCache().start()
.compose(ok -> getCache().remove("key", "value"))
.onComplete(ctx.succeeding(v -> {
ctx.verify(() -> {
verifyRemoveWithValue(grid, "key", "value", true);
verify(grid).removeAsync("key", "value");
assertThat(v).isTrue();
});
ctx.completeNow();
Expand All @@ -229,12 +211,13 @@ void testRemoveWithValueSucceeds(final VertxTestContext ctx) {
@Test
void testRemoveWithValueFails(final VertxTestContext ctx) {
final org.infinispan.commons.api.BasicCache<Object, Object> grid = givenAConnectedInfinispanCache();
mockRemoveWithValue(grid, "key", "value", false);
when(grid.removeAsync(eq("key"), eq((Object) "value")))
.thenReturn(CompletableFuture.completedFuture(false));
getCache().start()
.compose(ok -> getCache().remove("key", "value"))
.onComplete(ctx.succeeding(v -> {
ctx.verify(() -> {
verifyRemoveWithValue(grid, "key", "value", false);
verify(grid).removeAsync("key", "value");
assertThat(v).isFalse();
});
ctx.completeNow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

package org.eclipse.hono.deviceconnection.infinispan.client;

import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -25,11 +23,8 @@
import java.util.concurrent.TimeUnit;

import org.infinispan.client.hotrod.Flag;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheContainer;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.impl.MetadataValueImpl;
import org.infinispan.commons.api.BasicCache;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -77,40 +72,6 @@ protected org.eclipse.hono.deviceconnection.infinispan.client.BasicCache<String,
return cache;
}

@Override
protected void mockRemoveWithValue(
final BasicCache<Object, Object> infinispanCache,
final String key,
final Object value,
final boolean removeOperationResult) {

final org.infinispan.client.hotrod.RemoteCache<Object, Object> remoteCache = (RemoteCache<Object, Object>) infinispanCache;
if (removeOperationResult) {
final long version = 1;
when(remoteCache.getWithMetadataAsync(eq(key)))
.thenReturn(CompletableFuture.completedFuture(new MetadataValueImpl<>(-1, -1, -1, -1,
version, value)));
when(remoteCache.removeWithVersionAsync(eq(key), eq(version)))
.thenReturn(CompletableFuture.completedFuture(true));
} else {
when(remoteCache.getWithMetadataAsync(eq(key))).thenReturn(CompletableFuture.completedFuture(null));
}
}

@Override
protected void verifyRemoveWithValue(
final BasicCache<Object, Object> infinispanCache,
final String key,
final Object value,
final boolean expectedRemoveOperationResult) {

final org.infinispan.client.hotrod.RemoteCache<Object, Object> remoteCache = (RemoteCache<Object, Object>) infinispanCache;
verify(remoteCache).getWithMetadataAsync(key);
if (expectedRemoveOperationResult) {
verify(remoteCache).removeWithVersionAsync(eq(key), anyLong());
}
}

/**
* Verifies that the <em>checkForCacheAvailability</em> check uses a cached connection
* check result value if invoked shortly after a previous invocation.
Expand Down

0 comments on commit 5505c3c

Please sign in to comment.