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