mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2026-09-03 20:53:07 -05:00
recall compatibility
This commit is contained in:
@@ -41,6 +41,12 @@
|
|||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.15.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -16,18 +16,28 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.http.core;
|
package io.nosqlbench.adapter.http.core;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.nosqlbench.adapter.http.errors.InvalidResponseBodyException;
|
import io.nosqlbench.adapter.http.errors.InvalidResponseBodyException;
|
||||||
import io.nosqlbench.adapter.http.errors.InvalidStatusCodeException;
|
import io.nosqlbench.adapter.http.errors.InvalidStatusCodeException;
|
||||||
|
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
|
||||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
|
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.RunnableOp;
|
||||||
|
import org.apache.logging.log4j.core.tools.picocli.CommandLine;
|
||||||
|
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Spliterators;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
public class HttpOp implements RunnableOp {
|
public class HttpOp implements CycleOp {
|
||||||
|
|
||||||
public final Pattern ok_status;
|
public final Pattern ok_status;
|
||||||
public final Pattern ok_body;
|
public final Pattern ok_body;
|
||||||
@@ -46,15 +56,15 @@ public class HttpOp implements RunnableOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public Object apply(long value) {
|
||||||
HttpResponse.BodyHandler<String> bodyreader = HttpResponse.BodyHandlers.ofString();
|
HttpResponse.BodyHandler<String> bodyreader = HttpResponse.BodyHandlers.ofString();
|
||||||
HttpResponse<String> response = null;
|
HttpResponse<String> response = null;
|
||||||
Exception error = null;
|
Exception error = null;
|
||||||
long startat = System.nanoTime();
|
long startat = System.nanoTime();
|
||||||
try {
|
try {
|
||||||
CompletableFuture<HttpResponse<String>> responseFuture = client.sendAsync(request, bodyreader);
|
CompletableFuture<HttpResponse<String>> responseFuture = client.sendAsync(request, bodyreader);
|
||||||
response = responseFuture.get(space.getTimeoutMillis(), TimeUnit.MILLISECONDS);
|
response = responseFuture.get(space.getTimeoutMillis(), TimeUnit.MILLISECONDS);
|
||||||
space.getHttpMetrics().statusCodeHistogram.update(response.statusCode());
|
space.getHttpMetrics().statusCodeHistogram.update(response.statusCode());
|
||||||
|
|
||||||
if (ok_status != null) {
|
if (ok_status != null) {
|
||||||
if (!ok_status.matcher(String.valueOf(response.statusCode())).matches()) {
|
if (!ok_status.matcher(String.valueOf(response.statusCode())).matches()) {
|
||||||
@@ -84,6 +94,25 @@ public class HttpOp implements RunnableOp {
|
|||||||
throw new RuntimeException(error);
|
throw new RuntimeException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
JsonNode json = mapper.readTree(response.body());
|
||||||
|
|
||||||
|
Iterable<JsonNode> hits = json.get("hits").get("hits");
|
||||||
|
|
||||||
|
// get length from hits iterator
|
||||||
|
int count = (int)StreamSupport.stream(Spliterators.spliteratorUnknownSize(hits.iterator(), 0), false).count();
|
||||||
|
|
||||||
|
int[] keys = new int[count];
|
||||||
|
int i=0;
|
||||||
|
for (JsonNode hit : hits) {
|
||||||
|
keys[i]= hit.get("_source").get("key").asInt();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user