BAEL-1466 Updated the Integration Tests.
This commit is contained in:
parent
b6816bdcdd
commit
eafbe5d88a
@ -0,0 +1,39 @@
|
|||||||
|
package com.baeldung.geode.functions;
|
||||||
|
|
||||||
|
import com.baeldung.geode.Customer;
|
||||||
|
import org.apache.geode.cache.Region;
|
||||||
|
import org.apache.geode.cache.execute.Function;
|
||||||
|
import org.apache.geode.cache.execute.FunctionContext;
|
||||||
|
import org.apache.geode.cache.execute.RegionFunctionContext;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CustomerWithMaxAge implements Function<Customer> {
|
||||||
|
|
||||||
|
public static final String ID = CustomerWithMaxAge.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6023734758827953742L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(FunctionContext<Customer> context) {
|
||||||
|
RegionFunctionContext regionContext = (RegionFunctionContext) context;
|
||||||
|
Region<Integer, Customer> region = regionContext.getDataSet();
|
||||||
|
|
||||||
|
Comparator<Customer> ageComparator = Comparator.comparing(Customer::getAge);
|
||||||
|
|
||||||
|
Optional<Customer> customer = region.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(Map.Entry::getValue)
|
||||||
|
.max(ageComparator);
|
||||||
|
|
||||||
|
customer.ifPresent(c -> context.getResultSender()
|
||||||
|
.lastResult(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.baeldung.geode;
|
package com.baeldung.geode;
|
||||||
|
|
||||||
|
import com.baeldung.geode.functions.CustomerWithMaxAge;
|
||||||
import com.baeldung.geode.functions.PrimeNumber;
|
import com.baeldung.geode.functions.PrimeNumber;
|
||||||
import org.apache.geode.cache.Region;
|
import org.apache.geode.cache.Region;
|
||||||
import org.apache.geode.cache.client.ClientCache;
|
import org.apache.geode.cache.client.ClientCache;
|
||||||
@ -138,6 +139,19 @@ public class GeodeSamplesIntegrationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenExecuteFindEldestCustomerFunction_thenReturnTheEldestCustomer() {
|
||||||
|
Execution execution = FunctionService.onRegion(this.queryRegion);
|
||||||
|
|
||||||
|
ResultCollector<Customer, Customer> result = execution.execute(CustomerWithMaxAge.ID);
|
||||||
|
List<Customer> resultList = (List<Customer>) result.getResult();
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(1, resultList.size());
|
||||||
|
|
||||||
|
Customer customer = resultList.get(0);
|
||||||
|
assertEquals(Integer.valueOf(46), customer.getAge());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenExecutePrimeNumberFunction_thenReturnOnlyPrimeNumbers() {
|
public void whenExecutePrimeNumberFunction_thenReturnOnlyPrimeNumbers() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user