Search in sources :

Example 1 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetSerialiserTest method shouldSerialiserStringRBMBackedTimestampSet.

@Test
public void shouldSerialiserStringRBMBackedTimestampSet() throws SerialisationException {
    // Given
    final Serialiser<CustomMap, byte[]> customMapSerialiser = new CustomMapSerialiser();
    final RBMBackedTimestampSet timestampSet1 = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.MINUTE).timestamps(Lists.newArrayList(Instant.ofEpochSecond(10))).timestamps(Lists.newArrayList(Instant.ofEpochSecond(20))).build();
    final RBMBackedTimestampSet timestampSet2 = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.MINUTE).timestamps(Lists.newArrayList(Instant.ofEpochSecond(111))).timestamps(Lists.newArrayList(Instant.ofEpochSecond(222))).build();
    final CustomMap<String, RBMBackedTimestampSet> expected = new CustomMap<String, RBMBackedTimestampSet>(new StringSerialiser(), new RBMBackedTimestampSetSerialiser());
    expected.put("OneTimeStamp", timestampSet1);
    expected.put("TwoTimeStamp", timestampSet2);
    // When
    final CustomMap deserialise = customMapSerialiser.deserialise(customMapSerialiser.serialise(expected));
    // Then
    detailedEquals(expected, deserialise, String.class, RBMBackedTimestampSet.class, new StringSerialiser(), new RBMBackedTimestampSetSerialiser());
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) CustomMapSerialiser(uk.gov.gchq.gaffer.serialisation.CustomMapSerialiser) CustomMap(uk.gov.gchq.gaffer.types.CustomMap) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 2 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetSerialiserTest method testSerialiser.

@Test
public void testSerialiser() throws SerialisationException {
    // Given
    final RBMBackedTimestampSet rbmBackedTimestampSet = getExampleValue();
    // When
    final byte[] serialised = serialiser.serialise(rbmBackedTimestampSet);
    final RBMBackedTimestampSet deserialised = serialiser.deserialise(serialised);
    // Then
    assertEquals(rbmBackedTimestampSet, deserialised);
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 3 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetSerialiserTest method testSerialisationSizesQuotedInJavadoc.

@Test
public void testSerialisationSizesQuotedInJavadoc() throws SerialisationException {
    // Given
    final Random random = new Random(123456789L);
    final Instant instant = ZonedDateTime.of(2017, 1, 1, 1, 1, 1, 0, ZoneId.of("UTC")).toInstant();
    // Set of 100 minutes in a day and the time bucket is a minute
    final RBMBackedTimestampSet rbmBackedTimestampSet1 = new RBMBackedTimestampSet(TimeBucket.MINUTE);
    IntStream.range(0, 100).forEach(i -> rbmBackedTimestampSet1.add(instant.plusSeconds(random.nextInt(24 * 60) * 60)));
    // Set of every minute in a year and the time bucket is a minute
    final RBMBackedTimestampSet rbmBackedTimestampSet2 = new RBMBackedTimestampSet(TimeBucket.MINUTE);
    IntStream.range(0, 365 * 24 * 60).forEach(i -> rbmBackedTimestampSet2.add(instant.plusSeconds(i * 60)));
    // Set of every second in a year is set and the time bucket is a second
    final RBMBackedTimestampSet rbmBackedTimestampSet3 = new RBMBackedTimestampSet(TimeBucket.SECOND);
    IntStream.range(0, 365 * 24 * 60 * 60).forEach(i -> rbmBackedTimestampSet3.add(instant.plusSeconds(i)));
    // When
    final int lengthSet1 = serialiser.serialise(rbmBackedTimestampSet1).length;
    final int lengthSet2 = serialiser.serialise(rbmBackedTimestampSet2).length;
    final int lengthSet3 = serialiser.serialise(rbmBackedTimestampSet3).length;
    // Then
    assertTrue(200 < lengthSet1 && lengthSet1 < 220);
    assertTrue(72000 < lengthSet2 && lengthSet2 < 74000);
    assertTrue(3900000 < lengthSet3 && lengthSet3 < 4100000);
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Random(java.util.Random) Instant(java.time.Instant) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 4 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetAggregatorTest method testCantMergeIfDifferentTimeBucket.

@Test
public void testCantMergeIfDifferentTimeBucket() {
    try {
        final RBMBackedTimestampSet rbmBackedTimestampSet1 = new RBMBackedTimestampSet(TimeBucket.SECOND);
        final RBMBackedTimestampSet rbmBackedTimestampSet2 = new RBMBackedTimestampSet(TimeBucket.MINUTE);
        RBM_BACKED_TIMESTAMP_SET_AGGREGATOR._apply(rbmBackedTimestampSet1, rbmBackedTimestampSet2);
    } catch (final RuntimeException e) {
    // Expected
    }
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Test(org.junit.jupiter.api.Test)

Example 5 with RBMBackedTimestampSet

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

the class MaskTimestampSetByTimeRange method apply.

@Override
public RBMBackedTimestampSet apply(final RBMBackedTimestampSet rbmBackedTimestampSet) {
    RBMBackedTimestampSet cloned = rbmBackedTimestampSet.getShallowClone();
    cloned.applyTimeRangeMask(timeUnit.asMilliSeconds(startTime), timeUnit.asMilliSeconds(endTime));
    return cloned;
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)

Aggregations

RBMBackedTimestampSet (uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)19 Test (org.junit.jupiter.api.Test)11 ToBytesSerialisationTest (uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)4 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Instant (java.time.Instant)2 RoaringBitmap (org.roaringbitmap.RoaringBitmap)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)2 TimeBucket (uk.gov.gchq.gaffer.time.CommonTimeUtil.TimeBucket)2 CustomMap (uk.gov.gchq.gaffer.types.CustomMap)2 ReservoirLongsUnion (com.yahoo.sketches.sampling.ReservoirLongsUnion)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 BitmapJsonModules (uk.gov.gchq.gaffer.bitmap.serialisation.json.BitmapJsonModules)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 TimestampSetElementGenerator (uk.gov.gchq.gaffer.doc.properties.generator.TimestampSetElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1