use of org.apache.http.client.methods.HttpPost in project pinot by linkedin.
the class PinotResponseTime method main.
public static void main(String[] args) throws Exception {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPost post = new HttpPost("http://localhost:8099/query");
CloseableHttpResponse res;
if (STORE_RESULT) {
File dir = new File(RESULT_DIR);
if (!dir.exists()) {
dir.mkdirs();
}
}
int length;
// Make sure all segments online
System.out.println("Test if number of records is " + RECORD_NUMBER);
post.setEntity(new StringEntity("{\"pql\":\"select count(*) from tpch_lineitem\"}"));
while (true) {
System.out.print('*');
res = client.execute(post);
boolean valid;
try (BufferedInputStream in = new BufferedInputStream(res.getEntity().getContent())) {
length = in.read(BUFFER);
valid = new String(BUFFER, 0, length, "UTF-8").contains("\"value\":\"" + RECORD_NUMBER + "\"");
}
res.close();
if (valid) {
break;
} else {
Thread.sleep(5000);
}
}
System.out.println("Number of Records Test Passed");
// Start Benchmark
for (int i = 0; i < QUERIES.length; i++) {
System.out.println("--------------------------------------------------------------------------------");
System.out.println("Start running query: " + QUERIES[i]);
post.setEntity(new StringEntity("{\"pql\":\"" + QUERIES[i] + "\"}"));
// Warm-up Rounds
System.out.println("Run " + WARMUP_ROUND + " times to warm up cache...");
for (int j = 0; j < WARMUP_ROUND; j++) {
res = client.execute(post);
if (!isValid(res, null)) {
System.out.println("\nInvalid Response, Sleep 20 Seconds...");
Thread.sleep(20000);
}
res.close();
System.out.print('*');
}
System.out.println();
// Test Rounds
int[] time = new int[TEST_ROUND];
int totalTime = 0;
int validIdx = 0;
System.out.println("Run " + TEST_ROUND + " times to get average time...");
while (validIdx < TEST_ROUND) {
long startTime = System.currentTimeMillis();
res = client.execute(post);
long endTime = System.currentTimeMillis();
boolean valid;
if (STORE_RESULT && validIdx == 0) {
valid = isValid(res, RESULT_DIR + File.separator + i + ".json");
} else {
valid = isValid(res, null);
}
if (!valid) {
System.out.println("\nInvalid Response, Sleep 20 Seconds...");
Thread.sleep(20000);
res.close();
continue;
}
res.close();
time[validIdx] = (int) (endTime - startTime);
totalTime += time[validIdx];
System.out.print(time[validIdx] + "ms ");
validIdx++;
}
System.out.println();
// Process Results
double avgTime = (double) totalTime / TEST_ROUND;
double stdDev = 0;
for (int temp : time) {
stdDev += (temp - avgTime) * (temp - avgTime) / TEST_ROUND;
}
stdDev = Math.sqrt(stdDev);
System.out.println("The average response time for the query is: " + avgTime + "ms");
System.out.println("The standard deviation is: " + stdDev);
}
}
}
use of org.apache.http.client.methods.HttpPost in project pinpoint by naver.
the class HttpClientIT method test.
@Test
public void test() throws Exception {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost post = new HttpPost("http://www.naver.com");
post.addHeader("Content-Type", "application/json;charset=UTF-8");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
httpClient.execute(post, responseHandler);
} catch (Exception ignored) {
} finally {
if (null != httpClient && null != httpClient.getConnectionManager()) {
httpClient.getConnectionManager().shutdown();
}
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
Class<?> connectorClass;
try {
connectorClass = Class.forName("org.apache.http.impl.conn.ManagedClientConnectionImpl");
} catch (ClassNotFoundException e) {
connectorClass = Class.forName("org.apache.http.impl.conn.AbstractPooledConnAdapter");
}
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", AbstractHttpClient.class.getMethod("execute", HttpUriRequest.class, ResponseHandler.class)));
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", connectorClass.getMethod("open", HttpRoute.class, HttpContext.class, HttpParams.class), annotation("http.internal.display", "www.naver.com")));
verifier.verifyTrace(event("HTTP_CLIENT_4", HttpRequestExecutor.class.getMethod("execute", HttpRequest.class, HttpClientConnection.class, HttpContext.class), null, null, "www.naver.com", annotation("http.url", "/"), annotation("http.status.code", 200), annotation("http.io", anyAnnotationValue())));
verifier.verifyTraceCount(0);
}
use of org.apache.http.client.methods.HttpPost in project android-uploader by nightscout.
the class AbstractRestUploaderTest method testUploads_setsEntity.
@Test
public void testUploads_setsEntity() throws IOException, InvalidRecordLengthException {
setUpExecuteCaptor();
restUploader.uploadGlucoseDataSets(Lists.newArrayList(mockGlucoseDataSet()));
HttpPost post = (HttpPost) captor.getValue();
String entity = CharStreams.toString(new InputStreamReader(post.getEntity().getContent()));
assertThat(entity, containsString("jsonKey"));
assertThat(entity, containsString("jsonValue"));
}
use of org.apache.http.client.methods.HttpPost in project android-uploader by nightscout.
the class RestLegacyUploaderTest method testDeviceStatus_Entity.
@Test
public void testDeviceStatus_Entity() throws Exception {
AbstractUploaderDevice deviceStatus = mockDeviceStatus();
restUploader.uploadDeviceStatus(deviceStatus);
HttpPost post = (HttpPost) captor.getValue();
String entity = CharStreams.toString(new InputStreamReader(post.getEntity().getContent()));
verifyDeviceStatus(new JSONObject(entity), deviceStatus);
}
use of org.apache.http.client.methods.HttpPost in project android-uploader by nightscout.
the class RestV1UploaderTest method testMeterRecord_Entity.
@Test
public void testMeterRecord_Entity() throws Exception {
restUploader.uploadMeterRecords(Lists.newArrayList(mockMeterRecord()));
HttpPost post = (HttpPost) captor.getValue();
String entity = CharStreams.toString(new InputStreamReader(post.getEntity().getContent()));
verifyMeterRecord(new JSONObject(entity));
}
Aggregations