cyclops.reactive.ReactiveSeq.retry()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中cyclops.reactive.ReactiveSeq.retry方法的一些代码示例,展示了ReactiveSeq.retry的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.retry方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:retry

ReactiveSeq.retry介绍

[英]Retry a transformation if it fails. Default settings are to retry up to 7 times, with an doubling backoff period starting @ 2 seconds delay before retry.

String result = ReactiveSeq.of( 1,  2, 3)

[中]如果转换失败,请重试转换。默认设置为最多重试7次,在重试前延迟2秒,退避时间加倍

String result = ReactiveSeq.of( 1,  2, 3)

代码示例

代码示例来源:origin: aol/cyclops

/**
 * Retry a transformation if it fails. Default settings are to retry up to 7
 * times, with an doubling backoff period starting @ 2 seconds delay before
 * retry.
 *
 * <pre>
 * {@code
 *
 *
 *
 *         String result = ReactiveSeq.of( 1,  2, 3)
 *                 .retry(this::makeIOCall, 7, 2, TimeUnit.SECONDS)
 *                 .firstValue();
 *
 *         //result = [service call result]
 * }
 * </pre>
 *
 * @param fn
 *            Function to retry if fails
 *
 */
default <R> ReactiveSeq<R> retry(final Function<? super T, ? extends R> fn) {
  return retry(fn, 7, 2, TimeUnit.SECONDS);
}

代码示例来源:origin: aol/cyclops

@Test
public void shouldSucceedAfterFewAsynchronousRetries() throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException(new SocketException("First")),
      new RuntimeException(new IOException("Second"))).willReturn(
      "42");
  long time = System.currentTimeMillis();
  String result = of( 1,  2, 3)
      .retry(serviceMock,7,200,TimeUnit.MILLISECONDS)
      .firstValue(null);
  assertThat(System.currentTimeMillis()-time,greaterThan(200l));
  assertThat(result, is("42"));
}

代码示例来源:origin: aol/cyclops

@Test
public void shouldSucceedAfterFewAsynchronousRetries() throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException(new SocketException("First")),
      new RuntimeException(new IOException("Second"))).willReturn(
      "42");
  long time = System.currentTimeMillis();
  String result = of( 1,  2, 3)
      .retry(serviceMock,7,200,TimeUnit.MILLISECONDS)
      .firstValue(null);
  assertThat(System.currentTimeMillis()-time,greaterThan(200l));
  assertThat(result, is("42"));
}

代码示例来源:origin: aol/cyclops

@Test
public void shouldSucceedAfterFewAsynchronousRetries() throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException(new SocketException("First")),
      new RuntimeException(new IOException("Second"))).willReturn(
      "42");
  long time = System.currentTimeMillis();
  String result = of( 1,  2, 3)
      .retry(serviceMock,7,200,TimeUnit.MILLISECONDS)
      .firstValue(null);
  assertThat(System.currentTimeMillis()-time,greaterThan(200l));
  assertThat(result, is("42"));
}

代码示例来源:origin: aol/cyclops

@Test
public void shouldSucceedAfterFewAsynchronousRetries() throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException(new SocketException("First")),
      new RuntimeException(new IOException("Second"))).willReturn(
      "42");
  long time = System.currentTimeMillis();
  String result = ReactiveSeq.of( 1,  2, 3)
      .retry(serviceMock,7,200,TimeUnit.MILLISECONDS)
      .firstValue(null);
  assertThat(System.currentTimeMillis()-time,greaterThan(200l));
  assertThat(result, is("42"));
}

代码示例来源:origin: aol/cyclops

@Test
public void shouldSucceedAfterFewAsynchronousRetries() throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException(new SocketException("First")),
      new RuntimeException(new IOException("Second"))).willReturn(
      "42");
  long time = System.currentTimeMillis();
  String result = Spouts.of( 1,  2, 3)
      .retry(serviceMock,7,200,TimeUnit.MILLISECONDS)
      .firstValue(null);
  assertThat(System.currentTimeMillis()-time,greaterThan(200l));
  assertThat(result, is("42"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowExceptionThatWasThrownFromUserTaskBeforeReturningFuture()
    throws Exception {
  error = null;
  given(serviceMock.apply(anyInt())).willThrow(
      new IllegalArgumentException("DONT PANIC"));
  List<String> result = of(1).retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  error.printStackTrace();
  assertThat(error.getCause(), instanceOf(IllegalArgumentException.class));
  assertThat(error.getCause().getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowExceptionThatWasThrownFromUserTaskBeforeReturningFuture()
    throws Exception {
  error = null;
  given(serviceMock.apply(anyInt())).willThrow(
      new IllegalArgumentException("DONT PANIC"));
  List<String> result = of(1).retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  error.printStackTrace();
  assertThat(error.getCause(), instanceOf(IllegalArgumentException.class));
  assertThat(error.getCause().getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowExceptionThatWasThrownFromUserTaskBeforeReturningFuture()
    throws Exception {
  error = null;
  given(serviceMock.apply(anyInt())).willThrow(
      new IllegalArgumentException("DONT PANIC"));
  List<String> result = Spouts.of(1).retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  error.printStackTrace();
  assertThat(error.getCause(), instanceOf(IllegalArgumentException.class));
  assertThat(error.getCause().getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowExceptionThatWasThrownFromUserTaskBeforeReturningFuture()
    throws Exception {
  error = null;
  given(serviceMock.apply(anyInt())).willThrow(
      new IllegalArgumentException("DONT PANIC"));
  List<String> result = ReactiveSeq.of(1).retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  error.printStackTrace();
  assertThat(error.getCause(), instanceOf(IllegalArgumentException.class));
  assertThat(error.getCause().getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowExceptionThatWasThrownFromUserTaskBeforeReturningFuture()
    throws Exception {
  error = null;
  given(serviceMock.apply(anyInt())).willThrow(
      new IllegalArgumentException("DONT PANIC"));
  List<String> result = of(1).retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  error.printStackTrace();
  assertThat(error.getCause(), instanceOf(IllegalArgumentException.class));
  assertThat(error.getCause().getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowOriginalExceptionFromUserFutureCompletion()
    throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException("DONT PANIC"));
  List<String> result = ReactiveSeq.of(1)
      .retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  assertThat((error).getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowOriginalExceptionFromUserFutureCompletion()
    throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException("DONT PANIC"));
  List<String> result = of(1)
      .retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  assertThat((error).getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowOriginalExceptionFromUserFutureCompletion()
    throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException("DONT PANIC"));
  List<String> result = Spouts.of(1)
      .retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  assertThat((error).getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test
  public void retryShouldWaitOnlyAfterFailure() {
    final long[] timings = {System.currentTimeMillis(), Long.MAX_VALUE};
    Function<Integer, Integer> fn = i -> {
      timings[1] = System.currentTimeMillis();
      return 2 * i;
    };

    of(1)
          .retry(fn, 3, 10000, TimeUnit.MILLISECONDS)
          .firstValue(null);

    assertTrue(timings[1] - timings[0] < 5000);
  }
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowOriginalExceptionFromUserFutureCompletion()
    throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException("DONT PANIC"));
  List<String> result = of(1)
      .retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  assertThat((error).getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test @Ignore
public void shouldRethrowOriginalExceptionFromUserFutureCompletion()
    throws Exception {
  given(serviceMock.apply(anyInt())).willThrow(
      new RuntimeException("DONT PANIC"));
  List<String> result = of(1)
      .retry(serviceMock).toList();
  assertThat(result.size(), is(0));
  assertThat((error).getMessage(), is("DONT PANIC"));
}

代码示例来源:origin: aol/cyclops

@Test(expected = ArithmeticException.class)
public void retryShouldExecuteFnEvenIfRetryIsZero() {
  Function<Integer, Integer> fn = i -> i / 0;
  of(1)
        .retry(fn, 0, 1, TimeUnit.SECONDS)
        .firstValue(null);
  fail();
}

代码示例来源:origin: aol/cyclops

@Test
public void retryShouldNotThrowNPEIfRetryIsZero() {
  Function<Integer, Integer> fn = i -> 2 * i;
  int result = of(1)
              .retry(fn, 0, 1, TimeUnit.SECONDS)
              .firstValue(null);
  assertEquals(2, result);
}

代码示例来源:origin: com.oath.cyclops/cyclops-futurestream

@Override
default <R> FutureStream<R> retry(final Function<? super U, ? extends R> fn) {
  return (FutureStream) ReactiveSeq.super.retry(fn);
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法