Search in sources :

Example 1 with AccountHS

use of org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS in project infinispan by infinispan.

the class EmbeddedAccountMarshaller method readFrom.

@Override
public AccountHS readFrom(ProtoStreamReader reader) throws IOException {
    int id = reader.readInt("id");
    String description = reader.readString("description");
    long creationDate = reader.readLong("creationDate");
    Limits limits = reader.readObject("limits", LimitsHS.class);
    Limits hardLimits = reader.readObject("hardLimits", LimitsHS.class);
    List<byte[]> blurb = reader.readCollection("blurb", new ArrayList<>(), byte[].class);
    Account.Currency[] currencies = reader.readArray("currencies", Account.Currency.class);
    AccountHS account = new AccountHS();
    account.setId(id);
    account.setDescription(description);
    account.setCreationDate(new Date(creationDate));
    account.setLimits(limits);
    account.setHardLimits(hardLimits);
    account.setBlurb(blurb);
    account.setCurrencies(currencies);
    return account;
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) Limits(org.infinispan.query.dsl.embedded.testdomain.Limits) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) Date(java.util.Date)

Example 2 with AccountHS

use of org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS in project infinispan by infinispan.

the class EmbeddedRemoteInteropQueryTest method testRemoteQueryForEmbeddedEntry.

public void testRemoteQueryForEmbeddedEntry() {
    AccountHS account = new AccountHS();
    account.setId(1);
    account.setDescription("test description");
    account.setCreationDate(new Date(42));
    cache.put(1, account);
    // get account back from remote cache via query and check its attributes
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<Account> query = qf.create("FROM sample_bank_account.Account WHERE description LIKE '%test%'");
    List<Account> list = query.execute().list();
    assertNotNull(list);
    assertEquals(1, list.size());
    assertAccount(list.get(0), AccountPB.class);
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) QueryFactory(org.infinispan.query.dsl.QueryFactory) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) Date(java.util.Date)

Example 3 with AccountHS

use of org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS in project infinispan by infinispan.

the class EmbeddedRemoteInteropQueryTest method testPutAndGetForEmbeddedEntry.

public void testPutAndGetForEmbeddedEntry() {
    AccountHS account = new AccountHS();
    account.setId(1);
    account.setDescription("test description");
    account.setCreationDate(new Date(42));
    cache.put(1, account);
    // try to get the object through the remote cache interface and check it's the same object we put
    assertEquals(1, remoteCache.keySet().size());
    Map.Entry<Integer, Account> entry = remoteCache.entrySet().iterator().next();
    assertAccount(entry.getValue(), AccountPB.class);
    // get the object through the embedded cache interface and check it's the same object we put
    Account fromEmbeddedCache = (Account) embeddedCache.get(1);
    assertAccount(fromEmbeddedCache, AccountHS.class);
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) Map(java.util.Map) Date(java.util.Date)

Example 4 with AccountHS

use of org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS in project infinispan by infinispan.

the class EmbeddedRemoteInteropQueryTest method testEqSentenceEmbedded.

public void testEqSentenceEmbedded() {
    AccountHS account = new AccountHS();
    account.setId(1);
    account.setDescription("John Doe's first bank account");
    account.setCreationDate(new Date(42));
    cache.put(1, account);
    QueryFactory qf = org.infinispan.query.Search.getQueryFactory(cache);
    Query<Account> q = qf.create("FROM " + AccountHS.class.getName() + " WHERE description = \"John Doe's first bank account\"");
    List<Account> list = q.execute().list();
    assertEquals(1, list.size());
    assertEquals(1, list.get(0).getId());
}
Also used : Account(org.infinispan.query.dsl.embedded.testdomain.Account) QueryFactory(org.infinispan.query.dsl.QueryFactory) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) Date(java.util.Date)

Example 5 with AccountHS

use of org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS in project infinispan by infinispan.

the class BaseMultiServerRemoteIteratorTest method testFilterBySegment.

@Test
public void testFilterBySegment() {
    RemoteCache<Integer, AccountHS> cache = clients.get(0).getCache();
    populateCache(CACHE_SIZE, this::newAccount, cache);
    CacheTopologyInfo cacheTopologyInfo = cache.getCacheTopologyInfo();
    // Request all segments from one node
    Set<Integer> filterBySegments = cacheTopologyInfo.getSegmentsPerServer().values().iterator().next();
    Set<Entry<Object, Object>> entries = new HashSet<>();
    try (CloseableIterator<Entry<Object, Object>> iterator = cache.retrieveEntries(null, filterBySegments, 10)) {
        while (iterator.hasNext()) {
            entries.add(iterator.next());
        }
    }
    Marshaller marshaller = clients.get(0).getMarshaller();
    KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache(0), KeyPartitioner.class);
    assertKeysInSegment(entries, filterBySegments, marshaller, keyPartitioner::getSegment);
}
Also used : Entry(java.util.Map.Entry) Marshaller(org.infinispan.commons.marshall.Marshaller) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) CacheTopologyInfo(org.infinispan.client.hotrod.CacheTopologyInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) MultiHotRodServersTest(org.infinispan.client.hotrod.test.MultiHotRodServersTest)

Aggregations

AccountHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS)11 Date (java.util.Date)8 Account (org.infinispan.query.dsl.embedded.testdomain.Account)7 QueryFactory (org.infinispan.query.dsl.QueryFactory)4 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Cache (org.infinispan.Cache)1 CacheTopologyInfo (org.infinispan.client.hotrod.CacheTopologyInfo)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 AccountPB (org.infinispan.client.hotrod.query.testdomain.protobuf.AccountPB)1 MultiHotRodServersTest (org.infinispan.client.hotrod.test.MultiHotRodServersTest)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)1 AbstractKeyValueFilterConverter (org.infinispan.filter.AbstractKeyValueFilterConverter)1 Metadata (org.infinispan.metadata.Metadata)1 TheEntity (org.infinispan.query.dsl.embedded.impl.model.TheEntity)1 Address (org.infinispan.query.dsl.embedded.testdomain.Address)1 Author (org.infinispan.query.dsl.embedded.testdomain.Author)1 Book (org.infinispan.query.dsl.embedded.testdomain.Book)1