Search in sources :

Example 16 with User

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

the class UserUtils method createUser.

public static User createUser(String name, String surname) {
    User user = new User();
    user.setName(name);
    user.setSurname(surname);
    return user;
}
Also used : User(org.infinispan.protostream.sampledomain.User)

Example 17 with User

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

the class HotRodCacheContinuousQueries method testQueries.

@Test
public void testQueries() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser(1, 25));
    remoteCache.put(2, createUser(2, 25));
    remoteCache.put(3, createUser(3, 20));
    assertEquals(3, remoteCache.size());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'user1' AND age > 20");
    final BlockingQueue<Integer> joined = new LinkedBlockingQueue<>();
    final BlockingQueue<Integer> updated = new LinkedBlockingQueue<>();
    final BlockingQueue<Integer> left = new LinkedBlockingQueue<>();
    ContinuousQueryListener<Integer, User> listener = new ContinuousQueryListener<Integer, User>() {

        @Override
        public void resultJoining(Integer key, User value) {
            joined.add(key);
        }

        @Override
        public void resultUpdated(Integer key, User value) {
            updated.add(key);
        }

        @Override
        public void resultLeaving(Integer key) {
            left.add(key);
        }
    };
    ContinuousQuery<Integer, User> continuousQuery = Search.getContinuousQuery(remoteCache);
    continuousQuery.addContinuousQueryListener(query, listener);
    expectElementsInQueue(joined, 1);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 0);
    User user4 = createUser(4, 30);
    user4.setName("user1");
    remoteCache.put(4, user4);
    expectElementsInQueue(joined, 1);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 0);
    User user1 = remoteCache.get(1);
    user1.setAge(19);
    remoteCache.put(1, user1);
    expectElementsInQueue(joined, 0);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 1);
    user4 = remoteCache.get(4);
    user4.setAge(32);
    remoteCache.put(4, user4);
    expectElementsInQueue(joined, 0);
    expectElementsInQueue(updated, 1);
    expectElementsInQueue(left, 0);
    remoteCache.clear();
    expectElementsInQueue(joined, 0);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 1);
    continuousQuery.removeContinuousQueryListener(listener);
    user1.setAge(25);
    remoteCache.put(1, user1);
    expectElementsInQueue(joined, 0);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 0);
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) ContinuousQueryListener(org.infinispan.query.api.continuous.ContinuousQueryListener) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Test(org.junit.Test)

Example 18 with User

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

the class HotRodCacheContinuousQueries method createUser.

private User createUser(int id, int age) {
    User user = new User();
    user.setId(id);
    user.setName("user" + id);
    user.setAge(age);
    user.setSurname("Doesn't matter");
    user.setGender(User.Gender.MALE);
    return user;
}
Also used : User(org.infinispan.protostream.sampledomain.User)

Example 19 with User

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

the class HotRodCacheQueries method testIteratorWithQueryAndProjections.

@Test
public void testIteratorWithQueryAndProjections() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<Object[]> simpleQuery = qf.create("SELECT surname, name FROM sample_bank_account.User WHERE name = 'Tom'");
    List<Map.Entry<Object, Object>> entries = new ArrayList<>(1);
    try (CloseableIterator<Map.Entry<Object, Object>> iter = remoteCache.retrieveEntriesByQuery(simpleQuery, null, 3)) {
        while (iter.hasNext()) {
            entries.add(iter.next());
        }
    }
    assertEquals(1, entries.size());
    Object[] projections = (Object[]) entries.get(0).getValue();
    assertEquals("Cat", projections[0]);
    assertEquals("Tom", projections[1]);
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with User

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

the class HotRodCacheQueries method testUninverting.

/**
 * Sorting on a field that does not contain DocValues so Hibernate Search is forced to uninvert it.
 *
 * @see <a href="https://issues.jboss.org/browse/ISPN-5729">https://issues.jboss.org/browse/ISPN-5729</a>
 */
@Test
public void testUninverting() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'John' ORDER BY id ASC");
    assertEquals(0, query.execute().list().size());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) 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