mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-20 11:38:28 -06:00
recall compatibility
This commit is contained in:
parent
56bdd11a5e
commit
0092cb754c
@ -41,6 +41,12 @@
|
||||
<version>${revision}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.15.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -16,18 +16,28 @@
|
||||
|
||||
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.InvalidStatusCodeException;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
|
||||
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.HttpRequest;
|
||||
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.TimeUnit;
|
||||
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_body;
|
||||
@ -46,15 +56,15 @@ public class HttpOp implements RunnableOp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public Object apply(long value) {
|
||||
HttpResponse.BodyHandler<String> bodyreader = HttpResponse.BodyHandlers.ofString();
|
||||
HttpResponse<String> response = null;
|
||||
Exception error = null;
|
||||
long startat = System.nanoTime();
|
||||
try {
|
||||
CompletableFuture<HttpResponse<String>> responseFuture = client.sendAsync(request, bodyreader);
|
||||
response = responseFuture.get(space.getTimeoutMillis(), TimeUnit.MILLISECONDS);
|
||||
space.getHttpMetrics().statusCodeHistogram.update(response.statusCode());
|
||||
response = responseFuture.get(space.getTimeoutMillis(), TimeUnit.MILLISECONDS);
|
||||
space.getHttpMetrics().statusCodeHistogram.update(response.statusCode());
|
||||
|
||||
if (ok_status != null) {
|
||||
if (!ok_status.matcher(String.valueOf(response.statusCode())).matches()) {
|
||||
@ -84,6 +94,25 @@ public class HttpOp implements RunnableOp {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user