use of org.joda.time.Duration in project beam by apache.
the class CombineTest method testGlobalCombineWithDefaultsAndTriggers.
@Test
@Category(ValidatesRunner.class)
public void testGlobalCombineWithDefaultsAndTriggers() {
PCollection<Integer> input = pipeline.apply(Create.of(1, 1));
PCollection<String> output = input.apply(Window.<Integer>into(new GlobalWindows()).triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(1))).accumulatingFiredPanes().withAllowedLateness(new Duration(0))).apply(Sum.integersGlobally()).apply(ParDo.of(new FormatPaneInfo()));
// The actual elements produced are nondeterministic. Could be one, could be two.
// But it should certainly have a final element with the correct final sum.
PAssert.that(output).satisfies(new SerializableFunction<Iterable<String>, Void>() {
@Override
public Void apply(Iterable<String> input) {
assertThat(input, hasItem("2: true"));
return null;
}
});
pipeline.run();
}
use of org.joda.time.Duration in project beam by apache.
the class FixedWindowsTest method testEquality.
@Test
public void testEquality() {
assertTrue(FixedWindows.of(new Duration(10)).isCompatible(FixedWindows.of(new Duration(10))));
assertTrue(FixedWindows.of(new Duration(10)).isCompatible(FixedWindows.of(new Duration(10))));
assertTrue(FixedWindows.of(new Duration(10)).isCompatible(FixedWindows.of(new Duration(10))));
assertFalse(FixedWindows.of(new Duration(10)).isCompatible(FixedWindows.of(new Duration(20))));
assertFalse(FixedWindows.of(new Duration(10)).isCompatible(FixedWindows.of(new Duration(20))));
}
use of org.joda.time.Duration in project joda-time by JodaOrg.
the class TestConverterManager method testGetPeriodConverter.
public void testGetPeriodConverter() {
PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
assertEquals(ReadablePeriod.class, c.getSupportedType());
c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
assertEquals(ReadableDuration.class, c.getSupportedType());
c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
assertEquals(ReadableInterval.class, c.getSupportedType());
c = ConverterManager.getInstance().getPeriodConverter("");
assertEquals(String.class, c.getSupportedType());
c = ConverterManager.getInstance().getPeriodConverter(null);
assertEquals(null, c.getSupportedType());
try {
ConverterManager.getInstance().getPeriodConverter(Boolean.TRUE);
fail();
} catch (IllegalArgumentException ex) {
}
}
use of org.joda.time.Duration in project joda-time by JodaOrg.
the class TestReadableDurationConverter method testSetInto_Object.
public void testSetInto_Object() throws Exception {
MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime());
ReadableDurationConverter.INSTANCE.setInto(m, new Duration(3L * DateTimeConstants.MILLIS_PER_DAY + 4L * DateTimeConstants.MILLIS_PER_MINUTE + 5L), null);
assertEquals(0, m.getYears());
assertEquals(0, m.getMonths());
assertEquals(0, m.getWeeks());
assertEquals(0, m.getDays());
assertEquals(3 * 24, m.getHours());
assertEquals(4, m.getMinutes());
assertEquals(0, m.getSeconds());
assertEquals(5, m.getMillis());
}
use of org.joda.time.Duration in project beam by apache.
the class WindowingStrategyTranslation method fromProto.
/**
* Converts from {@link RunnerApi.WindowingStrategy} to the SDK's {@link WindowingStrategy} using
* the provided components to dereferences identifiers found in the proto.
*/
public static WindowingStrategy<?, ?> fromProto(RunnerApi.WindowingStrategy proto, Components components) throws InvalidProtocolBufferException {
SdkFunctionSpec windowFnSpec = proto.getWindowFn();
WindowFn<?, ?> windowFn = windowFnFromProto(windowFnSpec);
TimestampCombiner timestampCombiner = timestampCombinerFromProto(proto.getOutputTime());
AccumulationMode accumulationMode = fromProto(proto.getAccumulationMode());
Trigger trigger = TriggerTranslation.fromProto(proto.getTrigger());
ClosingBehavior closingBehavior = fromProto(proto.getClosingBehavior());
Duration allowedLateness = Duration.millis(proto.getAllowedLateness());
return WindowingStrategy.of(windowFn).withAllowedLateness(allowedLateness).withMode(accumulationMode).withTrigger(trigger).withTimestampCombiner(timestampCombiner).withClosingBehavior(closingBehavior);
}
Aggregations