2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.test.tool.client.http.perf;
10 import static org.opendaylight.netconf.test.tool.client.http.perf.RequestMessageUtils.formRequest;
12 import java.io.IOException;
13 import java.net.http.HttpClient;
14 import java.net.http.HttpResponse;
15 import java.net.http.HttpResponse.BodyHandlers;
16 import org.opendaylight.netconf.test.tool.client.stress.ExecutionStrategy;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class SyncExecutionStrategy implements ExecutionStrategy {
21 private static final Logger LOG = LoggerFactory.getLogger(SyncExecutionStrategy.class);
23 private final HttpClient httpClient;
24 private final RestPerfClient.RequestData payloads;
26 SyncExecutionStrategy(final HttpClient httpClient, final RestPerfClient.RequestData payloads) {
27 this.httpClient = httpClient;
28 this.payloads = payloads;
32 public void invoke() {
34 LOG.info("Begin sending sync requests");
35 for (int i = 0; i < payloads.getRequests(); i++) {
36 final String message = RequestMessageUtils.prepareMessage(payloads.getThreadId(), i,
37 payloads.getContentString(), payloads.getPort());
38 final HttpResponse<String> response;
40 response = httpClient.send(formRequest(payloads.getDestination(), message), BodyHandlers.ofString());
41 } catch (InterruptedException | IOException e) {
42 LOG.warn("Failed to execute request", e);
46 if (response.statusCode() != 200 && response.statusCode() != 204) {
47 LOG.warn("Status code: {}", response.statusCode());
48 LOG.warn("url: {}", response.uri());
49 LOG.warn("body: {}", response.body());
52 LOG.info("End sending sync requests");