Search in sources :

Example 31 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class UserAgentEndpointChannelTest method testServiceNameIsNotValidConjureAgent.

@Test
public void testServiceNameIsNotValidConjureAgent() {
    EndpointChannel channel = UserAgentEndpointChannel.create(delegate, new Endpoint() {

        @Override
        public void renderPath(Map<String, String> _params, UrlBuilder _url) {
        }

        @Override
        public HttpMethod httpMethod() {
            return HttpMethod.GET;
        }

        @Override
        public String serviceName() {
            return "Service_Name";
        }

        @Override
        public String endpointName() {
            return "endpoint";
        }

        @Override
        public String version() {
            return "4.5.6";
        }
    }, baseAgent);
    // Special case: In IDEs, tests are run against classes (not JARs) and thus don't carry versions.
    String dialogueVersion = Optional.ofNullable(Channel.class.getPackage().getImplementationVersion()).orElse("0.0.0");
    channel.execute(request);
    verify(delegate).execute(requestCaptor.capture());
    assertThat(requestCaptor.getValue().headerParams().get("user-agent")).containsExactly("test-class/1.2.3 dialogue/" + dialogueVersion);
}
Also used : TestEndpoint(com.palantir.dialogue.TestEndpoint) Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) EndpointChannel(com.palantir.dialogue.EndpointChannel) EndpointChannel(com.palantir.dialogue.EndpointChannel) UrlBuilder(com.palantir.dialogue.UrlBuilder) HttpMethod(com.palantir.dialogue.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 32 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class SimulationTest method server_side_rate_limits_with_sticky_clients_steady_vs_bursty_client.

@SimulationCase
void server_side_rate_limits_with_sticky_clients_steady_vs_bursty_client(Strategy strategy) {
    // 1 server
    // 2 types of clients sharing a DialogueChannel
    // - client that sends a request once a second
    // - client that burst sends 10k requests instantly
    // Assuming:
    // * server concurrency limit of 1
    // * 5ms to serve a request
    // 
    // Serving the bursty client by itself would take 50s. That is fine for that client, because it
    // is trying to do a lot. However, we should not make the slow-and-steady client wait 50s to send it's request.
    int numServers = 1;
    int concurrencyLimit = 1;
    Duration responseTime = Duration.ofMillis(5);
    Duration benchmarkDuration = Duration.ofMinutes(1);
    Duration timeBetweenSlowAndSteadyRequests = Duration.ofSeconds(1);
    long numSlowAndSteady = benchmarkDuration.toNanos() / timeBetweenSlowAndSteadyRequests.toNanos();
    assertThat(numSlowAndSteady).isEqualTo(60);
    Duration timeBetweenBurstRequests = Duration.ofNanos(50);
    long numBurst = 10_000;
    long totalNumRequests = numSlowAndSteady + numBurst;
    assertThat(totalNumRequests).isEqualTo(10060);
    servers = servers(IntStream.range(0, numServers).mapToObj(i -> SimulationServer.builder().serverName("node" + i).simulation(simulation).handler(h -> h.respond200UntilCapacity(429, concurrencyLimit).responseTime(responseTime)).build()).toArray(SimulationServer[]::new));
    Supplier<Channel> stickyChannelSupplier = strategy.getSticky2NonReloading(simulation, servers.get());
    Benchmark builder = Benchmark.builder().simulation(simulation);
    EndpointChannel slowAndSteadyChannel = builder.addEndpointChannel("slowAndSteady", DEFAULT_ENDPOINT, stickyChannelSupplier.get());
    EndpointChannel oneShotBurstChannel = builder.addEndpointChannel("oneShotBurst", DEFAULT_ENDPOINT, stickyChannelSupplier.get());
    Stream<ScheduledRequest> slowAndSteadyChannelRequests = builder.infiniteRequests(timeBetweenSlowAndSteadyRequests, () -> slowAndSteadyChannel).limit(numSlowAndSteady);
    Stream<ScheduledRequest> oneShotBurstChannelRequests = builder.infiniteRequests(timeBetweenBurstRequests, () -> oneShotBurstChannel).limit(numBurst);
    st = strategy;
    result = builder.mergeRequestStreams(slowAndSteadyChannelRequests, oneShotBurstChannelRequests).stopWhenNumReceived(totalNumRequests).abortAfter(benchmarkDuration.plus(Duration.ofMinutes(1))).run();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inherited(java.lang.annotation.Inherited) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) AfterAll(org.junit.jupiter.api.AfterAll) Duration(java.time.Duration) Map(java.util.Map) Tracers(com.palantir.tracing.Tracers) Path(java.nio.file.Path) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) StandardOpenOption(java.nio.file.StandardOpenOption) Channel(com.palantir.dialogue.Channel) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) TestResponse(com.palantir.dialogue.TestResponse) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Response(com.palantir.dialogue.Response) IntStream(java.util.stream.IntStream) Tracer(com.palantir.tracing.Tracer) Stopwatch(com.google.common.base.Stopwatch) EnumSource(org.junit.jupiter.params.provider.EnumSource) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) Meter(com.codahale.metrics.Meter) ScheduledRequest(com.palantir.dialogue.core.Benchmark.ScheduledRequest) Suppliers(com.google.common.base.Suppliers) Endpoint(com.palantir.dialogue.Endpoint) DEFAULT_ENDPOINT(com.palantir.dialogue.core.Benchmark.DEFAULT_ENDPOINT) Logger(org.slf4j.Logger) Files(java.nio.file.Files) XYChart(org.knowm.xchart.XYChart) Observability(com.palantir.tracing.Observability) IOException(java.io.IOException) HttpMethod(com.palantir.dialogue.HttpMethod) TimeUnit(java.util.concurrent.TimeUnit) EndpointChannel(com.palantir.dialogue.EndpointChannel) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ChronoUnit(java.time.temporal.ChronoUnit) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) Execution(org.junit.jupiter.api.parallel.Execution) RetentionPolicy(java.lang.annotation.RetentionPolicy) ScheduledRequest(com.palantir.dialogue.core.Benchmark.ScheduledRequest) Channel(com.palantir.dialogue.Channel) EndpointChannel(com.palantir.dialogue.EndpointChannel) Duration(java.time.Duration) EndpointChannel(com.palantir.dialogue.EndpointChannel) Endpoint(com.palantir.dialogue.Endpoint)

Aggregations

EndpointChannel (com.palantir.dialogue.EndpointChannel)32 Test (org.junit.jupiter.api.Test)28 Response (com.palantir.dialogue.Response)25 TestResponse (com.palantir.dialogue.TestResponse)25 Endpoint (com.palantir.dialogue.Endpoint)6 HttpMethod (com.palantir.dialogue.HttpMethod)4 Request (com.palantir.dialogue.Request)4 Channel (com.palantir.dialogue.Channel)3 RequestBody (com.palantir.dialogue.RequestBody)3 TestEndpoint (com.palantir.dialogue.TestEndpoint)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ByteStreams (com.google.common.io.ByteStreams)2 Futures (com.google.common.util.concurrent.Futures)2 SafeLong (com.palantir.conjure.java.lib.SafeLong)2 ClientEndpoint (com.palantir.conjure.java.lib.internal.ClientEndpoint)2