Search in sources :

Example 11 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetSerialiserTest method getExampleValue.

private RBMBackedTimestampSet getExampleValue() {
    final RBMBackedTimestampSet rbmBackedTimestampSet = new RBMBackedTimestampSet(TimeBucket.SECOND);
    rbmBackedTimestampSet.add(Instant.ofEpochMilli(1000L));
    rbmBackedTimestampSet.add(Instant.ofEpochMilli(1000000L));
    return rbmBackedTimestampSet;
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet)

Example 12 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetSerialiserTest method shouldJSONSerialiseFloatRDM.

@Test
public void shouldJSONSerialiseFloatRDM() throws IOException {
    // given
    System.setProperty(JSONSerialiser.JSON_SERIALISER_MODULES, BitmapJsonModules.class.getCanonicalName());
    final RBMBackedTimestampSet timestampSet1 = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.MINUTE).timestamps(Lists.newArrayList(Instant.ofEpochSecond(11))).build();
    final RBMBackedTimestampSet timestampSet2 = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.HOUR).timestamps(Lists.newArrayList(Instant.ofEpochSecond(222222))).build();
    final CustomMap<Float, RBMBackedTimestampSet> expectedMap = new CustomMap<>(new RawFloatSerialiser(), new RBMBackedTimestampSetSerialiser());
    expectedMap.put(123.3f, timestampSet1);
    expectedMap.put(345.6f, timestampSet2);
    final String expectedJson = jsonFromFile("custom-map04.json");
    // when
    final byte[] serialise = JSONSerialiser.serialise(expectedMap, true);
    final CustomMap jsonMap = JSONSerialiser.deserialise(expectedJson, CustomMap.class);
    final CustomMap deserialiseMap = JSONSerialiser.deserialise(serialise, CustomMap.class);
    // then
    assertEquals(jsonMap, deserialiseMap, "The expected map from Json doesn't match");
    assertEquals(expectedMap, deserialiseMap, "The expected map doesn't match");
}
Also used : BitmapJsonModules(uk.gov.gchq.gaffer.bitmap.serialisation.json.BitmapJsonModules) RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) CustomMap(uk.gov.gchq.gaffer.types.CustomMap) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 13 with RBMBackedTimestampSet

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

the class MaskTimestampSetByTimeRangeTest method shouldFilterInclusively.

@Test
public void shouldFilterInclusively() {
    // Given
    final RBMBackedTimestampSet timestampSet = createTimestampSet();
    // When
    maskTimestampSetByTimeRange.setStartTime(instant.plus(Duration.ofDays(100)).toEpochMilli());
    maskTimestampSetByTimeRange.setEndTime(instant.plus(Duration.ofDays(200)).toEpochMilli());
    final RBMBackedTimestampSet actualTimestampSet = maskTimestampSetByTimeRange.apply(timestampSet);
    // Then
    RBMBackedTimestampSet expectedTimestampSet = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.MINUTE).timestamps(Sets.newHashSet(instant.plus(Duration.ofDays(100L)), instant.plus(Duration.ofDays(200L)))).build();
    assertEquals(expectedTimestampSet, actualTimestampSet);
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 14 with RBMBackedTimestampSet

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

the class MaskTimestampSetByTimeRangeTest method shouldNotMutateOriginalValue.

@Test
public void shouldNotMutateOriginalValue() {
    final RBMBackedTimestampSet timestampSet = createTimestampSet();
    maskTimestampSetByTimeRange.setStartTime(instant.plus(Duration.ofDays(100)).toEpochMilli());
    maskTimestampSetByTimeRange.setEndTime(instant.plus(Duration.ofDays(250)).toEpochMilli());
    final RBMBackedTimestampSet actualTimestampSet = maskTimestampSetByTimeRange.apply(timestampSet);
    assertNotEquals(actualTimestampSet, timestampSet);
    assertEquals(4, timestampSet.getTimestamps().size());
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 15 with RBMBackedTimestampSet

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

the class RBMBackedTimestampSetInRangeTest method shouldThrowExceptionIfTimestampSetIsEmpty.

@Test
public void shouldThrowExceptionIfTimestampSetIsEmpty() {
    // Given
    predicate.startTime(-5L).endTime(5L);
    // When / Then
    RBMBackedTimestampSet emptySet = new RBMBackedTimestampSet.Builder().timeBucket(TimeBucket.SECOND).build();
    assertThatIllegalArgumentException().isThrownBy(() -> predicate.test(emptySet)).withMessage("TimestampSet must contain at least one value");
}
Also used : RBMBackedTimestampSet(uk.gov.gchq.gaffer.time.RBMBackedTimestampSet) Test(org.junit.jupiter.api.Test)

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