use of com.palantir.dialogue.Endpoint in project conjure-java-runtime by palantir.
the class JaxRsClientDialogueEndpointTest method testPostWithBody.
@Test
public void testPostWithBody() {
Channel channel = stubNoContentResponseChannel();
StubService service = JaxRsClient.create(StubService.class, channel, runtime);
service.post("Hello, World!");
ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
Endpoint endpoint = endpointCaptor.getValue();
assertThat(endpoint.serviceName()).isEqualTo("StubService");
assertThat(endpoint.endpointName()).isEqualTo("post");
assertThat(endpoint.httpMethod()).isEqualTo(HttpMethod.POST);
Request request = requestCaptor.getValue();
assertThat(request.body()).isPresent();
assertThat(request.body().get().contentType()).isEqualTo("text/plain");
assertThat(request.headerParams().asMap()).containsExactly(new AbstractMap.SimpleImmutableEntry<>("Accept", ImmutableList.of("application/json")), new AbstractMap.SimpleImmutableEntry<>("Content-Length", ImmutableList.of("13")));
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class SimulationServer method execute.
@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
Meter perEndpointRequests = MetricNames.requestMeter(simulation.taggedMetrics(), serverName, endpoint);
activeRequests.inc();
perEndpointRequests.mark();
simulation.metricsReporter().report();
for (ServerHandler handler : handlers) {
long beforeNanos = simulation.clock().read();
Optional<ListenableFuture<Response>> maybeResp = handler.maybeExecute(this, endpoint, request);
if (!maybeResp.isPresent()) {
continue;
}
ListenableFuture<Response> resp = maybeResp.get();
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(_ignored -> globalResponses.inc()));
resp.addListener(() -> {
activeRequests.dec();
globalServerTimeNanos.inc(simulation.clock().read() - beforeNanos);
}, DialogueFutures.safeDirectExecutor());
if (log.isDebugEnabled()) {
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(result -> {
log.debug("time={} server={} status={} id={}", Duration.ofNanos(simulation.clock().read()), serverName, result.code(), request != null ? request.headerParams().get(Benchmark.REQUEST_ID_HEADER) : null);
}));
}
return resp;
}
log.error("No handler available for request {}", request);
activeRequests.dec();
return Futures.immediateFailedFuture(new SafeRuntimeException("No handler"));
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class SimulationTest method one_endpoint_dies_on_each_server.
@SimulationCase
public void one_endpoint_dies_on_each_server(Strategy strategy) {
Endpoint endpoint1 = SimulationUtils.endpoint("e1", HttpMethod.POST);
Endpoint endpoint2 = SimulationUtils.endpoint("e2", HttpMethod.POST);
servers = servers(SimulationServer.builder().serverName("server_where_e1_breaks").simulation(simulation).handler(endpoint1, h -> h.response(200).responseTime(Duration.ofMillis(600))).handler(endpoint2, h -> h.response(200).responseTime(Duration.ofMillis(600))).until(Duration.ofSeconds(3), "e1 breaks").handler(endpoint1, h -> h.response(500).responseTime(Duration.ofMillis(600))).handler(endpoint2, h -> h.response(200).responseTime(Duration.ofMillis(600))).build(), SimulationServer.builder().serverName("server_where_e2_breaks").simulation(simulation).handler(endpoint1, h -> h.response(200).responseTime(Duration.ofMillis(600))).handler(endpoint2, h -> h.response(200).responseTime(Duration.ofMillis(600))).until(Duration.ofSeconds(3), "e2 breaks").handler(endpoint1, h -> h.response(200).responseTime(Duration.ofMillis(600))).handler(endpoint2, h -> h.response(500).responseTime(Duration.ofMillis(600))).build());
st = strategy;
result = Benchmark.builder().simulation(simulation).requestsPerSecond(250).sendUntil(Duration.ofSeconds(10)).abortAfter(Duration.ofMinutes(1)).clients(10, _i -> strategy.getChannel(simulation, servers)).endpoints(endpoint1, endpoint2).abortAfter(Duration.ofMinutes(10)).run();
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class Benchmark method endpoints.
public Benchmark endpoints(Endpoint... endpoints) {
Preconditions.checkNotNull(clients, "Must call client or clients first");
Preconditions.checkNotNull(requestStream, "Must call sendUntil or numRequests first");
Preconditions.checkNotNull(simulation, "Must call .simulation() first");
endpointChannels = new ArrayList<>();
Arrays.stream(clients).forEach(client -> Arrays.stream(endpoints).forEach(endpoint -> addEndpointChannel(client.name(), endpoint, client.channel())));
Random pseudoRandom = new Random(21876781263L);
int count = endpointChannels.size();
endpointChannelChooser = () -> pseudoRandom.nextInt(count);
return this;
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class BalancedNodeSelectionStrategyChannelTest method constant_4xxs_do_eventually_move_the_needle_but_we_go_back_to_fair_distribution.
@Test
void constant_4xxs_do_eventually_move_the_needle_but_we_go_back_to_fair_distribution() {
when(chan1.maybeExecute(any(), any(), eq(LimitEnforcement.DEFAULT_ENABLED))).thenReturn(http(400));
when(chan2.maybeExecute(any(), any(), eq(LimitEnforcement.DEFAULT_ENABLED))).thenReturn(http(200));
for (int i = 0; i < 11; i++) {
rttChannel.maybeExecute(endpoint, request, LimitEnforcement.DEFAULT_ENABLED);
assertThat(rttChannel.getScoresForTesting()).describedAs("%s %s: Scores not affected yet %s", i, Duration.ofNanos(clock.read()), rttChannel).containsExactly(0, 0);
incrementClockBy(Duration.ofMillis(50));
}
rttChannel.maybeExecute(endpoint, request, LimitEnforcement.DEFAULT_ENABLED);
assertThat(rttChannel.getScoresForTesting()).describedAs("%s: Constant 4xxs did move the needle %s", Duration.ofNanos(clock.read()), rttChannel).containsExactly(1, 0);
incrementClockBy(Duration.ofSeconds(5));
assertThat(rttChannel.getScoresForTesting()).describedAs("%s: We quickly forget about 4xxs and go back to fair shuffling %s", Duration.ofNanos(clock.read()), rttChannel).containsExactly(0, 0);
}
Aggregations