use of org.immutables.criteria.personmodel.PersonRepository in project immutables by immutables.
the class GeodeCqTest method pubsub.
@Test
public void pubsub() throws Exception {
PersonRepository repository = new PersonRepository(new GeodeBackend(GeodeSetup.of(x -> region)));
TestSubscriber<WatchEvent<Person>> events = Flowable.fromPublisher(repository.watcher(PersonCriteria.person).watch()).test();
final PersonGenerator generator = new PersonGenerator();
final int count = 4;
for (int i = 0; i < count; i++) {
repository.insert(generator.next().withId("id" + i));
}
check(region.keySet()).notEmpty();
// ensure (de)serialization is successful
check(region.query("true")).hasSize(count);
events.awaitCount(count);
events.assertNoErrors();
events.assertValueCount(count);
check(events.values().stream().map(e -> e.newValue().get().id()).collect(Collectors.toList())).hasContentInAnyOrder("id0", "id1", "id2", "id3");
}
use of org.immutables.criteria.personmodel.PersonRepository in project immutables by immutables.
the class GetAllOptimizationTest method withoutIdResolver.
/**
* {@link Region#getAll(Collection)} should not be called without
* known key metadata
*/
@Test
void withoutIdResolver() {
// custom extractor based on generic function
KeyExtractor.Factory extractor = KeyExtractor.generic(obj -> {
Person person = (Person) obj;
return person.id();
});
PersonRepository repository = createRepository(builder -> builder.keyExtractorFactory(extractor));
repository.find(person.id.is("id1")).fetch();
check(calls).isEmpty();
repository.find(person.id.in("id1", "id2")).fetch();
check(calls).isEmpty();
// negatives
repository.find(person.id.isNot("id1")).fetch();
check(calls.isEmpty());
repository.find(person.id.notIn("id1", "id2")).fetch();
check(calls.isEmpty());
}
use of org.immutables.criteria.personmodel.PersonRepository in project immutables by immutables.
the class GetAllOptimizationTest method optimization_getAll.
/**
* With ID resolver {@link Region#getAll(Collection)} should be called
*/
@SuppressWarnings("unchecked")
@Test
void optimization_getAll() {
PersonRepository repository = createRepository(builder -> builder);
repository.find(person.id.is("id1")).fetch();
// expect some calls to be intercepted
if (calls.isEmpty()) {
Assertions.fail("Region.getAll(...) was not called. Check that this optimization is enabled");
}
check(calls).hasSize(1);
check(calls.get(0).method.getName()).isIn("get", "getAll");
check((Iterable<Object>) calls.get(0).args[0]).hasAll("id1");
calls.clear();
repository.find(person.id.in("id1", "id2")).fetch();
check(calls).hasSize(1);
check(calls.get(0).method.getName()).is("getAll");
check((Iterable<Object>) calls.get(0).args[0]).hasAll("id1", "id2");
calls.clear();
// negatives should not use getAll
repository.find(person.id.isNot("id1")).fetch();
check(calls.isEmpty());
repository.find(person.id.notIn("id1", "id2")).fetch();
check(calls.isEmpty());
// any other composite expression should not trigger getAll
repository.find(person.id.is("id1").age.is(1)).fetch();
repository.find(person.age.is(1).id.in(Arrays.asList("id1", "id2"))).fetch();
check(calls.isEmpty());
}
use of org.immutables.criteria.personmodel.PersonRepository in project immutables by immutables.
the class GetAllOptimizationTest method createRepository.
/**
* Create repository using lambda for customization
*/
private PersonRepository createRepository(Function<GeodeSetup.Builder, GeodeSetup.Builder> fn) {
RegionResolver resolver = new LocalResolver(RegionResolver.defaultResolver(cache));
GeodeSetup.Builder setup = fn.apply(GeodeSetup.builder().regionResolver(resolver));
AutocreateRegion autocreate = new AutocreateRegion(cache);
Backend backend = WithSessionCallback.wrap(new GeodeBackend(setup.build()), autocreate);
return new PersonRepository(backend);
}
Aggregations