Search in sources :

Example 51 with BigInteger

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);
}
Also used : Random(java.util.Random) BigInteger(java.math.BigInteger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with BigInteger

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);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BigInteger(java.math.BigInteger) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 53 with BigInteger

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);
}
Also used : Random(java.util.Random) BigInteger(java.math.BigInteger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 54 with BigInteger

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);
}
Also used : Random(java.util.Random) BigInteger(java.math.BigInteger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with BigInteger

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);
}
Also used : Random(java.util.Random) BigInteger(java.math.BigInteger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

BigInteger (java.math.BigInteger)3500 BigDecimal (java.math.BigDecimal)635 Test (org.junit.Test)337 IOException (java.io.IOException)113 ArrayList (java.util.ArrayList)105 MessageDigest (java.security.MessageDigest)101 RoundingMode (java.math.RoundingMode)88 Date (java.util.Date)80 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)75 MathContext (java.math.MathContext)71 Random (java.util.Random)65 Test (org.junit.jupiter.api.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 KeyFactory (java.security.KeyFactory)46 HashMap (java.util.HashMap)45 List (java.util.List)44 SecureRandom (java.security.SecureRandom)42 X509Certificate (java.security.cert.X509Certificate)42 EllipticCurve (java.security.spec.EllipticCurve)40