Search in sources :

Example 1 with IteratorMapper

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);
    });
}
Also used : GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) IOException(java.io.IOException) RemoteStore(org.infinispan.persistence.remote.RemoteStore) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) IteratorMapper(org.infinispan.commons.util.IteratorMapper) RemoteCacheImpl(org.infinispan.client.hotrod.impl.RemoteCacheImpl)

Aggregations

IOException (java.io.IOException)1 RemoteCacheImpl (org.infinispan.client.hotrod.impl.RemoteCacheImpl)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 IteratorMapper (org.infinispan.commons.util.IteratorMapper)1 GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)1 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)1 RemoteStore (org.infinispan.persistence.remote.RemoteStore)1