Search in sources :

Example 21 with User

use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.

the class HotRodCacheQueries method testProjections.

@Test
public void testProjections() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    // get user back from remote cache and check its attributes
    User fromCache = remoteCache.get(1);
    assertUser1(fromCache);
    // get user back from remote cache via query and check its attributes
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<Object[]> query = qf.create("SELECT name, surname FROM sample_bank_account.User WHERE name = 'Tom'");
    List<Object[]> list = query.execute().list();
    assertNotNull(list);
    assertEquals(1, list.size());
    assertEquals(Object[].class, list.get(0).getClass());
    assertEquals("Tom", list.get(0)[0]);
    assertEquals("Cat", list.get(0)[1]);
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) Test(org.junit.Test)

Example 22 with User

use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.

the class HotRodCacheQueries method testQueryViaRest.

@Test
public void testQueryViaRest() throws IOException {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    String query = "FROM sample_bank_account.User WHERE name='Adrian'";
    RestClient restClient = SERVER_TEST.newRestClient(new RestClientConfigurationBuilder());
    RestResponse response = sync(restClient.cache(SERVER_TEST.getMethodName()).query(query));
    Json results = Json.read(response.getBody());
    assertEquals(1, results.at("total_results").asInteger());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) User(org.infinispan.protostream.sampledomain.User) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.junit.Test)

Example 23 with User

use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.

the class HotRodCacheQueries method testManyInClauses.

@Test
public void testManyInClauses() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    // get user back from remote cache and check its attributes
    User fromCache = remoteCache.get(1);
    assertUser1(fromCache);
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Set<String> values = new HashSet<>();
    values.add("Tom");
    for (int i = 0; i < 1024; i++) {
        values.add("test" + i);
    }
    Query<User> query = qf.from(User.class).having("name").in(values).build();
    // this Ickle query translates to a BooleanQuery with 1025 clauses, 1 more than the max default (1024) so
    // executing it will fail unless the server jvm arg -Dinfinispan.query.lucene.max-boolean-clauses=1025 takes effect
    List<User> list = query.execute().list();
    assertNotNull(list);
    assertEquals(1, list.size());
    assertEquals(User.class, list.get(0).getClass());
    assertUser1(list.get(0));
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with User

use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.

the class HotRodCacheQueries method createUser2.

public static User createUser2() {
    User user = new User();
    user.setId(2);
    user.setName("Adrian");
    user.setSurname("Nistor");
    user.setGender(User.Gender.MALE);
    Address address = new Address();
    address.setStreet("Old Street");
    address.setPostCode("XYZ");
    user.setAddresses(Collections.singletonList(address));
    return user;
}
Also used : User(org.infinispan.protostream.sampledomain.User) Address(org.infinispan.protostream.sampledomain.Address)

Example 25 with User

use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.

the class HotRodCacheQueries method testWayTooManyInClauses.

@Test
public void testWayTooManyInClauses() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    if (indexed) {
        expectedException.expect(HotRodClientException.class);
        expectedException.expectMessage("org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1025");
    }
    Set<String> values = new HashSet<>();
    for (int i = 0; i < 1026; i++) {
        values.add("test" + i);
    }
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<User> query = qf.from(User.class).having("name").in(values).build();
    // this Ickle query translates to a BooleanQuery with 1026 clauses, 1 more than the configured
    // -Dinfinispan.query.lucene.max-boolean-clauses=1025, so executing the query is expected to fail
    query.execute();
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

User (org.infinispan.protostream.sampledomain.User)29 Test (org.junit.Test)15 QueryFactory (org.infinispan.query.dsl.QueryFactory)12 Exchange (org.apache.camel.Exchange)5 Address (org.infinispan.protostream.sampledomain.Address)5 UserUtils.hasUser (org.apache.camel.component.infinispan.util.UserUtils.hasUser)4 TestUser (org.infinispan.server.test.api.TestUser)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 RestCacheClient (org.infinispan.client.rest.RestCacheClient)2 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Processor (org.apache.camel.Processor)1 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 RestClient (org.infinispan.client.rest.RestClient)1