Search in sources :

Example 26 with User

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

the class HotRodCacheQueries method createUser1.

public static User createUser1() {
    User user = new User();
    user.setId(1);
    user.setName("Tom");
    user.setSurname("Cat");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(Collections.singleton(12));
    Address address = new Address();
    address.setStreet("Dark Alley");
    address.setPostCode("1234");
    user.setAddresses(Collections.singletonList(address));
    return user;
}
Also used : User(org.infinispan.protostream.sampledomain.User) Address(org.infinispan.protostream.sampledomain.Address)

Example 27 with User

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

the class AbstractAuthorization method testBulkReadUsersCanQuery.

@Test
public void testBulkReadUsersCanQuery() {
    org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
        RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
        User fromCache = userCache.get(1);
        HotRodCacheQueries.assertUser1(fromCache);
        QueryFactory qf = Search.getQueryFactory(userCache);
        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());
        HotRodCacheQueries.assertUser1(list.get(0));
    }
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(OK, 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)

Example 28 with User

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

the class UserMarshaller method readFrom.

@Override
public User readFrom(ProtoStreamReader reader) throws IOException {
    int id = reader.readInt("id");
    Set<Integer> accountIds = reader.readCollection("accountIds", new HashSet<>(), Integer.class);
    String name = reader.readString("name");
    String surname = reader.readString("surname");
    String salutation = reader.readString("salutation");
    List<Address> addresses = reader.readCollection("addresses", new ArrayList<>(), Address.class);
    Integer age = reader.readInt("age");
    User.Gender gender = reader.readEnum("gender", User.Gender.class);
    String notes = reader.readString("notes");
    Instant creationDate = reader.readInstant("creationDate");
    Instant passwordExpirationDate = reader.readInstant("passwordExpirationDate");
    User user = new User();
    user.setId(id);
    user.setAccountIds(accountIds);
    user.setName(name);
    user.setSurname(surname);
    user.setSalutation(salutation);
    user.setAge(age);
    user.setGender(gender);
    user.setAddresses(addresses);
    user.setNotes(notes);
    user.setCreationDate(creationDate);
    user.setPasswordExpirationDate(passwordExpirationDate);
    return user;
}
Also used : User(org.infinispan.protostream.sampledomain.User) Address(org.infinispan.protostream.sampledomain.Address) Instant(java.time.Instant)

Example 29 with User

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

the class InfinispanRemoteQueryConsumerIT method continuousQuery.

// *****************************
// 
// *****************************
@Test
public void continuousQuery() throws Exception {
    MockEndpoint continuousQueryBuilderNoMatch = getMockEndpoint("mock:continuousQueryNoMatch");
    continuousQueryBuilderNoMatch.expectedMessageCount(0);
    MockEndpoint continuousQueryBuilderAll = getMockEndpoint("mock:continuousQueryAll");
    continuousQueryBuilderAll.expectedMessageCount(CQ_USERS.length * 2);
    MockEndpoint continuousQuery = getMockEndpoint("mock:continuousQuery");
    continuousQuery.expectedMessageCount(4);
    for (int i = 0; i < 4; i++) {
        continuousQuery.message(i).header(InfinispanConstants.KEY).isEqualTo(createKey(CQ_USERS[i % 2]));
        continuousQuery.message(i).header(InfinispanConstants.CACHE_NAME).isEqualTo(getCache().getName());
        if (i >= 2) {
            continuousQuery.message(i).header(InfinispanConstants.EVENT_TYPE).isEqualTo(InfinispanConstants.CACHE_ENTRY_LEAVING);
            continuousQuery.message(i).header(InfinispanConstants.EVENT_DATA).isNull();
        } else {
            continuousQuery.message(i).header(InfinispanConstants.EVENT_TYPE).isEqualTo(InfinispanConstants.CACHE_ENTRY_JOINING);
            continuousQuery.message(i).header(InfinispanConstants.EVENT_DATA).isNotNull();
            continuousQuery.message(i).header(InfinispanConstants.EVENT_DATA).isInstanceOf(User.class);
        }
    }
    for (final User user : CQ_USERS) {
        getCache().put(createKey(user), user);
    }
    assertEquals(CQ_USERS.length, getCache().size());
    for (final User user : CQ_USERS) {
        getCache().remove(createKey(user));
    }
    assertTrue(getCache().isEmpty());
    continuousQuery.assertIsSatisfied();
    continuousQueryBuilderNoMatch.assertIsSatisfied();
    continuousQueryBuilderAll.assertIsSatisfied();
}
Also used : User(org.infinispan.protostream.sampledomain.User) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest)

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