Search in sources :

Example 26 with Duration

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();
}
Also used : GlobalWindows(org.apache.beam.sdk.transforms.windowing.GlobalWindows) Duration(org.joda.time.Duration) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 27 with Duration

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))));
}
Also used : Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 28 with Duration

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) {
    }
}
Also used : Period(org.joda.time.Period) ReadWritablePeriod(org.joda.time.ReadWritablePeriod) ReadablePeriod(org.joda.time.ReadablePeriod) Duration(org.joda.time.Duration) ReadableDuration(org.joda.time.ReadableDuration) Interval(org.joda.time.Interval) ReadableInterval(org.joda.time.ReadableInterval) ReadWritableInterval(org.joda.time.ReadWritableInterval)

Example 29 with Duration

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());
}
Also used : MutablePeriod(org.joda.time.MutablePeriod) ReadableDuration(org.joda.time.ReadableDuration) Duration(org.joda.time.Duration)

Example 30 with Duration

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);
}
Also used : SdkFunctionSpec(org.apache.beam.sdk.common.runner.v1.RunnerApi.SdkFunctionSpec) Trigger(org.apache.beam.sdk.transforms.windowing.Trigger) TimestampCombiner(org.apache.beam.sdk.transforms.windowing.TimestampCombiner) AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode) Duration(org.joda.time.Duration) ClosingBehavior(org.apache.beam.sdk.transforms.windowing.Window.ClosingBehavior)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9