Search in sources :

Example 1 with BoundedTimestampSet

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

the class BoundedTimestampSetElementGenerator method _apply.

@Override
public Iterable<Element> _apply(final String line) {
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        final TimestampSet timestampSet = new BoundedTimestampSet(CommonTimeUtil.TimeBucket.MINUTE, 25);
        timestampSet.add(START_OF_2017.plusSeconds(RANDOM.nextInt(SECONDS_IN_YEAR)));
        final Edge edge = new Edge.Builder().group("red").source("A").dest("B").property("boundedTimestampSet", timestampSet).build();
        elements.add(edge);
    }
    for (int i = 0; i < 1000; i++) {
        final TimestampSet timestampSet = new BoundedTimestampSet(CommonTimeUtil.TimeBucket.MINUTE, 25);
        timestampSet.add(START_OF_2017.plusSeconds(RANDOM.nextInt(SECONDS_IN_YEAR)));
        final Edge edge = new Edge.Builder().group("red").source("A").dest("C").property("boundedTimestampSet", timestampSet).build();
        elements.add(edge);
    }
    return elements;
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) TimestampSet(uk.gov.gchq.gaffer.time.TimestampSet) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 2 with BoundedTimestampSet

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

the class BoundedTimestampSetAggregatorTest method testAggregateWhenBothInSampleState.

@Test
public void testAggregateWhenBothInSampleState() {
    // Given
    final BoundedTimestampSet boundedTimestampSet1 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants1 = new HashSet<>();
    IntStream.range(0, 100).forEach(i -> instants1.add(Instant.ofEpochMilli(i * 1000L)));
    instants1.forEach(boundedTimestampSet1::add);
    final BoundedTimestampSet boundedTimestampSet2 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants2 = new HashSet<>();
    IntStream.range(50, 150).forEach(i -> instants2.add(Instant.ofEpochMilli(i * 1000L)));
    instants2.forEach(boundedTimestampSet2::add);
    final Set<Instant> allInstants = new HashSet<>(instants1);
    allInstants.addAll(instants2);
    // When
    final BoundedTimestampSet aggregated = BOUNDED_TIMESTAMP_SET_AGGREGATOR._apply(boundedTimestampSet1, boundedTimestampSet2);
    // Then
    assertEquals(10, aggregated.getNumberOfTimestamps());
    assertEquals(BoundedTimestampSet.State.SAMPLE, aggregated.getState());
    assertTrue(allInstants.containsAll(aggregated.getTimestamps()));
}
Also used : Instant(java.time.Instant) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with BoundedTimestampSet

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

the class BoundedTimestampSetAggregatorTest method testAggregateWhenAIsInNotFullStateAndBIsInSampleState.

@Test
public void testAggregateWhenAIsInNotFullStateAndBIsInSampleState() {
    // Given
    final BoundedTimestampSet boundedTimestampSet1 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants1 = new HashSet<>();
    instants1.add(Instant.ofEpochMilli(1000L));
    instants1.add(Instant.ofEpochMilli(1000000L));
    instants1.forEach(boundedTimestampSet1::add);
    final BoundedTimestampSet boundedTimestampSet2 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants2 = new HashSet<>();
    IntStream.range(50, 150).forEach(i -> instants2.add(Instant.ofEpochMilli(i * 1000L)));
    instants2.forEach(boundedTimestampSet2::add);
    final Set<Instant> allInstants = new HashSet<>(instants1);
    allInstants.addAll(instants2);
    // When
    final BoundedTimestampSet aggregated = BOUNDED_TIMESTAMP_SET_AGGREGATOR._apply(boundedTimestampSet1, boundedTimestampSet2);
    // Then
    assertEquals(10, aggregated.getNumberOfTimestamps());
    assertEquals(BoundedTimestampSet.State.SAMPLE, aggregated.getState());
    assertTrue(allInstants.containsAll(aggregated.getTimestamps()));
}
Also used : Instant(java.time.Instant) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with BoundedTimestampSet

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

the class BoundedTimestampSetAggregatorTest method testAggregateWhenAIsInSampleStateAndBIsInNotFullState.

@Test
public void testAggregateWhenAIsInSampleStateAndBIsInNotFullState() {
    // Given
    final BoundedTimestampSet boundedTimestampSet1 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants1 = new HashSet<>();
    instants1.add(Instant.ofEpochMilli(1000L));
    instants1.add(Instant.ofEpochMilli(1000000L));
    instants1.forEach(boundedTimestampSet1::add);
    final BoundedTimestampSet boundedTimestampSet2 = new BoundedTimestampSet(TimeBucket.SECOND, 10);
    final Set<Instant> instants2 = new HashSet<>();
    IntStream.range(50, 150).forEach(i -> instants2.add(Instant.ofEpochMilli(i * 1000L)));
    instants2.forEach(boundedTimestampSet2::add);
    final Set<Instant> allInstants = new HashSet<>(instants1);
    allInstants.addAll(instants2);
    // When
    final BoundedTimestampSet aggregated = BOUNDED_TIMESTAMP_SET_AGGREGATOR._apply(boundedTimestampSet2, boundedTimestampSet1);
    // Then
    assertEquals(10, aggregated.getNumberOfTimestamps());
    assertEquals(BoundedTimestampSet.State.SAMPLE, aggregated.getState());
    assertTrue(allInstants.containsAll(aggregated.getTimestamps()));
}
Also used : Instant(java.time.Instant) BoundedTimestampSet(uk.gov.gchq.gaffer.time.BoundedTimestampSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with BoundedTimestampSet

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

the class BoundedTimestampSetAggregatorTest method testCantMergeIfDifferentTimeBucket.

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

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