Ejemplo n.º 1
0
 public static <W extends BoundedWindow> TriggerTester<Integer, Iterable<Integer>, W> nonCombining(
     WindowingStrategy<?, W> windowingStrategy) throws Exception {
   return new TriggerTester<Integer, Iterable<Integer>, W>(
       windowingStrategy,
       SystemReduceFn.<String, Integer, W>buffering(VarIntCoder.of()).create(KEY),
       IterableCoder.of(VarIntCoder.of()));
 }
Ejemplo n.º 2
0
  @Test
  public void testAfterPaneWithGlobalWindowsAndCombining() throws Exception {
    Duration windowDuration = Duration.millis(10);
    ReduceFnTester<Integer, Integer, IntervalWindow> tester =
        ReduceFnTester.combining(
            FixedWindows.of(windowDuration),
            AfterPane.<IntervalWindow>elementCountAtLeast(2),
            AccumulationMode.DISCARDING_FIRED_PANES,
            new SumIntegerFn().<String>asKeyedFn(),
            VarIntCoder.of(),
            Duration.millis(100));

    tester.injectElements(
        TimestampedValue.of(1, new Instant(1)), TimestampedValue.of(2, new Instant(9)));

    assertThat(
        tester.extractOutput(),
        Matchers.contains(WindowMatchers.isSingleWindowedValue(Matchers.equalTo(3), 1, 0, 10)));

    // This element should not be output because that trigger (which was one-time) has already
    // gone off.
    tester.injectElements(TimestampedValue.of(6, new Instant(2)));
    assertThat(tester.extractOutput(), Matchers.emptyIterable());

    assertTrue(tester.isMarkedFinished(new IntervalWindow(new Instant(0), new Instant(10))));
    assertFalse(tester.isMarkedFinished(new IntervalWindow(new Instant(10), new Instant(20))));

    tester.assertHasOnlyGlobalAndFinishedSetsFor(
        new IntervalWindow(new Instant(0), new Instant(10)));
  }
Ejemplo n.º 3
0
/** Test case for {@link SetCoder}. */
@RunWith(JUnit4.class)
public class SetCoderTest {

  private static final Coder<Set<Integer>> TEST_CODER = SetCoder.of(VarIntCoder.of());

  private static final List<Set<Integer>> TEST_VALUES =
      Arrays.<Set<Integer>>asList(
          Collections.<Integer>emptySet(),
          Collections.singleton(13),
          new HashSet<>(Arrays.asList(31, -5, 83)));

  @Test
  public void testDecodeEncodeContentsEqual() throws Exception {
    for (Set<Integer> value : TEST_VALUES) {
      CoderProperties.coderDecodeEncodeContentsEqual(TEST_CODER, value);
    }
  }

  // If this changes, it implies the binary format has changed.
  private static final String EXPECTED_ENCODING_ID = "";

  @Test
  public void testEncodingId() throws Exception {
    CoderProperties.coderHasEncodingId(TEST_CODER, EXPECTED_ENCODING_ID);
  }
}
Ejemplo n.º 4
0
  public static <W extends BoundedWindow, AccumT, OutputT>
      TriggerTester<Integer, OutputT, W> combining(
          WindowFn<?, W> windowFn,
          Trigger<W> trigger,
          AccumulationMode mode,
          KeyedCombineFn<String, Integer, AccumT, OutputT> combineFn,
          Coder<OutputT> outputCoder,
          Duration allowedDataLateness)
          throws Exception {

    WindowingStrategy<?, W> strategy =
        WindowingStrategy.of(windowFn)
            .withTrigger(trigger)
            .withMode(mode)
            .withAllowedLateness(allowedDataLateness);

    CoderRegistry registry = new CoderRegistry();
    registry.registerStandardCoders();
    AppliedCombineFn<String, Integer, AccumT, OutputT> fn =
        AppliedCombineFn.<String, Integer, AccumT, OutputT>withInputCoder(
            combineFn, registry, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()));

    return new TriggerTester<Integer, OutputT, W>(
        strategy,
        SystemReduceFn.<String, Integer, AccumT, OutputT, W>combining(StringUtf8Coder.of(), fn)
            .create(KEY),
        outputCoder);
  }
Ejemplo n.º 5
0
 @Test
 public void testDecodeEncodeContentsEqual() throws Exception {
   Coder<Set<Integer>> coder = SetCoder.of(VarIntCoder.of());
   for (Set<Integer> value : TEST_VALUES) {
     CoderProperties.coderDecodeEncodeContentsEqual(coder, value);
   }
 }
 @Test
 public void testDecodeEncodeEqual() throws Exception {
   Coder<Integer> coder = VarIntCoder.of();
   for (Integer value : TEST_VALUES) {
     CoderProperties.coderDecodeEncodeEqual(coder, value);
   }
 }
 @Override
 protected Coder<?> getDefaultOutputCoder() {
   return VarIntCoder.of();
 }