scala.util.Failure Java Examples
The following examples show how to use
scala.util.Failure.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskManagerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void handleMessage(Object message) throws Exception { if (message instanceof ScheduleOrUpdateConsumers) { getSender().tell( decorateMessage( new Status.Failure(new Exception("Could not schedule or update consumers."))), getSelf()); } else { super.handleMessage(message); } }
Example #2
Source File: BasicTestingDao.java From ob1k with Apache License 2.0 | 5 votes |
@Override public Try<MySQLConnection> validate(final MySQLConnection item) { if (!item.isConnected()) { return new Failure<>(new ConnectionNotConnectedException(item)); } if (item.isQuerying()) { return new Failure<>(new ConnectionStillRunningQueryException(item.count(), false)); } return new Success<>(item); }
Example #3
Source File: RequestContextImplCompleteInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
@Override protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) { try { if (result instanceof Future && ((Future) result).isCompleted()) { Option value = ((Future) result).value(); if (value == null) { return; } Object routeResult = value.get(); if (routeResult instanceof Success) { Object success = ((Success) routeResult).get(); if (success instanceof Complete) { akka.http.javadsl.model.HttpResponse response = ((Complete) success).getResponse(); if (response == null) { return; } akka.http.javadsl.model.StatusCode status = response.status(); if (status == null) { return; } recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, status.intValue()); } } else if (routeResult instanceof Failure) { Throwable failure = ((Failure) routeResult).exception(); recorder.recordException(failure); } } } finally { recorder.recordApi(methodDescriptor); recorder.recordServiceType(AkkaHttpConstants.AKKA_HTTP_SERVER_INTERNAL); recorder.recordException(throwable); } }
Example #4
Source File: HttpPushFactoryTest.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Test public void withHttpProxyConfig() throws Exception { // GIVEN: the connection's URI points to an unreachable host connection = connection.toBuilder() .uri("http://no.such.host.example:42/path/prefix/") .build(); // GIVEN: the HTTP-push factory has the proxy configured to the test server binding final HttpPushFactory underTest = HttpPushFactory.of(connection, new HttpPushConfig() { @Override public int getMaxQueueSize() { return 0; } @Override public HttpProxyConfig getHttpProxyConfig() { return getEnabledProxyConfig(binding); } }); final Pair<SourceQueueWithComplete<HttpRequest>, SinkQueueWithCancel<Try<HttpResponse>>> pair = newSourceSinkQueues(underTest); final SourceQueueWithComplete<HttpRequest> sourceQueue = pair.first(); final SinkQueueWithCancel<Try<HttpResponse>> sinkQueue = pair.second(); final HttpRequest request = underTest.newRequest(HttpPublishTarget.of("PUT:/path/appendage/")); // WHEN: request is made sourceQueue.offer(request); // THEN: CONNECT request is made to the Akka HTTP test server. // THEN: Akka HTTP server rejects CONNECT request, creating a failed response final Optional<Try<HttpResponse>> optionalTryResponse = sinkQueue.pull().toCompletableFuture().join(); assertThat(optionalTryResponse).isNotEmpty(); final Try<HttpResponse> tryResponse = optionalTryResponse.get(); assertThat(tryResponse).isInstanceOf(Failure.class); assertThat(tryResponse.failed().get()).isInstanceOf(ProxyConnectionFailedException.class); assertThat(tryResponse.failed().get().getMessage()) .contains("proxy rejected to open a connection to no.such.host.example:42 with status code: 400"); }
Example #5
Source File: ScalaTrySerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Try<String> createTestData() { return new Failure(new SpecifiedException("Specified exception for ScalaTry.")); }
Example #6
Source File: ScalaTrySerializerUpgradeTest.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Matcher<Try<String>> testDataMatcher() { return is(new Failure(new SpecifiedException("Specified exception for ScalaTry."))); }