本文整理了Java中com.google.common.truth.ThrowableSubject.isNotNull()
方法的一些代码示例,展示了ThrowableSubject.isNotNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.isNotNull()
方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:isNotNull
暂无
代码示例来源:origin: google/ExoPlayer
@Test
public void testInvalidBitstream() {
try {
playUri(INVALID_BITSTREAM_URI);
fail();
} catch (Exception e) {
assertThat(e.getCause()).isNotNull();
assertThat(e.getCause()).isInstanceOf(VpxDecoderException.class);
}
}
代码示例来源:origin: googleapis/google-cloud-java
assertThat(error).isNotNull();
} else {
if (error != null) {
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void readRowRetryCodesMustMatch() {
EnhancedBigtableStubSettings.Builder builder =
EnhancedBigtableStubSettings.newBuilder()
.setProjectId("my-project")
.setInstanceId("my-instance");
builder.readRowsSettings().setRetryableCodes(Code.DEADLINE_EXCEEDED);
builder.readRowSettings().setRetryableCodes(Code.ABORTED);
Exception actualError = null;
try {
builder.build();
} catch (Exception e) {
actualError = e;
}
assertThat(actualError).isNotNull();
builder.readRowSettings().setRetryableCodes(Code.DEADLINE_EXCEEDED);
actualError = null;
try {
builder.build();
} catch (Exception e) {
actualError = e;
}
assertThat(actualError).isNull();
}
代码示例来源:origin: uber/motif
public static void run() {
assertThat(error).isNotNull();
}
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testBidiStreamingServerError() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable =
GrpcCallableFactory.createBidiStreamingCallable(
GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE_ERROR), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver =
new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
stream.send(request);
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNotNull();
assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
assertThat(moneyObserver.error.getCause()).isInstanceOf(StatusRuntimeException.class);
assertThat(((StatusRuntimeException) moneyObserver.error.getCause()).getStatus())
.isEqualTo(Status.INVALID_ARGUMENT);
assertThat(moneyObserver.response).isNull();
}
代码示例来源:origin: googleapis/gax-java
assertThat(actualError).isNotNull();
assertThat(isMethodInStacktrace(currentMethod, actualError)).isFalse();
代码示例来源:origin: googleapis/gax-java
@Test
public void testGetSpanNameInvalid() {
List<String> invalidNames = ImmutableList.of("no_split", ".no_client");
for (String invalidName : invalidNames) {
@SuppressWarnings("unchecked")
ApiMethodDescriptor descriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(invalidName)
.setHttpMethod(HttpMethods.POST)
.setRequestFormatter(Mockito.mock(HttpRequestFormatter.class))
.setResponseParser(Mockito.mock(HttpResponseParser.class))
.build();
IllegalArgumentException actualError = null;
try {
SpanName spanName = HttpJsonCallableFactory.getSpanName(descriptor);
assertWithMessage("Invalid method descriptor should not have a valid span name")
.fail("%s should not generate the spanName: %s", invalidName, spanName);
} catch (IllegalArgumentException e) {
actualError = e;
}
assertThat(actualError).isNotNull();
}
}
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testGetSpanNameInvalid() {
List<String> invalidNames = ImmutableList.of("BareMethod", "/MethodWithoutService");
for (String invalidName : invalidNames) {
@SuppressWarnings("unchecked")
MethodDescriptor descriptor =
MethodDescriptor.newBuilder()
.setType(MethodType.SERVER_STREAMING)
.setFullMethodName(invalidName)
.setRequestMarshaller(Mockito.mock(Marshaller.class))
.setResponseMarshaller(Mockito.mock(Marshaller.class))
.build();
IllegalArgumentException actualError = null;
try {
SpanName spanName = GrpcCallableFactory.getSpanName(descriptor);
Truth.assertWithMessage("Invalid method descriptor should not have a valid span name")
.fail("%s should not generate the spanName: %s", invalidName, spanName);
} catch (IllegalArgumentException e) {
actualError = e;
}
assertThat(actualError).isNotNull();
}
}
}
代码示例来源:origin: googleapis/gax-java
private void assertFutureCancelMetaCancel(OperationFuture<Color, Currency> future)
throws InterruptedException, ExecutionException, TimeoutException {
Exception exception = null;
try {
future.get(3, TimeUnit.SECONDS);
} catch (CancellationException e) {
exception = e;
}
assertThat(exception).isNotNull();
assertThat(future.isDone()).isTrue();
assertThat(future.isCancelled()).isTrue();
try {
future.peekMetadata().get();
} catch (CancellationException e) {
exception = e;
}
assertThat(future.peekMetadata()).isSameAs(future.peekMetadata());
assertThat(exception).isNotNull();
assertThat(future.peekMetadata().isDone()).isTrue();
assertThat(future.peekMetadata().isCancelled()).isTrue();
try {
future.getMetadata().get();
} catch (CancellationException e) {
exception = e;
}
assertThat(future.getMetadata()).isSameAs(future.getMetadata());
assertThat(exception).isNotNull();
assertThat(future.getMetadata().isDone()).isTrue();
assertThat(future.getMetadata().isCancelled()).isTrue();
}
代码示例来源:origin: googleapis/gax-java
assertThat(exception).isNotNull();
if (statusCode != null) {
assertExceptionMatchesCode(statusCode, exception.getCause());
exception = e;
assertThat(exception).isNotNull();
if (statusCode != null) {
assertExceptionMatchesCode(statusCode, exception.getCause());
exception = e;
assertThat(exception).isNotNull();
if (statusCode != null) {
assertExceptionMatchesCode(statusCode, exception.getCause());
代码示例来源:origin: googleapis/gax-java
@Test
public void testBidiStreamingClientError() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable =
GrpcCallableFactory.createBidiStreamingCallable(
GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE_ERROR), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver =
new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
Throwable clientError = new StatusRuntimeException(Status.CANCELLED);
stream.closeSendWithError(clientError);
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNotNull();
assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
assertThat(((ApiException) moneyObserver.error).getStatusCode().getCode())
.isEqualTo(Code.CANCELLED);
assertThat(moneyObserver.response).isNull();
// As of gRPC 1.8, when the client closes, the server gRPC issues
// io.grpc.StatusRuntimeException: CANCELLED: cancelled before receiving half close
// to the server application, and our error is not propagated.
// We don't check the error received by the server; we can't round-trip it.
}
代码示例来源:origin: googleapis/gax-java
assertThat(exception).isNotNull();
assertExceptionMatchesCode(statusCode, exception.getCause());
ApiException cause = (ApiException) exception.getCause();
assertThat(exception).isNotNull();
assertExceptionMatchesCode(statusCode, exception.getCause());
cause = (ApiException) exception.getCause();
代码示例来源:origin: googleapis/gax-java
@Test
public void cancellationDuringRetryDelay() throws Exception {
Throwable throwable =
new UnavailableException(null, FakeStatusCode.of(StatusCode.Code.UNAVAILABLE), true);
CancellationTrackingFuture<Integer> innerFuture = CancellationTrackingFuture.create();
Mockito.when(callInt.futureCall((Integer) Mockito.any(), (ApiCallContext) Mockito.any()))
.thenReturn(RetryingTest.<Integer>immediateFailedFuture(throwable))
.thenReturn(innerFuture);
CountDownLatch retryScheduledLatch = new CountDownLatch(1);
LatchCountDownScheduler scheduler = LatchCountDownScheduler.get(retryScheduledLatch, 0L, 0L);
UnaryCallSettings<Integer, Integer> callSettings =
RetryingTest.createSettings(SLOW_RETRY_SETTINGS);
UnaryCallable<Integer, Integer> callable =
FakeCallableFactory.createUnaryCallable(
callInt, callSettings, clientContext.toBuilder().setExecutor(scheduler).build());
ApiFuture<Integer> resultFuture = callable.futureCall(0);
CancellationHelpers.cancelInThreadAfterLatchCountDown(resultFuture, retryScheduledLatch);
CancellationException gotException = null;
try {
resultFuture.get();
} catch (CancellationException e) {
gotException = e;
}
Truth.assertThat(gotException).isNotNull();
Truth.assertThat(resultFuture.isDone()).isTrue();
Truth.assertThat(resultFuture.isCancelled()).isTrue();
Truth.assertThat(innerFuture.isCancelled()).isFalse();
scheduler.shutdownNow();
}
代码示例来源:origin: googleapis/gax-java
@Test
public void cancellationDuringFirstCall() throws Exception {
CancellationTrackingFuture<Integer> innerFuture = CancellationTrackingFuture.<Integer>create();
CountDownLatch callIssuedLatch = new CountDownLatch(1);
UnaryCallable<Integer, Integer> innerCallable =
new LatchCountDownFutureCallable<>(callIssuedLatch, innerFuture);
UnaryCallSettings<Integer, Integer> callSettings =
RetryingTest.createSettings(FAST_RETRY_SETTINGS);
UnaryCallable<Integer, Integer> callable =
FakeCallableFactory.createUnaryCallable(
innerCallable,
callSettings,
clientContext.toBuilder().setExecutor(new ScheduledThreadPoolExecutor(1)).build());
ApiFuture<Integer> resultFuture = callable.futureCall(0);
CancellationHelpers.cancelInThreadAfterLatchCountDown(resultFuture, callIssuedLatch);
CancellationException gotException = null;
try {
resultFuture.get();
} catch (CancellationException e) {
gotException = e;
}
Truth.assertThat(gotException).isNotNull();
Truth.assertThat(innerFuture.isCancelled()).isTrue();
}
代码示例来源:origin: googleapis/gax-java
private void assertFutureFailMetaSuccess(
OperationFuture<Color, Currency> future,
Currency meta,
FakeStatusCode statusCode,
String errorMessage)
throws TimeoutException, InterruptedException, ExecutionException {
Exception exception = null;
try {
future.get(3, TimeUnit.SECONDS);
} catch (ExecutionException e) {
exception = e;
}
assertThat(exception).isNotNull();
assertExceptionMatchesCode(statusCode, exception.getCause());
ApiException cause = (ApiException) exception.getCause();
assertThat(cause.getStatusCode()).isEqualTo(statusCode);
assertThat(cause.getMessage()).isEqualTo(errorMessage);
assertThat(future.isDone()).isTrue();
assertThat(future.isCancelled()).isFalse();
Truth.assertThat(future.peekMetadata().get()).isEqualTo(meta);
assertThat(future.peekMetadata()).isSameAs(future.peekMetadata());
assertThat(future.peekMetadata().isDone()).isTrue();
assertThat(future.peekMetadata().isCancelled()).isFalse();
Truth.assertThat(future.getMetadata().get()).isEqualTo(meta);
assertThat(future.getMetadata()).isSameAs(future.getMetadata());
assertThat(future.getMetadata().isDone()).isTrue();
assertThat(future.getMetadata().isCancelled()).isFalse();
}
代码示例来源:origin: googleapis/gax-java
gotException = e;
Truth.assertThat(gotException).isNotNull();
Truth.assertThat(resultFuture.isDone()).isTrue();
Truth.assertThat(resultFuture.isCancelled()).isTrue();
代码示例来源:origin: googleapis/gax-java
@Test
public void testFutureCallInitialCancel() throws Exception {
String opName = "testFutureCallInitialCancel";
OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
OperationSnapshot resultOperation = getOperation(opName, null, null, null, false);
UnaryCallable<Integer, OperationSnapshot> initialCallable =
mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation);
OperationCallableImpl<Integer, Color, Currency> callableImpl =
Callables.longRunningOperationImpl(
initialCallable, callSettings, initialContext, longRunningClient);
OperationFutureImpl<Color, Currency> future =
callableImpl.futureCall(
new ListenableFutureToApiFuture<>(
Futures.<OperationSnapshot>immediateCancelledFuture()),
FakeCallContext.createDefault());
Exception exception = null;
try {
future.get(3, TimeUnit.SECONDS);
} catch (CancellationException e) {
exception = e;
}
assertThat(exception).isNotNull();
assertThat(future.isDone()).isTrue();
assertThat(future.isCancelled()).isTrue();
assertThat(future.getInitialFuture().isDone()).isTrue();
assertThat(future.getInitialFuture().isCancelled()).isTrue();
assertFutureCancelMetaCancel(future);
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
内容来源于网络,如有侵权,请联系作者删除!