-
Notifications
You must be signed in to change notification settings - Fork 12
Validations support 2 #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| package org.apache.solr.benchmarks; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| package org.apache.solr.benchmarks; | ||
| import java.util.List; | ||
| import java.util.ArrayList; | ||
| import java.util.Map; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.apache.solr.benchmarks.beans; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.util.Map; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.http.client.methods.CloseableHttpResponse; | ||
| import org.apache.solr.client.solrj.request.QueryRequest; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| // nocommit: javadocs | ||
| public class SolrBenchQueryResponse { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
|
||
| public String queryString; | ||
|
|
||
| public String responseString = null; | ||
|
|
||
| public NamedList<Object> rawResponse; | ||
|
|
||
| public boolean isSuccessfulResponse = false; | ||
|
|
||
| public SolrBenchQueryResponse (String queryString, NamedList<Object> response) { | ||
| this.rawResponse = response; | ||
| this.queryString = queryString; | ||
|
|
||
| InputStream responseStream = (InputStream) response.get("stream"); | ||
| try { | ||
| responseString = getResponseStreamAsString(responseStream); // should only call this once, as this reads the stream! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to make reading the stream lazy? My concern is that this always read the response stream, which seems unnecessary if the caller does not care about detailed stats nor needing any validations (which i assume is a common case for general benchmarking?) |
||
| } catch (IOException e) { | ||
| log.warn("Failed to read the response stream for " + queryString); | ||
| } | ||
|
|
||
| isSuccessfulResponse = isSuccessfulRsp(response.get("closeableResponse")); | ||
| } | ||
|
|
||
| private String getResponseStreamAsString(InputStream responseStream) throws IOException { | ||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| IOUtils.copy(responseStream, baos); | ||
|
|
||
| return new String(baos.toByteArray()); | ||
| } | ||
|
|
||
| private boolean isSuccessfulRsp(Object responseObj) { | ||
| if (responseObj instanceof CloseableHttpResponse) { | ||
| int statusCode = ((CloseableHttpResponse) responseObj).getStatusLine().getStatusCode(); | ||
| if (statusCode == 200) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have this class to avoid double reading the stream that triggers errors 💪🏼