|
import java.util.concurrent.Callable; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
import org.apache.http.client.methods.HttpPost; |
|
import org.apache.http.entity.ContentType; |
|
import org.apache.http.entity.StringEntity; |
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
import org.junit.Test; |
|
|
|
public class RemoteOverhead |
|
{ |
|
@Test |
|
public void transactionalEndpoint() throws Exception |
|
{ |
|
try ( CloseableHttpClient httpClient = HttpClientBuilder.create().build() ) |
|
{ |
|
final ObjectMapper jsonMapper = new ObjectMapper(); |
|
|
|
for ( int i = 0; i < 10; i++ ) |
|
{ |
|
time( new Callable<Void>() |
|
{ |
|
@Override |
|
public Void call() throws Exception |
|
{ |
|
ObjectNode requestJson = JsonNodeFactory.instance.objectNode(); |
|
requestJson.withArray( "statements" ).addObject().put( "statement", "RETURN 1" ); |
|
|
|
HttpPost request = new HttpPost( "http://localhost:7474/db/data/transaction/commit" ); |
|
request.setEntity( new StringEntity( jsonMapper.writeValueAsString( requestJson ), |
|
ContentType.APPLICATION_JSON ) ); |
|
|
|
try ( CloseableHttpResponse response = httpClient.execute( request ) ) |
|
{ |
|
JsonNode responseJson = jsonMapper.readTree( response.getEntity().getContent() ); |
|
System.out.println( "result = " + |
|
responseJson.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "row" ).get( 0 ) ); |
|
} |
|
|
|
return null; |
|
} |
|
} ); |
|
} |
|
} |
|
} |
|
|
|
private static void time( Callable<Void> callable ) throws Exception |
|
{ |
|
long before = System.currentTimeMillis(); |
|
callable.call(); |
|
long after = System.currentTimeMillis(); |
|
System.out.printf( "round-trip time: %dms%n", after - before ); |
|
} |
|
} |