Пример #1
0
  @Test
  public void simpleOn2Test() throws InterruptedException {
    AVar<Tuple2> val = new AVar<>();
    firehose.on(
        Key.wrap("key1"),
        (key, value) -> {
          val.set(Tuple.of(key, value));
        });
    firehose.notify(Key.wrap("key1"), 1);

    assertThat(val.get(10, TimeUnit.MILLISECONDS), is(Tuple.of(Key.wrap("key1"), 1)));
  }
Пример #2
0
  @Test
  public void keyMissTest() throws InterruptedException {
    AVar<Tuple2> val = new AVar<>();

    firehose.miss(
        (k_) -> true,
        (k) -> {
          return Collections.singletonMap(
              k,
              (key, value) -> {
                val.set(Tuple.of(key, value));
              });
        });

    firehose.notify(Key.wrap("key1"), 1);
    assertThat(val.get(10, TimeUnit.MILLISECONDS), is(Tuple.of(Key.wrap("key1"), 1)));
  }
Пример #3
0
  @Test
  public void errorTest() throws InterruptedException {
    AVar<Throwable> caught = new AVar<>();
    Dispatcher asyncDispatcher = new ThreadPoolExecutorDispatcher(2, 100);
    Firehose<Key, Integer> asyncFirehose =
        new Firehose<>(asyncDispatcher, consumerRegistry, null, throwable -> caught.set(throwable));
    Key k1 = Key.wrap("key1");

    asyncFirehose.on(
        k1,
        (i) -> {
          int j = i / 0;
        });

    asyncFirehose.notify(k1, 1);

    assertTrue(caught.get(1, TimeUnit.MINUTES) instanceof ArithmeticException);

    asyncDispatcher.shutdown();
  }