Search in sources :

Example 1 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RequestTrackerTest method droppedAfterExpiration.

@Test
public void droppedAfterExpiration() {
    Request requestMessage = Request.forUri("http://service/path");
    OngoingRequest ongoingRequest = mock(OngoingRequest.class);
    when(ongoingRequest.request()).thenReturn(requestMessage);
    when(ongoingRequest.isExpired()).thenReturn(true);
    new TrackedOngoingRequestImpl(ongoingRequest, tracker);
    tracker.reap();
    verify(ongoingRequest).drop();
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 2 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RequestTrackerTest method shouldFailRequestsWhenClosed.

@Test
public void shouldFailRequestsWhenClosed() throws Exception {
    Request requestMessage = Request.forUri("http://service/path");
    TrackedOngoingRequest ongoingRequest = mock(TrackedOngoingRequest.class);
    when(ongoingRequest.request()).thenReturn(requestMessage);
    when(ongoingRequest.isExpired()).thenReturn(false);
    tracker.register(ongoingRequest);
    tracker.close();
    verify(ongoingRequest).reply(argThat(hasStatus(Status.SERVICE_UNAVAILABLE)));
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 3 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RouteEndpointTest method setUp.

@Before
public void setUp() throws Exception {
    pathArgs = ImmutableMap.of("arg", "one", "and", "value2");
    request = mock(Request.class);
    // noinspection unchecked
    syncEndpointHandler = mock(SyncHandler.class);
    // noinspection unchecked
    asyncHandler = mock(AsyncHandler.class);
    Request request = Request.forUri("http://foo");
    requestContext = RequestContexts.create(request, mock(Client.class), pathArgs, 0L, RequestMetadataImpl.create(Instant.EPOCH, Optional.empty(), Optional.empty()));
    theData = ByteString.encodeUtf8("theString");
    response = Response.forPayload(theData);
}
Also used : Request(com.spotify.apollo.Request) Before(org.junit.Before)

Example 4 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RouteRuleBuilderTest method shouldCreateRule.

@Theory
public void shouldCreateRule(String method) throws Exception {
    RouteProvider provider = () -> Stream.of(Route.sync(method, "/test/<arg>", newHandler1("foo")));
    Request request = request(method, "/test/" + "bar");
    ApplicationRouter<Endpoint> router = Routers.newRouterFromInspecting(provider);
    assertRequestResponse(router, "foo", "bar", request);
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) Request(com.spotify.apollo.Request) Theory(org.junit.experimental.theories.Theory)

Example 5 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class EndpointInvocationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    handler = new EndpointInvocationHandler();
    Request requestMessage = Request.forUri("http://foo/bar").withService("nameless-registry");
    when(ongoingRequest.request()).thenReturn(requestMessage);
    when(requestContext.request()).thenReturn(requestMessage);
    future = new CompletableFuture<>();
}
Also used : Request(com.spotify.apollo.Request) OngoingRequest(com.spotify.apollo.request.OngoingRequest) Before(org.junit.Before)

Aggregations

Request (com.spotify.apollo.Request)33 Test (org.junit.Test)21 ByteString (okio.ByteString)14 Client (com.spotify.apollo.Client)3 Response (com.spotify.apollo.Response)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 RequestContext (com.spotify.apollo.RequestContext)2 Album (com.spotify.apollo.example.data.Album)2 Artist (com.spotify.apollo.example.data.Artist)2 AsyncHandler (com.spotify.apollo.route.AsyncHandler)2 JsonSerializerMiddlewares (com.spotify.apollo.route.JsonSerializerMiddlewares)2 Route (com.spotify.apollo.route.Route)2 ArrayList (java.util.ArrayList)2 CompletionStage (java.util.concurrent.CompletionStage)2 Stream (java.util.stream.Stream)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1