use of org.infinispan.commons.util.IteratorMapper in project infinispan by infinispan.
the class HotRodUpgradeSynchronizerTest method doWhenSourceIterationReaches.
private void doWhenSourceIterationReaches(String key, TestCluster cluster, String cacheName, IterationCallBack callback) {
cluster.getEmbeddedCaches(cacheName).forEach(c -> {
PersistenceManager pm = extractComponent(c, PersistenceManager.class);
RemoteStore remoteStore = pm.getStores(RemoteStore.class).iterator().next();
RemoteCacheImpl remoteCache = TestingUtil.extractField(remoteStore, "remoteCache");
RemoteCacheImpl spy = spy(remoteCache);
doAnswer(invocation -> {
Object[] params = invocation.getArguments();
CloseableIterator<Map.Entry<Object, Object>> iterator = remoteCache.retrieveEntriesWithMetadata((Set<Integer>) params[0], (int) params[1]);
Marshaller marshaller = new GenericJBossMarshaller();
return new IteratorMapper<>(iterator, entry -> {
try {
if (key.equals(marshaller.objectFromByteBuffer((byte[]) entry.getKey()))) {
callback.iterationReached(key);
}
} catch (IOException | ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
return entry;
});
}).when(spy).retrieveEntriesWithMetadata(anySet(), anyInt());
TestingUtil.replaceField(spy, "remoteCache", remoteStore, RemoteStore.class);
});
}
Aggregations