use of org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB in project infinispan by infinispan.
the class TwoCachesSharedIndexTest method getAccountPB.
private AccountPB getAccountPB() {
AccountPB accountPB = new AccountPB();
accountPB.setId(1);
accountPB.setDescription("account1");
accountPB.setCreationDate(new Date());
return accountPB;
}
use of org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB in project infinispan by infinispan.
the class ProtobufRemoteIteratorTest method testFilteredIteration.
public void testFilteredIteration() {
servers.forEach(s -> s.addKeyValueFilterConverterFactory("filterName", new ToStringFilterConverterFactory()));
RemoteCache<Integer, AccountPB> cache = clients.get(0).getCache();
populateCache(CACHE_SIZE, this::newAccountPB, cache);
Set<Integer> segments = rangeAsSet(1, 30);
Set<Entry<Object, Object>> results = new HashSet<>();
cache.retrieveEntries("filterName", segments, CACHE_SIZE).forEachRemaining(results::add);
Set<Object> values = extractValues(results);
assertForAll(values, s -> s instanceof String);
Marshaller marshaller = clients.iterator().next().getMarshaller();
LocalizedCacheTopology cacheTopology = advancedCache(0).getDistributionManager().getCacheTopology();
assertKeysInSegment(results, segments, marshaller, cacheTopology::getSegment);
}
use of org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB in project infinispan by infinispan.
the class ProtobufRemoteIteratorIndexingTest method testFilteredIterationWithQuery.
public void testFilteredIterationWithQuery() {
RemoteCache<Integer, AccountPB> remoteCache = clients.get(0).getCache();
populateCache(CACHE_SIZE, this::newAccountPB, remoteCache);
QueryFactory queryFactory = Search.getQueryFactory(remoteCache);
int lowerId = 5;
int higherId = 8;
Query<Account> simpleQuery = queryFactory.<Account>create("FROM sample_bank_account.Account WHERE id BETWEEN :lowerId AND :higherId").setParameter("lowerId", lowerId).setParameter("higherId", higherId);
Set<Entry<Object, Object>> entries = extractEntries(remoteCache.retrieveEntriesByQuery(simpleQuery, null, 10));
Set<Integer> keys = extractKeys(entries);
assertEquals(4, keys.size());
assertForAll(keys, key -> key >= lowerId && key <= higherId);
assertForAll(entries, e -> e.getValue() instanceof AccountPB);
Query<Object[]> projectionsQuery = queryFactory.<Object[]>create("SELECT id, description FROM sample_bank_account.Account WHERE id BETWEEN :lowerId AND :higherId").setParameter("lowerId", lowerId).setParameter("higherId", higherId);
Set<Entry<Integer, Object[]>> entriesWithProjection = extractEntries(remoteCache.retrieveEntriesByQuery(projectionsQuery, null, 10));
assertEquals(4, entriesWithProjection.size());
assertForAll(entriesWithProjection, entry -> {
Integer id = entry.getKey();
Object[] projection = entry.getValue();
return projection[0].equals(id) && projection[1].equals("description for " + id);
});
}
use of org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method createAccountPB.
private AccountPB createAccountPB(int id) {
AccountPB account = new AccountPB();
account.setId(id);
account.setDescription("test description");
account.setCreationDate(new Date(42));
return account;
}
use of org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testIterationForRemote.
public void testIterationForRemote() {
IntStream.range(0, 10).forEach(id -> remoteCache.put(id, createAccountPB(id)));
// Remote unfiltered iteration
CloseableIterator<Map.Entry<Object, Object>> remoteUnfilteredIterator = remoteCache.retrieveEntries(null, null, 10);
remoteUnfilteredIterator.forEachRemaining(e -> {
Integer key = (Integer) e.getKey();
AccountPB value = (AccountPB) e.getValue();
assertTrue(key < 10);
assertEquals((int) key, value.getId());
});
// Remote filtered iteration
KeyValueFilterConverterFactory<Integer, Account, String> filterConverterFactory = () -> new AbstractKeyValueFilterConverter<Integer, Account, String>() {
@Override
public String filterAndConvert(Integer key, Account value, Metadata metadata) {
if (key % 2 == 0) {
return value.toString();
}
return null;
}
};
hotRodServer.addKeyValueFilterConverterFactory("filterConverterFactory", filterConverterFactory);
CloseableIterator<Map.Entry<Object, Object>> remoteFilteredIterator = remoteCache.retrieveEntries("filterConverterFactory", null, 10);
remoteFilteredIterator.forEachRemaining(e -> {
Integer key = (Integer) e.getKey();
String value = (String) e.getValue();
assertTrue(key < 10);
assertEquals(createAccountHS(key).toString(), value);
});
// Embedded iteration
Cache<Integer, AccountHS> ourCache = (Cache<Integer, AccountHS>) embeddedCache;
Iterator<Map.Entry<Integer, AccountHS>> localUnfilteredIterator = ourCache.entrySet().stream().iterator();
localUnfilteredIterator.forEachRemaining(e -> {
Integer key = e.getKey();
AccountHS value = e.getValue();
assertTrue(key < 10);
assertEquals((int) key, value.getId());
});
}
Aggregations