misc code cleanups

This commit is contained in:
Jonathan Shook 2020-12-02 14:18:59 -06:00
parent ff6492763d
commit 0b03da159c
2 changed files with 8 additions and 111 deletions

View File

@ -7,11 +7,10 @@ import io.nosqlbench.engine.api.activityapi.core.SyncAction;
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
import io.nosqlbench.nb.api.errors.BasicError;
import io.nosqlbench.virtdata.core.templates.StringBindings;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.io.FileNotFoundException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@ -28,14 +27,11 @@ public class HttpAction implements SyncAction {
private final HttpActivity httpActivity;
private final int slot;
private final int maxTries = 1;
private boolean showstmts;
private OpSequence<ReadyHttpOp> sequencer;
private HttpClient client;
private final HttpResponse.BodyHandler<String> bodyreader = HttpResponse.BodyHandlers.ofString();
private final long timeoutMillis=30000L;
public HttpAction(ActivityDef activityDef, int slot, HttpActivity httpActivity) {
this.slot = slot;
@ -54,25 +50,15 @@ public class HttpAction implements SyncAction {
@Override
public int runCycle(long cycleValue) {
StringBindings stringBindings;
String statement = null;
InputStream result = null;
// The request to be used must be constructed from the template each time.
HttpOp httpOp = null;
// The bind timer captures all the time involved in preparing the
// operation for execution, including data generation as well as
// op construction
// The request to be used must be constructed from the template each time.
HttpOp httpOp=null;
// A specifier for what makes a response ok. If this is provided, then it is
// either a list of valid http status codes, or if non-numeric, a regex for the body
// which must match.
// If not provided, then status code 200 is the only thing required to be matched.
String ok;
try (Timer.Context bindTime = httpActivity.bindTimer.time()) {
ReadyHttpOp readHTTPOperation = httpActivity.getSequencer().get(cycleValue);
ReadyHttpOp readHTTPOperation = sequencer.get(cycleValue);
httpOp = readHTTPOperation.apply(cycleValue);
} catch (Exception e) {
if (httpActivity.isDiagnosticMode()) {
@ -135,98 +121,10 @@ public class HttpAction implements SyncAction {
}
}
// if (ok == null) {
// if (response.statusCode() != 200) {
// throw new ResponseError("Result had status code " +
// response.statusCode() + ", but 'ok' was not set for this statement," +
// "so it is considered an error.");
// }
// } else {
// String[] oks = ok.split(",");
// for (String ok_condition : oks) {
// if (ok_condition.charAt(0)>='0' && ok_condition.charAt(0)<='9') {
// int matching_status = Integer.parseInt(ok_condition);
// } else {
// Pattern successRegex = Pattern.compile(ok);
// }
// }
//// Matcher matcher = successRegex.matcher(String.valueOf(response.statusCode()));
//// if (!matcher.matches()) {
//// throw new BasicError("status code " + response.statusCode() + " did not match " + success);
//// }
// }
}
return 0;
}
// String body = future.body();
// String[] splitStatement = statement.split("\\?");
// String path, query;
//
// path = splitStatement[0];
// query = "";
//
// if (splitStatement.length >= 2) {
// query = splitStatement[1];
// }
//
// URI uri = new URI(
// "http",
// null,
// host,
// httpActivity.getPort(),
// path,
// query,
// null);
//
// statement = uri.toString();
//
// showstmts = httpActivity.getShowstmts();
// if (showstmts) {
// logger.info("STMT(cycle=" + cycleValue + "):\n" + statement);
// }
// } catch (URISyntaxException e) {
// e.printStackTrace();
// }
//
// long nanoStartTime=System.nanoTime();
//
// Timer.Context resultTime = httpActivity.resultTimer.time();
// try {
// StringBuilder res = new StringBuilder();
//
// BufferedReader rd = new BufferedReader(new InputStreamReader(result));
// String line;
// while ((line = rd.readLine()) != null) {
// res.append(line);
// }
// rd.close();
//
// } catch (Exception e) {
// long resultNanos = resultTime.stop();
// resultTime = null;
// } finally {
// if (resultTime != null) {
// resultTime.stop();
// }
//
// }
//
// }
// long resultNanos = System.nanoTime() - nanoStartTime;
// httpActivity.resultSuccessTimer.update(resultNanos, TimeUnit.NANOSECONDS);
// protected HttpActivity getHttpActivity () {
// return httpActivity;
// }
// }
private HttpRequest.BodyPublisher bodySourceFrom(Map<String, String> cmdMap) {
if (cmdMap.containsKey("body")) {
String body = cmdMap.remove("body");

View File

@ -13,10 +13,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<javadoc.name>nosqlbench</javadoc.name>
<java.target.version>11</java.target.version>
<!-- <java.target.version>11</java.target.version>-->
<!-- properties for package versions -->
<antlr4.version>4.8</antlr4.version>
<ascii.data.version>1.2.0</ascii.data.version>
<commons.codec.version>1.14</commons.codec.version>
<commons.compress.version>1.20</commons.compress.version>
@ -325,7 +324,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr4.version}</version>
<version>4.8</version>
</dependency>
<dependency>