use of java.math.BigInteger in project hazelcast by hazelcast.
the class MapSumAggregationTest method testBigIntegerSum.
@Test
public void testBigIntegerSum() throws Exception {
BigInteger[] values = buildPlainValues(new ValueProvider<BigInteger>() {
@Override
public BigInteger provideRandom(Random random) {
return BigInteger.valueOf(10000L + random(1000, 2000));
}
}, BigInteger.class);
BigInteger expectation = BigInteger.ZERO;
for (int i = 0; i < values.length; i++) {
expectation = expectation.add(values[i]);
}
Aggregation<String, BigInteger, BigInteger> aggregation = Aggregations.bigIntegerSum();
BigInteger result = testSum(values, aggregation);
assertEquals(expectation, result);
}
use of java.math.BigInteger in project hazelcast by hazelcast.
the class MapReduceTest method testNullFromObjectCombiner.
@Test(timeout = TEST_TIMEOUT)
public void testNullFromObjectCombiner() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
try {
IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
for (int i = 0; i < 100; i++) {
m1.put(i, i);
}
JobTracker jobTracker = h1.getJobTracker("default");
Job<Integer, Integer> job = jobTracker.newJob(integerKvSource(m1));
JobCompletableFuture<Map<String, BigInteger>> future = job.chunkSize(10).mapper(new GroupingTestMapper()).combiner(new ObjectCombinerFactory()).reducer(new ObjectReducerFactory()).submit();
int[] expectedResults = new int[4];
for (int i = 0; i < 100; i++) {
int index = i % 4;
expectedResults[index] += i;
}
Map<String, BigInteger> map = future.get();
for (int i = 0; i < 4; i++) {
assertEquals(BigInteger.valueOf(expectedResults[i]), map.get(String.valueOf(i)));
}
} finally {
tripTerminate(h1, h2, h3);
}
}
use of java.math.BigInteger in project hazelcast by hazelcast.
the class MapAvgAggregationTest method testBigIntegerAvg.
@Test
public void testBigIntegerAvg() throws Exception {
BigInteger[] values = buildPlainValues(new ValueProvider<BigInteger>() {
@Override
public BigInteger provideRandom(Random random) {
return BigInteger.valueOf(10000L + random(1000, 2000));
}
}, BigInteger.class);
BigInteger expectation = BigInteger.ZERO;
for (int i = 0; i < values.length; i++) {
expectation = expectation.add(values[i]);
}
expectation = expectation.divide(BigInteger.valueOf(values.length));
Aggregation<String, BigInteger, BigInteger> aggregation = Aggregations.bigIntegerAvg();
BigInteger result = testAvg(values, aggregation);
assertEquals(expectation, result);
}
use of java.math.BigInteger in project hazelcast by hazelcast.
the class MapAvgAggregationTest method testBigIntegerAvgWithExtractor.
@Test
public void testBigIntegerAvgWithExtractor() throws Exception {
Value<BigInteger>[] values = buildValues(new ValueProvider<BigInteger>() {
@Override
public BigInteger provideRandom(Random random) {
return BigInteger.valueOf(10000L + random(1000, 2000));
}
});
BigInteger expectation = BigInteger.ZERO;
for (int i = 0; i < values.length; i++) {
expectation = expectation.add(values[i].value);
}
expectation = expectation.divide(BigInteger.valueOf(values.length));
Aggregation<String, BigInteger, BigInteger> aggregation = Aggregations.bigIntegerAvg();
BigInteger result = testAvgWithExtractor(values, aggregation);
assertEquals(expectation, result);
}
use of java.math.BigInteger in project hazelcast by hazelcast.
the class MapMaxAggregationTest method testBigIntegerMax.
@Test
public void testBigIntegerMax() throws Exception {
BigInteger[] values = buildPlainValues(new ValueProvider<BigInteger>() {
@Override
public BigInteger provideRandom(Random random) {
return BigInteger.valueOf(10000L + random(1000, 2000));
}
}, BigInteger.class);
BigInteger expectation = BigInteger.ZERO;
for (int i = 0; i < values.length; i++) {
BigInteger value = values[i];
expectation = i == 0 ? value : expectation.max(value);
}
Aggregation<String, BigInteger, BigInteger> aggregation = Aggregations.bigIntegerMax();
BigInteger result = testMax(values, aggregation);
assertEquals(expectation, result);
}
Aggregations