use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin__execute_multiple__commit.
@Test
public void begin__execute_multiple__commit() throws Exception {
long nodesInDatabaseBeforeTransaction = countNodes();
// begin
Response begin = http.POST("/db/data/transaction");
String commitResource = begin.stringFromContent("commit");
// execute
http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' }, " + "{ 'statement': 'CREATE (n)' } ] }"));
// commit
Response commit = http.POST(commitResource);
assertThat(commit, containsNoErrors());
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + 2));
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin__execute__commit__execute.
@Test
public void begin__execute__commit__execute() throws Exception {
// begin
Response begin = http.POST("/db/data/transaction");
String commitResource = begin.stringFromContent("commit");
// execute
http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
// commit
http.POST(commitResource);
// execute
Response execute2 = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ]" + " }"));
assertThat(execute2.status(), equalTo(404));
assertThat(execute2, hasErrors(Status.Transaction.TransactionNotFound));
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin__execute__rollback_concurrently.
@Test
public void begin__execute__rollback_concurrently() throws Exception {
// begin
final Response begin = http.POST("/db/data/transaction");
assertThat(begin.status(), equalTo(201));
assertHasTxLocation(begin);
// execute
final String executeResource = begin.location();
final String statement = "WITH range(0, 100000) AS r UNWIND r AS i CREATE (n {number: i}) RETURN count(n)";
final CountDownLatch latch = new CountDownLatch(1);
final Future<Response> executeFuture = Executors.newSingleThreadExecutor().submit(() -> {
latch.countDown();
Response response = http.POST(executeResource, quotedJson("{ 'statements': [ { 'statement': '" + statement + "' } ] }"));
assertThat(response.status(), equalTo(200));
return response;
});
// terminate
final Future<Response> interruptFuture = Executors.newSingleThreadExecutor().submit(() -> {
try {
latch.await();
Thread.sleep(100);
} catch (InterruptedException ignored) {
// go
}
Response response = http.DELETE(begin.location());
assertThat(response.status(), equalTo(200));
return response;
});
interruptFuture.get();
Response execute = executeFuture.get();
assertThat(execute, hasErrors(Status.Statement.ExecutionFailed));
Response execute2 = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertThat(execute2.status(), equalTo(404));
assertThat(execute2, hasErrors(Status.Transaction.TransactionNotFound));
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin_and_execute_cypher_23_periodic_commit_that_returns_data_and_commit.
@Test
public void begin_and_execute_cypher_23_periodic_commit_that_returns_data_and_commit() throws Exception {
// to get rid off the property key id creation in the actual test
try (Transaction tx = graphdb().beginTx()) {
Node node = graphdb().createNode();
node.setProperty("id", 42);
}
int nodes = 11;
int batch = 2;
ServerTestUtils.withCSVFile(nodes, url -> {
long nodesInDatabaseBeforeTransaction = countNodes();
long txIdBefore = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CYPHER 2.3 USING PERIODIC COMMIT " + batch + " LOAD CSV FROM" + " \\\"" + url + "\\\" AS line CREATE (n {id: 23}) RETURN n' } ] }"));
long txIdAfter = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
assertThat(response.status(), equalTo(200));
assertThat(response, containsNoErrors());
JsonNode columns = response.get("results").get(0).get("columns");
assertThat(columns.toString(), equalTo("[\"n\"]"));
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + nodes));
assertThat(txIdAfter, equalTo(txIdBefore + ((nodes / batch) + 1)));
});
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method returned_rest_urls_must_be_useable.
@Test
public void returned_rest_urls_must_be_useable() throws Exception {
// begin and execute and commit "resultDataContents":["REST"]
HTTP.RawPayload payload = quotedJson("{ 'statements': [ { 'statement': 'CREATE (n {a: 1}) return n', " + "'resultDataContents' : ['REST'] } ] }");
Response begin = http.POST("/db/data/transaction/commit", payload);
assertThat(begin.status(), equalTo(200));
JsonNode results = begin.get("results");
JsonNode result = results.get(0);
JsonNode data = result.get("data");
JsonNode firstDataSegment = data.get(0);
JsonNode restData = firstDataSegment.get("rest");
JsonNode firstRestSegment = restData.get(0);
String propertiesUri = firstRestSegment.get("properties").asText();
Response propertiesResponse = http.GET(propertiesUri);
assertThat(propertiesResponse.status(), is(200));
}
Aggregations