Search in sources :

Example 31 with Context

use of io.helidon.common.context.Context in project helidon by oracle.

the class WebClientService method testFollowRedirect.

public void testFollowRedirect(Context ctx) {
    client.get().path("/wc/redirect").followRedirects(true).context(ctx).request(Animal.class).thenAccept(animal -> assertTrue(animal, a -> "Frank".equals(a.getName()))).await(15, TimeUnit.SECONDS);
    WebClientResponse response = client.get().path("/wc/redirect").followRedirects(false).context(ctx).request().await(15, TimeUnit.SECONDS);
    assertEquals(response.status(), Http.Status.MOVED_PERMANENTLY_301);
}
Also used : PrintWriter(java.io.PrintWriter) WebClientException(io.helidon.webclient.WebClientException) JsonbSupport(io.helidon.media.jsonb.JsonbSupport) WebClient(io.helidon.webclient.WebClient) JsonValue(jakarta.json.JsonValue) Config(io.helidon.config.Config) WebClientResponse(io.helidon.webclient.WebClientResponse) Predicate(java.util.function.Predicate) StringWriter(java.io.StringWriter) Context(io.helidon.common.context.Context) CompletableFuture(java.util.concurrent.CompletableFuture) Logger(java.util.logging.Logger) MediaType(io.helidon.common.http.MediaType) ServerRequest(io.helidon.webserver.ServerRequest) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) CompletionStage(java.util.concurrent.CompletionStage) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) Service(io.helidon.webserver.Service) Http(io.helidon.common.http.Http) Routing(io.helidon.webserver.Routing) WebClientResponse(io.helidon.webclient.WebClientResponse)

Example 32 with Context

use of io.helidon.common.context.Context in project helidon by oracle.

the class Slf4jMdcTest method testThreadPropagation.

@Test
public void testThreadPropagation() {
    HelidonMdc.set(TEST_KEY, TEST_VALUE);
    Context context = Context.create();
    ExecutorService executor = Contexts.wrap(Executors.newFixedThreadPool(1));
    Contexts.runInContext(context, () -> {
        try {
            String value = executor.submit(new TestCallable()).get();
            assertThat(value, is(TEST_VALUE));
        } catch (Exception e) {
            throw new ExecutorException("failed to execute", e);
        }
    });
}
Also used : Context(io.helidon.common.context.Context) ExecutorException(io.helidon.common.context.ExecutorException) ExecutorService(java.util.concurrent.ExecutorService) ExecutorException(io.helidon.common.context.ExecutorException) Test(org.junit.jupiter.api.Test)

Aggregations

Context (io.helidon.common.context.Context)32 Test (org.junit.jupiter.api.Test)14 Contexts (io.helidon.common.context.Contexts)8 WebClient (io.helidon.webclient.WebClient)8 Optional (java.util.Optional)7 Http (io.helidon.common.http.Http)6 Single (io.helidon.common.reactive.Single)6 Config (io.helidon.config.Config)6 ServerRequest (io.helidon.webserver.ServerRequest)6 SpanContext (io.opentracing.SpanContext)6 Logger (java.util.logging.Logger)6 HttpRequest (io.helidon.common.http.HttpRequest)5 SecurityContext (io.helidon.security.SecurityContext)5 ServerResponse (io.helidon.webserver.ServerResponse)5 List (java.util.List)5 Map (java.util.Map)5 WebClientResponse (io.helidon.webclient.WebClientResponse)4 Span (io.opentracing.Span)4 Tracer (io.opentracing.Tracer)4 Collections (java.util.Collections)4