Java Code Examples for io.vertx.core.Future#result()
The following examples show how to use
io.vertx.core.Future#result() .
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: CacheServiceTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void cacheBidsOpenrtbShouldReturnExpectedCacheBids() { // given final com.iab.openrtb.response.Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); // when final Future<CacheServiceResult> future = cacheService.cacheBidsOpenrtb( singletonList(bid), singletonList(givenImp(builder -> builder.id("impId1"))), CacheContext.builder() .shouldCacheBids(true) .bidderToBidIds(singletonMap("bidder", singletonList("bidId1"))) .build(), account, eventsContext, timeout); // then final CacheServiceResult result = future.result(); assertThat(result.getCacheBids()).hasSize(1) .containsEntry(bid, CacheIdInfo.of("uuid1", null)); }
Example 2
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void callShouldSubmitErrorToAdapterIfHttpResponseBodyCouldNotBeParsed() { // given givenHttpClientReturnsResponse(200, "response"); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isNotNull(); assertThat(adapterResponse.getError().getMessage()).startsWith("Failed to decode"); assertThat(adapterResponse.getError().getType()).isEqualTo(BidderError.Type.bad_server_response); assertThat(adapterResponse.getBidderStatus().getError()).startsWith("Failed to decode"); }
Example 3
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void callShouldReturnAdapterResponseWithDebugIfFlagIsTrueAndGlobalTimeoutAlreadyExpired() { // given preBidRequestContext = givenPreBidRequestContext( builder -> builder .timeout(expiredTimeout()) .isDebug(true), identity()); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getBidderStatus().getDebug()).hasSize(1); final BidderDebug bidderDebug = adapterResponse.getBidderStatus().getDebug().get(0); assertThat(bidderDebug.getRequestUri()).isNotBlank(); assertThat(bidderDebug.getRequestBody()).isNotBlank(); }
Example 4
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void callShouldSubmitTimeOutErrorToAdapterIfGlobalTimeoutAlreadyExpired() { // given preBidRequestContext = givenPreBidRequestContext( builder -> builder.timeout(expiredTimeout()), identity()); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isEqualTo(BidderError.timeout("Timed out")); assertThat(adapterResponse.getBidderStatus().getError()).isEqualTo("Timed out"); verifyZeroInteractions(httpClient); }
Example 5
Source File: Sync.java From vertx-vaadin with MIT License | 6 votes |
public static <T> T await(Consumer<Handler<AsyncResult<T>>> task) { CountDownLatch countDownLatch = new CountDownLatch(1); try { Promise<T> p = Promise.promise(); Future<T> f = p.future(); f.setHandler(ar -> { countDownLatch.countDown(); if (ar.failed()) { throw new VertxException(ar.cause()); } }); task.accept(p); countDownLatch.await(); return f.result(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new VertxException(e); } }
Example 6
Source File: CacheServiceTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void cacheBidsOpenrtbShouldReturnExpectedDebugInfo() throws JsonProcessingException { // given final com.iab.openrtb.response.Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); // when final Future<CacheServiceResult> future = cacheService.cacheBidsOpenrtb( singletonList(bid), singletonList(givenImp(builder -> builder.id("impId1"))), CacheContext.builder() .shouldCacheBids(true) .bidderToBidIds(singletonMap("bidder", singletonList("bidId1"))) .build(), account, eventsContext, timeout); // then final CacheServiceResult result = future.result(); assertThat(result.getHttpCall()).isNotNull() .isEqualTo(CacheHttpCall.of(givenCacheHttpRequest(bid), CacheHttpResponse.of(200, "{\"responses\":[{\"uuid\":\"uuid1\"}]}"), 0)); }
Example 7
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void callShouldReturnAdapterResponseWithErrorIfErrorsOccurWhileExtractingForNotToleratedErrorsAdapter() throws JsonProcessingException { // given willReturn(asList(givenHttpRequest(), givenHttpRequest())).given(adapter).makeHttpRequests(any(), any()); final AdUnitBid adUnitBid = givenAdUnitBid(identity()); adapterRequest = AdapterRequest.of("bidderCode1", asList(adUnitBid, adUnitBid)); given(adapter.extractBids(any(), any())) .willReturn(singletonList(org.prebid.server.proto.response.Bid.builder())) .willThrow(new PreBidException("adapter extractBids exception")); final String bidResponse = givenBidResponse(identity(), identity(), singletonList(identity())); givenHttpClientReturnsResponse(200, bidResponse); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()) .isEqualTo(BidderError.badServerResponse("adapter extractBids exception")); assertThat(adapterResponse.getBidderStatus().getError()).isEqualTo("adapter extractBids exception"); }
Example 8
Source File: CacheServiceTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void cacheBidsOpenrtbShouldTolerateReadingHttpResponseFails() throws JsonProcessingException { // given givenHttpClientProducesException(new RuntimeException("Response exception")); final com.iab.openrtb.response.Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); // when final Future<CacheServiceResult> future = cacheService.cacheBidsOpenrtb( singletonList(bid), singletonList(givenImp(builder -> builder.id("impId1"))), CacheContext.builder() .shouldCacheBids(true) .bidderToBidIds(singletonMap("bidder", singletonList("bidId1"))) .build(), account, eventsContext, timeout); // then final CacheServiceResult result = future.result(); assertThat(result.getCacheBids()).isEmpty(); assertThat(result.getError()).isInstanceOf(RuntimeException.class).hasMessage("Response exception"); assertThat(result.getHttpCall()).isNotNull() .isEqualTo(CacheHttpCall.of(givenCacheHttpRequest(bid), null, 0)); }
Example 9
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void callShouldReturnAdapterResponseWithDebugIfFlagIsTrueAndResponseIsNotSuccessful() { // given preBidRequestContext = givenPreBidRequestContext(builder -> builder.isDebug(true), identity()); givenHttpClientReturnsResponse(503, "response"); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getBidderStatus().getDebug()).hasSize(1); final BidderDebug bidderDebug = adapterResponse.getBidderStatus().getDebug().get(0); assertThat(bidderDebug.getRequestUri()).isNotBlank(); assertThat(bidderDebug.getRequestBody()).isNotBlank(); assertThat(bidderDebug.getResponseBody()).isNotBlank(); assertThat(bidderDebug.getStatusCode()).isPositive(); }
Example 10
Source File: Sync.java From vertx-vaadin with MIT License | 6 votes |
public static <T> T await(Consumer<Handler<AsyncResult<T>>> task) { CountDownLatch countDownLatch = new CountDownLatch(1); try { Future<T> f = Future.<T>future().setHandler(ar -> { countDownLatch.countDown(); if (ar.failed()) { throw new VertxException(ar.cause()); } }); task.accept(f.completer()); countDownLatch.await(); return f.result(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new VertxException(e); } }
Example 11
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldReturnAdapterResponseWithEmptyBidsIfAdUnitBidIsBannerAndSizesLengthMoreThanOne() throws JsonProcessingException { // given adapterRequest = AdapterRequest.of("bidderCode1", singletonList( givenAdUnitBid(builder -> builder .adUnitCode("adUnitCode1") .sizes(asList(Format.builder().w(100).h(200).build(), Format.builder().w(100).h(200).build())) .bidId("bidId1")))); given(adapter.extractBids(any(), any())) .willReturn(singletonList(org.prebid.server.proto.response.Bid.builder() .code("adUnitCode1") .bidId("bidId1") .mediaType(MediaType.banner))); givenHttpClientReturnsResponse(200, givenBidResponse(identity(), identity(), singletonList(identity()))); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getBids()).isEmpty(); assertThat(adapterResponse.getBidderStatus().getNumBids()).isEqualTo(0); }
Example 12
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldReturnAdapterResponseWithDebugIfFlagIsTrue() throws JsonProcessingException { // given preBidRequestContext = givenPreBidRequestContext(builder -> builder.isDebug(true), identity()); adapterRequest = AdapterRequest.of("bidderCode1", asList( givenAdUnitBid(builder -> builder.adUnitCode("adUnitCode1")), givenAdUnitBid(builder -> builder.adUnitCode("adUnitCode2")))); final String bidResponse = givenBidResponse(builder -> builder.id("bidResponseId1"), identity(), asList(bidBuilder -> bidBuilder.impid("adUnitCode1"), bidBuilder -> bidBuilder.impid("adUnitCode2"))); givenHttpClientReturnsResponse(200, bidResponse); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); final ArgumentCaptor<String> bidRequestCaptor = ArgumentCaptor.forClass(String.class); verify(httpClient).request(any(), anyString(), any(), bidRequestCaptor.capture(), anyLong()); final List<String> bidRequests = bidRequestCaptor.getAllValues(); assertThat(adapterResponse.getBidderStatus().getDebug()).hasSize(1).containsOnly( BidderDebug.builder() .requestUri("uri") .requestBody(bidRequests.get(0)) .responseBody(bidResponse) .statusCode(200) .build()); }
Example 13
Source File: AmqpAdapterClientCommandConsumerTest.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Verifies that the proton receiver is recreated after a reconnect. */ @Test public void testReceiverIsRecreatedOnConnectionFailure() { final AtomicReference<ReconnectListener<HonoConnection>> reconnectListener = new AtomicReference<>(); doAnswer(invocation -> { reconnectListener.set(invocation.getArgument(0)); return null; }).when(connection).addReconnectListener(any()); // GIVEN a connected command consumer @SuppressWarnings("unchecked") final Future<MessageConsumer> consumerFuture = AmqpAdapterClientCommandConsumer.create(connection, mock(BiConsumer.class)); final AmqpAdapterClientCommandConsumer commandConsumer = (AmqpAdapterClientCommandConsumer) consumerFuture .result(); // WHEN the connection is re-established final ProtonReceiver newReceiver = createNewProtonReceiver(connection); reconnectListener.get().onReconnect(null); // THEN the receiver is recreated verify(connection, times(2)).createReceiver( eq("command"), eq(ProtonQoS.AT_LEAST_ONCE), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler()); final ProtonReceiver actual = commandConsumer.getReceiver(); assertThat(actual).isNotEqualTo(originalReceiver); assertThat(actual).isEqualTo(newReceiver); }
Example 14
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldReturnAdapterResponseWithoutErrorIfBidsArePresentWhileHttpRequestForToleratedErrorsAdapter() throws JsonProcessingException { // given willReturn(asList(givenHttpRequest(), givenHttpRequest())).given(adapter).makeHttpRequests(any(), any()); given(adapter.tolerateErrors()).willReturn(true); final AdUnitBid adUnitBid = givenAdUnitBid(identity()); adapterRequest = AdapterRequest.of("bidderCode1", asList(adUnitBid, adUnitBid)); given(adapter.extractBids(any(), any())) .willReturn(singletonList(org.prebid.server.proto.response.Bid.builder())) .willReturn(null); final String bidResponse = givenBidResponse(identity(), identity(), singletonList(identity())); givenHttpClientReturnsResponses( HttpClientResponse.of(200, null, bidResponse), HttpClientResponse.of(503, null, "error response")); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isNull(); assertThat(adapterResponse.getBidderStatus().getError()).isNull(); assertThat(adapterResponse.getBids()).hasSize(1); }
Example 15
Source File: CacheServiceTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void cacheBidsVideoOnlyShouldReturnExpectedResult() { // given and when final Future<List<BidCacheResult>> future = cacheService.cacheBidsVideoOnly( singletonList(givenBid(builder -> builder.mediaType(MediaType.video))), timeout); // then final List<BidCacheResult> bidCacheResults = future.result(); assertThat(bidCacheResults).hasSize(1) .containsOnly(BidCacheResult.of("uuid1", "http://cache-service-host/cache?uuid=uuid1")); }
Example 16
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldSubmitTimeOutErrorToAdapterIfConnectTimeoutOccurs() { // given givenHttpClientProducesException(new ConnectTimeoutException()); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isEqualTo(BidderError.timeout("Timed out")); assertThat(adapterResponse.getBidderStatus().getError()).isEqualTo("Timed out"); }
Example 17
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldSubmitTimeOutErrorToAdapterIfTimeoutOccurs() { // given givenHttpClientProducesException(new TimeoutException()); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isEqualTo(BidderError.timeout("Timed out")); assertThat(adapterResponse.getBidderStatus().getError()).isEqualTo("Timed out"); }
Example 18
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldNotSubmitErrorToAdapterIfHttpResponseStatusCodeIs204() { // given givenHttpClientReturnsResponse(204, "response"); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()).isNull(); assertThat(adapterResponse.getBidderStatus().getError()).isNull(); assertThat(adapterResponse.getBids()).isEmpty(); }
Example 19
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldSubmitErrorToAdapterIfHttpResponseStatusCodeIsNot200Or204() { // given givenHttpClientReturnsResponse(503, "response"); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getError()) .isEqualTo(BidderError.badServerResponse("HTTP status 503; body: response")); assertThat(adapterResponse.getBidderStatus().getError()).isEqualTo("HTTP status 503; body: response"); }
Example 20
Source File: HttpAdapterConnectorTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void callShouldReturnGdprAwareAdapterResponseWithNoCookieIfNoAdapterUidInCookieAndNoAppInPreBidRequest() throws IOException { // given final Regs regs = Regs.of(0, mapper.valueToTree(ExtRegs.of(1, "1---"))); final User user = User.builder() .ext(mapper.valueToTree(ExtUser.builder().consent("consent$1").build())) .build(); preBidRequestContext = givenPreBidRequestContext(identity(), builder -> builder.regs(regs).user(user)); givenHttpClientReturnsResponse(200, givenBidResponse(identity(), identity(), singletonList(identity()))); usersyncer = new Usersyncer(null, "http://url?redir=%26gdpr%3D{{gdpr}}" + "%26gdpr_consent%3D{{gdpr_consent}}" + "%26us_privacy={{us_privacy}}", null, null, null, false); // when final Future<AdapterResponse> adapterResponseFuture = httpAdapterConnector.call(adapter, usersyncer, adapterRequest, preBidRequestContext); // then final AdapterResponse adapterResponse = adapterResponseFuture.result(); assertThat(adapterResponse.getBidderStatus().getNoCookie()).isTrue(); assertThat(adapterResponse.getBidderStatus().getUsersync()).isNotNull(); assertThat(adapterResponse.getBidderStatus().getUsersync()).isEqualTo(UsersyncInfo.of( "http://url?redir=%26gdpr%3D1%26gdpr_consent%3Dconsent%241%26us_privacy=1---", null, false)); }