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]);
}
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());
}
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));
}
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;
}
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();
}
Aggregations