示例#1
0
  @Test
  public void doubleSubscriptionTest() throws InterruptedException {
    AVar<Integer> val = new AVar<>();
    AVar<Integer> val2 = new AVar<>();

    firehose.on(
        Key.wrap("key1"),
        (key, value) -> {
          return;
        });
    firehose.on(Key.wrap("key1"), val::set);

    firehose.on(Key.wrap("key2"), val2::set);
    firehose.on(
        Key.wrap("key2"),
        (key, value) -> {
          return;
        });

    firehose.notify(Key.wrap("key1"), 1);
    firehose.notify(Key.wrap("key2"), 2);

    assertThat(val.get(10, TimeUnit.MILLISECONDS), is(1));
    assertThat(val2.get(10, TimeUnit.MILLISECONDS), is(2));
  }
示例#2
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)));
  }
示例#3
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)));
  }
示例#4
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();
  }