Search in sources :

Example 1 with AliasOfOptional

use of com.palantir.dialogue.example.AliasOfOptional in project dialogue by palantir.

the class IntegrationTest method alias_of_optional.

@Test
public void alias_of_optional() {
    set204Response();
    AliasOfOptional myAlias = blocking.getMyAlias();
    Optional<String> maybeString = myAlias.get();
    assertThat(maybeString).isNotPresent();
}
Also used : AliasOfOptional(com.palantir.dialogue.example.AliasOfOptional) AliasOfAliasOfOptional(com.palantir.dialogue.example.AliasOfAliasOfOptional) Test(org.junit.jupiter.api.Test)

Example 2 with AliasOfOptional

use of com.palantir.dialogue.example.AliasOfOptional in project dialogue by palantir.

the class IntegrationTest method when_thread_is_interrupted_no_requests_are_made.

@Test
public void when_thread_is_interrupted_no_requests_are_made() {
    AtomicInteger served = new AtomicInteger();
    undertowHandler = exchange -> {
        served.getAndIncrement();
        exchange.setStatusCode(204);
    };
    Thread.currentThread().interrupt();
    assertThatThrownBy(blocking::getMyAlias).satisfies(throwable -> assertThat(throwable.getClass().getSimpleName()).isEqualTo("DialogueException")).hasCauseInstanceOf(InterruptedException.class);
    ListenableFuture<AliasOfOptional> future = async.getMyAlias();
    assertThat(future).isDone();
    assertThat(future).isNotCancelled();
    assertThatThrownBy(future::get).isInstanceOf(InterruptedException.class);
    assertThat(served).hasValue(0);
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) Iterables(com.google.common.collect.Iterables) AliasOfOptional(com.palantir.dialogue.example.AliasOfOptional) Arrays(java.util.Arrays) AliasOfAliasOfOptional(com.palantir.dialogue.example.AliasOfAliasOfOptional) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Stopwatch(com.google.common.base.Stopwatch) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SslConfiguration(com.palantir.conjure.java.api.config.ssl.SslConfiguration) RateLimiter(com.google.common.util.concurrent.RateLimiter) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Undertow(io.undertow.Undertow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ByteArrayInputStream(java.io.ByteArrayInputStream) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) Refreshable(com.palantir.refreshable.Refreshable) BlockingHandler(io.undertow.server.handlers.BlockingHandler) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) IOException(java.io.IOException) Ints(com.google.common.primitives.Ints) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) HttpHandler(io.undertow.server.HttpHandler) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) Headers(io.undertow.util.Headers) Optional(java.util.Optional) GZIPOutputStream(java.util.zip.GZIPOutputStream) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Preconditions(com.palantir.logsafe.Preconditions) InputStream(java.io.InputStream) AliasOfOptional(com.palantir.dialogue.example.AliasOfOptional) AliasOfAliasOfOptional(com.palantir.dialogue.example.AliasOfAliasOfOptional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 3 with AliasOfOptional

use of com.palantir.dialogue.example.AliasOfOptional in project dialogue by palantir.

the class IntegrationTest method testClosedConnectionIsRetried.

@Test
public void testClosedConnectionIsRetried() {
    AtomicInteger requests = new AtomicInteger();
    undertowHandler = exchange -> {
        if (requests.getAndIncrement() == 0) {
            exchange.getConnection().close();
        } else {
            exchange.setStatusCode(204);
        }
    };
    AliasOfOptional myAlias = blocking.getMyAlias();
    Optional<String> maybeString = myAlias.get();
    assertThat(maybeString).isNotPresent();
    assertThat(requests).hasValue(2);
}
Also used : AliasOfOptional(com.palantir.dialogue.example.AliasOfOptional) AliasOfAliasOfOptional(com.palantir.dialogue.example.AliasOfAliasOfOptional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Aggregations

AliasOfAliasOfOptional (com.palantir.dialogue.example.AliasOfAliasOfOptional)3 AliasOfOptional (com.palantir.dialogue.example.AliasOfOptional)3 Test (org.junit.jupiter.api.Test)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Stopwatch (com.google.common.base.Stopwatch)1 Iterables (com.google.common.collect.Iterables)1 ByteStreams (com.google.common.io.ByteStreams)1 Ints (com.google.common.primitives.Ints)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)1 ServicesConfigBlock (com.palantir.conjure.java.api.config.service.ServicesConfigBlock)1 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)1 SslConfiguration (com.palantir.conjure.java.api.config.ssl.SslConfiguration)1 DialogueClients (com.palantir.dialogue.clients.DialogueClients)1 ReloadingFactory (com.palantir.dialogue.clients.DialogueClients.ReloadingFactory)1 SampleServiceAsync (com.palantir.dialogue.example.SampleServiceAsync)1 SampleServiceBlocking (com.palantir.dialogue.example.SampleServiceBlocking)1 Preconditions (com.palantir.logsafe.Preconditions)1