Search in sources :

Example 1 with AccountPB

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;
}
Also used : AccountPB(org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB) Date(java.util.Date)

Example 2 with 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);
}
Also used : Marshaller(org.infinispan.commons.marshall.Marshaller) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Entry(java.util.Map.Entry) AccountPB(org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB) HashSet(java.util.HashSet)

Example 3 with AccountPB

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);
    });
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) QueryFactory(org.infinispan.query.dsl.QueryFactory) Entry(java.util.Map.Entry) AccountPB(org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB)

Example 4 with AccountPB

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;
}
Also used : AccountPB(org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB) Date(java.util.Date)

Example 5 with AccountPB

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());
    });
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) Metadata(org.infinispan.metadata.Metadata) AbstractKeyValueFilterConverter(org.infinispan.filter.AbstractKeyValueFilterConverter) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) AccountPB(org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache)

Aggregations

AccountPB (org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB)9 Date (java.util.Date)5 Account (org.infinispan.query.dsl.embedded.testdomain.Account)4 Entry (java.util.Map.Entry)3 QueryFactory (org.infinispan.query.dsl.QueryFactory)2 HashSet (java.util.HashSet)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 UserPB (org.infinispan.client.hotrod.query.testdomain.protobuf.UserPB)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)1 AbstractKeyValueFilterConverter (org.infinispan.filter.AbstractKeyValueFilterConverter)1 Metadata (org.infinispan.metadata.Metadata)1 Limits (org.infinispan.query.dsl.embedded.testdomain.Limits)1 AccountHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS)1