use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.
the class RestClientTest method testPutWithHeaders.
@Test
public void testPutWithHeaders() {
RestClient client = new RestClientImpl("/test", 1000, 200);
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add("key1", "value1-1");
headers.add("key1", "value1-2");
headers.add("Content-Encoding", "gzip");
RestResult restResult = client.put("path", "id1", "body", headers);
Assert.assertEquals(200, restResult.status());
}
use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.
the class RestClientTest method testGetWithException.
@Test
public void testGetWithException() {
RestClient client = new RestClientImpl("/test", 1000, 400);
Assert.assertThrows(ClientException.class, () -> {
client.get("path", "id1");
});
}
use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.
the class RestClientTest method testDeleteWithId.
@Test
public void testDeleteWithId() {
RestClient client = new RestClientImpl("/test", 1000, 204);
RestResult restResult = client.delete("path", "id1");
Assert.assertEquals(204, restResult.status());
}
use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.
the class RestClientTest method testPostWithTokenAndAllParams.
@Test
public void testPostWithTokenAndAllParams() {
RestClient client = new RestClientImpl("/test", "token", 1000, 10, 5, 200);
RestResult restResult = client.post("path", "body");
Assert.assertEquals(200, restResult.status());
}
use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.
the class RestClientTest method testCleanExecutor.
@Test
public void testCleanExecutor() throws Exception {
// Modify IDLE_TIME 100ms to speed test
int newIdleTime = 100;
int newCheckPeriod = newIdleTime + 20;
RestClient client = new RestClientImpl("/test", 1000, newIdleTime, 10, 5, 200);
PoolingHttpClientConnectionManager pool;
pool = Whitebox.getInternalState(client, "pool");
pool = Mockito.spy(pool);
Whitebox.setInternalState(client, "pool", pool);
HttpRoute route = new HttpRoute(HttpHost.create("http://127.0.0.1:8080"));
// Create a connection manually, it will be put into leased list
HttpClientConnection conn = pool.requestConnection(route, null).get(1L, TimeUnit.SECONDS);
PoolStats stats = pool.getTotalStats();
int usingConns = stats.getLeased() + stats.getPending();
Assert.assertGte(1, usingConns);
// Sleep more than two check periods for busy connection
Thread.sleep(newCheckPeriod);
Mockito.verify(pool, Mockito.never()).closeExpiredConnections();
stats = pool.getTotalStats();
usingConns = stats.getLeased() + stats.getPending();
Assert.assertGte(1, usingConns);
// The connection will be put into available list
pool.releaseConnection(conn, null, 0, TimeUnit.SECONDS);
stats = pool.getTotalStats();
usingConns = stats.getLeased() + stats.getPending();
Assert.assertEquals(0, usingConns);
/*
* Sleep more than two check periods for free connection,
* ensure connection has been closed
*/
Thread.sleep(newCheckPeriod);
Mockito.verify(pool, Mockito.atLeastOnce()).closeExpiredConnections();
Mockito.verify(pool, Mockito.atLeastOnce()).closeIdleConnections(newIdleTime, TimeUnit.MILLISECONDS);
}
Aggregations