Search in sources :

Example 1 with ReservoirLongsUnion

use of com.yahoo.sketches.sampling.ReservoirLongsUnion in project Gaffer by gchq.

the class ReservoirLongUnionAggregatorTest method testCloneOfBusySketch.

@Test
public void testCloneOfBusySketch() {
    final ReservoirLongsUnionAggregator unionAggregator = new ReservoirLongsUnionAggregator();
    unionAggregator.init();
    for (int i = 0; i < 100; i++) {
        final ReservoirLongsUnion union = ReservoirLongsUnion.getInstance(20);
        for (int j = 0; j < 100; j++) {
            union.update(RANDOM.nextLong());
        }
        unionAggregator._aggregate(union);
    }
    final ReservoirLongsUnionAggregator clone = unionAggregator.statelessClone();
    assertNotSame(unionAggregator, clone);
    clone._aggregate(union1);
    assertEquals(union1.getResult().getN(), ((ReservoirLongsUnion) clone.state()[0]).getResult().getN());
}
Also used : ReservoirLongsUnion(com.yahoo.sketches.sampling.ReservoirLongsUnion) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 2 with ReservoirLongsUnion

use of com.yahoo.sketches.sampling.ReservoirLongsUnion in project Gaffer by gchq.

the class ReservoirLongsUnionSerialiserTest method testSerialiseAndDeserialise.

@Test
public void testSerialiseAndDeserialise() {
    final ReservoirLongsUnion union = ReservoirLongsUnion.getInstance(20);
    union.update(1L);
    union.update(2L);
    union.update(3L);
    testSerialiser(union);
    final ReservoirLongsUnion emptyUnion = ReservoirLongsUnion.getInstance(20);
    testSerialiser(emptyUnion);
}
Also used : ReservoirLongsUnion(com.yahoo.sketches.sampling.ReservoirLongsUnion) Test(org.junit.Test)

Example 3 with ReservoirLongsUnion

use of com.yahoo.sketches.sampling.ReservoirLongsUnion in project Gaffer by gchq.

the class ReservoirLongsUnionSerialiserTest method testSerialiser.

private void testSerialiser(final ReservoirLongsUnion union) {
    final ReservoirLongsSketch result = union.getResult();
    final boolean resultIsNull = result == null;
    long[] sample = new long[] {};
    if (!resultIsNull) {
        sample = union.getResult().getSamples();
    }
    final byte[] unionSerialised;
    try {
        unionSerialised = SERIALISER.serialise(union);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final ReservoirLongsUnion unionDeserialised;
    try {
        unionDeserialised = SERIALISER.deserialise(unionSerialised);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final ReservoirLongsSketch deserialisedResult = unionDeserialised.getResult();
    if (deserialisedResult == null) {
        assertTrue(resultIsNull);
    } else {
        assertArrayEquals(sample, unionDeserialised.getResult().getSamples());
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ReservoirLongsUnion(com.yahoo.sketches.sampling.ReservoirLongsUnion) ReservoirLongsSketch(com.yahoo.sketches.sampling.ReservoirLongsSketch)

Example 4 with ReservoirLongsUnion

use of com.yahoo.sketches.sampling.ReservoirLongsUnion in project Gaffer by gchq.

the class ReservoirLongUnionAggregatorTest method testEquals.

@Test
public void testEquals() {
    final ReservoirLongsUnion sketch1 = ReservoirLongsUnion.getInstance(20);
    sketch1.update(1L);
    final ReservoirLongsUnionAggregator sketchAggregator1 = new ReservoirLongsUnionAggregator();
    sketchAggregator1.aggregate(new ReservoirLongsUnion[] { sketch1 });
    final ReservoirLongsUnion sketch2 = ReservoirLongsUnion.getInstance(20);
    sketch2.update(1L);
    final ReservoirLongsUnionAggregator sketchAggregator2 = new ReservoirLongsUnionAggregator();
    sketchAggregator2.aggregate(new ReservoirLongsUnion[] { sketch2 });
    assertEquals(sketchAggregator1, sketchAggregator2);
    sketch2.update(2L);
    sketchAggregator2.aggregate(new ReservoirLongsUnion[] { sketch2 });
    assertNotEquals(sketchAggregator1, sketchAggregator2);
}
Also used : ReservoirLongsUnion(com.yahoo.sketches.sampling.ReservoirLongsUnion) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Aggregations

ReservoirLongsUnion (com.yahoo.sketches.sampling.ReservoirLongsUnion)4 Test (org.junit.Test)3 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)2 ReservoirLongsSketch (com.yahoo.sketches.sampling.ReservoirLongsSketch)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1