Search in sources :

Example 1 with ExecutorException

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

the class JulMdcTest 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)

Example 2 with ExecutorException

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

the class Log4jMdcTest 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 : ThreadContext(org.apache.logging.log4j.ThreadContext) 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)

Example 3 with ExecutorException

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

the class Slf4jMdcTest method testThreadPropagationWithEmptyMdc.

@Test
public void testThreadPropagationWithEmptyMdc() {
    Context context = Context.create();
    ExecutorService executor = Contexts.wrap(Executors.newFixedThreadPool(1));
    Contexts.runInContext(context, () -> {
        try {
            Boolean value = executor.submit(new TestEmptyMdc()).get();
            assertThat(value, is(true));
        } 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)

Example 4 with ExecutorException

use of io.helidon.common.context.ExecutorException 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)4 ExecutorException (io.helidon.common.context.ExecutorException)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.junit.jupiter.api.Test)4 ThreadContext (org.apache.logging.log4j.ThreadContext)1