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