Search in sources :

Example 11 with BoundedTimestampSet

use of uk.gov.gchq.gaffer.time.BoundedTimestampSet in project Gaffer by gchq.

the class BoundedTimestampSetSerialiserTest method testSerialiserWhenSampling.

@Test
public void testSerialiserWhenSampling() throws SerialisationException {
    // Given
    final Set<Instant> instants = new HashSet<>();
    IntStream.range(0, 1000).forEach(i -> instants.add(Instant.ofEpochMilli(i * 1000L)));
    final BoundedTimestampSet boundedTimestampSet = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    instants.forEach(boundedTimestampSet::add);
    // When
    final byte[] serialised = serialiser.serialise(boundedTimestampSet);
    final BoundedTimestampSet deserialised = serialiser.deserialise(serialised);
    // Then
    assertEquals(boundedTimestampSet.getState(), deserialised.getState());
    assertEquals(boundedTimestampSet.getTimeBucket(), deserialised.getTimeBucket());
    assertEquals(boundedTimestampSet.getMaxSize(), deserialised.getMaxSize());
    assertEquals(boundedTimestampSet.getNumberOfTimestamps(), deserialised.getNumberOfTimestamps());
    assertEquals(boundedTimestampSet.getTimestamps(), deserialised.getTimestamps());
}
Also used : Instant(java.time.Instant) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)

Aggregations

BoundedTimestampSet (uk.gov.gchq.gaffer.time.BoundedTimestampSet)11 Test (org.junit.jupiter.api.Test)8 Instant (java.time.Instant)4 HashSet (java.util.HashSet)4 ToBytesSerialisationTest (uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)2 ReservoirLongsUnion (com.yahoo.sketches.sampling.ReservoirLongsUnion)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RoaringBitmap (org.roaringbitmap.RoaringBitmap)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 TimeBucket (uk.gov.gchq.gaffer.time.CommonTimeUtil.TimeBucket)1 RBMBackedTimestampSet (uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)1 TimestampSet (uk.gov.gchq.gaffer.time.TimestampSet)1