use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class RemoteQueryDslPerfTest method populateCache.
@BeforeClass(alwaysRun = true)
protected void populateCache() {
for (int i = 0; i < WRITE_LOOPS; i++) {
// create the test objects
User user1 = new UserHS();
int id1 = i * 10 + 1;
user1.setId(id1);
user1.setName("John" + id1);
user1.setSurname("Doe" + id1);
user1.setAge(22);
user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
user1.setNotes("Lorem ipsum dolor sit amet");
User user2 = new UserHS();
int id2 = i * 10 + 2;
user2.setId(id2);
user2.setName("Spider" + id2);
user2.setSurname("Man" + id2);
user2.setAccountIds(Collections.singleton(3));
User user3 = new UserHS();
int id3 = i * 10 + 3;
user3.setId(id3);
user3.setName("Spider" + id3);
user3.setSurname("Woman" + id3);
cache.put("user_" + user1.getId(), user1);
cache.put("user_" + user2.getId(), user2);
cache.put("user_" + user3.getId(), user3);
}
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testEmbeddedQueryForEmbeddedEntryOnIndexedAndNonIndexedField.
public void testEmbeddedQueryForEmbeddedEntryOnIndexedAndNonIndexedField() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
// get user back from remote cache via query and check its attributes
QueryFactory qf = org.infinispan.query.Search.getQueryFactory(cache);
Query<User> query = qf.create("FROM " + UserHS.class.getName() + " WHERE notes LIKE '%567%' AND surname = 'test surname'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertNotNull(list.get(0));
assertEquals(UserHS.class, list.get(0).getClass());
assertEquals(1, list.get(0).getId());
assertEquals("1234567890", list.get(0).getNotes());
assertEquals("test surname", list.get(0).getSurname());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testEmbeddedQueryForEmbeddedEntryOnNonIndexedField.
public void testEmbeddedQueryForEmbeddedEntryOnNonIndexedField() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
// get user back from remote cache via query and check its attributes
QueryFactory qf = org.infinispan.query.Search.getQueryFactory(cache);
Query<User> query = qf.create("FROM " + UserHS.class.getName() + " WHERE notes LIKE '%567%'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertNotNull(list.get(0));
assertEquals(UserHS.class, list.get(0).getClass());
assertEquals(1, list.get(0).getId());
assertEquals("1234567890", list.get(0).getNotes());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testRemoteQueryForEmbeddedEntryOnIndexedAndNonIndexedField.
public void testRemoteQueryForEmbeddedEntryOnIndexedAndNonIndexedField() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
// get user back from remote cache via query and check its attributes
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE notes LIKE '%567%' AND surname = 'test surname'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertNotNull(list.get(0));
assertEquals(UserPB.class, list.get(0).getClass());
assertEquals(1, list.get(0).getId());
assertEquals("1234567890", list.get(0).getNotes());
assertEquals("test surname", list.get(0).getSurname());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class QueryCacheEmbeddedTest method testQueryCache.
public void testQueryCache() {
// populate our data cache
UserHS user = new UserHS();
user.setId(1);
user.setName("John");
cache.put("user_" + user.getId(), user);
// obtain the query cache component
QueryCache queryCache = ComponentRegistryUtils.getQueryCache(cache);
// force creation of the lazy internal cache and ensure it is empty
queryCache.get("someCacheName", "someQueryString", null, "typeDiscriminator", (queryString, acc) -> queryString);
// ensure internal cache is empty
queryCache.clear();
// obtain a reference to the internal query cache via reflection
Cache<?, ?> internalCache = TestingUtil.extractField(QueryCache.class, queryCache, "lazyCache");
String queryString = "from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS u where u.name = 'John'";
// everything is ready to go
// ensure the QueryCreator gets invoked
int[] invoked = { 0 };
IckleParsingResult<?> created = queryCache.get(cache.getName(), queryString, null, IckleParsingResult.class, (qs, acc) -> {
invoked[0]++;
return null;
});
assertEquals(1, invoked[0]);
assertNull(created);
// test that the query cache does not have it already
assertEquals(0, internalCache.size());
// create and execute a query
Query<?> query = Search.getQueryFactory(cache).create(queryString);
query.execute().list();
// ensure the query cache has it now: one FilterParsingResult and one SearchQueryParsingResult
assertEquals(2, internalCache.size());
Set<Class<?>> cacheValueClasses = internalCache.values().stream().map(Object::getClass).collect(Collectors.toSet());
Set<Class<?>> expectedCachedValueClasses = Sets.newLinkedHashSet(IckleParsingResult.class, SearchQueryParsingResult.class);
assertEquals(expectedCachedValueClasses, cacheValueClasses);
// ensure the QueryCreator does not get invoked now
IckleParsingResult<?> cached = queryCache.get(cache.getName(), queryString, null, IckleParsingResult.class, (qs, acc) -> {
throw new AssertionError("QueryCreator should not be invoked now");
});
assertNotNull(cached);
}
Aggregations