Search in sources :

Example 16 with RestClient

use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.

the class RestClientTest method testPostWithUserAndPassword.

@Test
public void testPostWithUserAndPassword() {
    RestClient client = new RestClientImpl("/test", "user", "", 1000, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) Test(org.junit.Test)

Example 17 with RestClient

use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.

the class RestClientTest method testPost.

@Test
public void testPost() {
    RestClient client = new RestClientImpl("/test", 1000, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) Test(org.junit.Test)

Example 18 with RestClient

use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.

the class RestClientTest method testClose.

@Test
public void testClose() {
    RestClient client = new RestClientImpl("/test", 1000, 10, 5, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
    client.close();
    Assert.assertThrows(IllegalStateException.class, () -> {
        client.post("path", "body");
    });
    PoolingHttpClientConnectionManager pool;
    pool = Whitebox.getInternalState(client, "pool");
    Assert.assertNotNull(pool);
    AtomicBoolean isShutDown = Whitebox.getInternalState(pool, "isShutDown");
    Assert.assertTrue(isShutDown.get());
    ScheduledExecutorService cleanExecutor;
    cleanExecutor = Whitebox.getInternalState(client, "cleanExecutor");
    Assert.assertNotNull(cleanExecutor);
    Assert.assertTrue(cleanExecutor.isShutdown());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 19 with RestClient

use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.

the class RestClientTest method testPostWithToken.

@Test
public void testPostWithToken() {
    RestClient client = new RestClientImpl("/test", "token", 1000, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) Test(org.junit.Test)

Example 20 with RestClient

use of com.baidu.hugegraph.rest.RestClient in project hugegraph-common by hugegraph.

the class RestClientTest method testPostHttpsWithTokenAndAllParams.

@Test
public void testPostHttpsWithTokenAndAllParams() {
    String trustStoreFile = "src/test/resources/cacerts.jks";
    String trustStorePassword = "changeit";
    RestClient client = new RestClientImpl("/test", "token", 1000, 10, 5, trustStoreFile, trustStorePassword, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) Test(org.junit.Test)

Aggregations

AbstractRestClient (com.baidu.hugegraph.rest.AbstractRestClient)24 RestClient (com.baidu.hugegraph.rest.RestClient)24 Test (org.junit.Test)24 RestResult (com.baidu.hugegraph.rest.RestResult)19 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)3 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)2 HashMap (java.util.HashMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpClientConnection (org.apache.http.HttpClientConnection)1 HttpRoute (org.apache.http.conn.routing.HttpRoute)1 PoolStats (org.apache.http.pool.PoolStats)1