Search in sources :

Example 1 with UserHS

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);
    }
}
Also used : User(org.infinispan.query.dsl.embedded.testdomain.User) UserHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with UserHS

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());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.query.dsl.embedded.testdomain.User) UserHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS)

Example 3 with UserHS

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());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.query.dsl.embedded.testdomain.User) UserHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS)

Example 4 with UserHS

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());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.query.dsl.embedded.testdomain.User) UserHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS)

Example 5 with UserHS

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);
}
Also used : QueryCache(org.infinispan.query.core.impl.QueryCache) UserHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS)

Aggregations

UserHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS)10 User (org.infinispan.query.dsl.embedded.testdomain.User)9 QueryFactory (org.infinispan.query.dsl.QueryFactory)6 Address (org.infinispan.query.dsl.embedded.testdomain.Address)2 BeforeClass (org.testng.annotations.BeforeClass)2 Instant (java.time.Instant)1 QueryCache (org.infinispan.query.core.impl.QueryCache)1 TheEntity (org.infinispan.query.dsl.embedded.impl.model.TheEntity)1 Account (org.infinispan.query.dsl.embedded.testdomain.Account)1 Author (org.infinispan.query.dsl.embedded.testdomain.Author)1 Book (org.infinispan.query.dsl.embedded.testdomain.Book)1 NotIndexed (org.infinispan.query.dsl.embedded.testdomain.NotIndexed)1 Transaction (org.infinispan.query.dsl.embedded.testdomain.Transaction)1 AccountHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS)1 AddressHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.AddressHS)1 TransactionHS (org.infinispan.query.dsl.embedded.testdomain.hsearch.TransactionHS)1