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());
}
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);
}
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());
}
}
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);
}
Aggregations