Ejemplo n.º 1
0
 private static boolean assertBufferEquals(WindowBuffer window, String... elements) {
   for (int i = 0; i < window.getSize(); i++) {
     ParameterValue pval = window.getHistoricValue(-window.getSize() + 1 + i);
     assertEquals(
         "Incorrect element at position " + i,
         elements[i],
         (pval != null) ? pval.getEngValue().getStringValue() : null);
   }
   return true;
 }
Ejemplo n.º 2
0
  @Test
  public void test() {
    WindowBuffer window = new WindowBuffer(5);
    assertBufferEquals(window, null, null, null, null, null);

    window.update(toPval(50, "a1"));
    window.update(toPval(60, "a2"));
    assertBufferEquals(window, null, null, null, "a1", "a2");

    window.update(toPval(55, "a11"));
    assertBufferEquals(window, null, null, "a1", "a11", "a2");

    window.update(toPval(10, "n"));
    assertBufferEquals(window, null, "n", "a1", "a11", "a2");

    window.update(toPval(5, "n"));
    assertBufferEquals(window, "n", "n", "a1", "a11", "a2");

    window.update(toPval(15, "n")); // older than a1
    assertBufferEquals(window, "n", "n", "a1", "a11", "a2");

    window.update(toPval(60, "n")); // ignored, already have a param at 60
    assertBufferEquals(window, "n", "n", "a1", "a11", "a2");
  }
  @Test
  public void testEmitWindow() throws Exception {

    TestCollector<StreamWindow<Integer>> collector = new TestCollector<StreamWindow<Integer>>();
    List<StreamWindow<Integer>> collected = collector.getCollected();

    WindowBuffer<Integer> wb =
        new JumpingTimePreReducer<Integer>(
            reducer,
            serializer,
            3,
            2,
            new TimestampWrapper<Integer>(
                new Timestamp<Integer>() {

                  private static final long serialVersionUID = 1L;

                  @Override
                  public long getTimestamp(Integer value) {
                    return value;
                  }
                },
                1));

    wb.store(1);
    wb.store(2);
    wb.store(3);
    wb.evict(1);
    wb.emitWindow(collector);

    assertEquals(1, collected.size());
    assertEquals(StreamWindow.fromElements(5), collected.get(0));

    wb.store(4);
    wb.store(5);

    // Nothing should happen here
    wb.evict(2);

    wb.store(6);

    wb.emitWindow(collector);
    wb.evict(2);
    wb.emitWindow(collector);
    wb.store(12);
    wb.emitWindow(collector);

    assertEquals(3, collected.size());
    assertEquals(StreamWindow.fromElements(11), collected.get(1));
    assertEquals(StreamWindow.fromElements(12), collected.get(2));
  }