Search in sources :

Example 1 with User

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

the class HotRodCacheQueries method testAttributeQuery.

@Test
public void testAttributeQuery() {
    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<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
    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) Test(org.junit.Test)

Example 2 with User

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

the class HotRodCacheQueries method testEmbeddedAttributeQuery.

@Test
public void testEmbeddedAttributeQuery() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    // 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 u WHERE u.addresses.postCode = '1234'");
    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) Test(org.junit.Test)

Example 3 with User

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

the class HotRodCacheQueries method testIteratorWithQuery.

@Test
public void testIteratorWithQuery() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
    remoteCache.put(1, createUser1());
    remoteCache.put(2, createUser2());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<User> simpleQuery = qf.create("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());
    assertEquals("Cat", ((User) entries.get(0).getValue()).getSurname());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with User

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

the class HotRodListenerWithDslFilter method testEventFilter.

@Test
public void testEventFilter() {
    RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, true);
    User user1 = new User();
    user1.setId(1);
    user1.setName("John");
    user1.setSurname("Doe");
    user1.setGender(User.Gender.MALE);
    user1.setAge(22);
    user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
    user1.setNotes("Lorem ipsum dolor sit amet");
    Address address1 = new Address();
    address1.setStreet("Main Street");
    address1.setPostCode("X1234");
    user1.setAddresses(Collections.singletonList(address1));
    User user2 = new User();
    user2.setId(2);
    user2.setName("Spider");
    user2.setSurname("Man");
    user2.setGender(User.Gender.MALE);
    user2.setAge(32);
    user2.setAccountIds(Collections.singleton(3));
    Address address2 = new Address();
    address2.setStreet("Old Street");
    address2.setPostCode("Y12");
    Address address3 = new Address();
    address3.setStreet("Bond Street");
    address3.setPostCode("ZZ");
    user2.setAddresses(Arrays.asList(address2, address3));
    User user3 = new User();
    user3.setId(3);
    user3.setName("Spider");
    user3.setSurname("Woman");
    user3.setGender(User.Gender.FEMALE);
    user3.setAge(31);
    user3.setAccountIds(Collections.emptySet());
    remoteCache.put(user1.getId(), user1);
    remoteCache.put(user2.getId(), user2);
    remoteCache.put(user3.getId(), user3);
    assertEquals(3, remoteCache.size());
    SerializationContext serCtx = MarshallerUtil.getSerializationContext(remoteCache.getRemoteCacheManager());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<User> query = qf.<User>create("SELECT age FROM sample_bank_account.User WHERE age <= :ageParam").setParameter("ageParam", 32);
    ClientEntryListener listener = new ClientEntryListener(serCtx);
    ClientEvents.addClientQueryListener(remoteCache, listener, query);
    expectElementsInQueue(listener.createEvents, 3);
    user3.setAge(40);
    remoteCache.put(user1.getId(), user1);
    remoteCache.put(user2.getId(), user2);
    remoteCache.put(user3.getId(), user3);
    assertEquals(3, remoteCache.size());
    expectElementsInQueue(listener.modifyEvents, 2);
    remoteCache.removeClientListener(listener);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) Address(org.infinispan.protostream.sampledomain.Address) Test(org.junit.Test)

Example 5 with User

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

the class AbstractAuthorization method testNonBulkReadUsersCannotQuery.

@Test
public void testNonBulkReadUsersCannotQuery() {
    org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
    // Hot Rod
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER)) {
        RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
        QueryFactory qf = Search.getQueryFactory(userCache);
        Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
        Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> query.execute().list());
    }
    // REST
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER, TestUser.MONITOR)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(FORBIDDEN, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
        assertStatus(OK, userCache.searchStats());
        assertStatus(OK, userCache.indexStats());
        assertStatus(OK, userCache.queryStats());
    }
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) TestUser(org.infinispan.server.test.api.TestUser) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) 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