use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin_and_execute__commit_with_badly_escaped_statement.
@Test
public void begin_and_execute__commit_with_badly_escaped_statement() throws Exception {
long nodesInDatabaseBeforeTransaction = countNodes();
String json = "{ \"statements\": [ { \"statement\": \"LOAD CSV WITH HEADERS FROM " + "\\\"xx file://C:/countries.csvxxx\\\\\" as csvLine MERGE (c:Country { Code: csvLine.Code })\" " + "} ] }";
// begin and execute
// given statement is badly escaped and it is a client error, thus tx is rolled back at once
Response begin = http.POST("/db/data/transaction", quotedJson(json));
String commitResource = begin.stringFromContent("commit");
// commit fails because tx was rolled back on the previous step
Response commit = http.POST(commitResource);
assertThat(begin.status(), equalTo(201));
assertThat(begin, hasErrors(Status.Request.InvalidFormat));
assertThat(commit.status(), equalTo(404));
assertThat(commit, hasErrors(Status.Transaction.TransactionNotFound));
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction));
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin_and_execute_periodic_commit_and_commit.
@Test
public void begin_and_execute_periodic_commit_and_commit() throws Exception {
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': 'USING PERIODIC COMMIT " + batch + " LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE ()' } ] }"));
long txIdAfter = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
System.out.println("RESPONSE:");
System.out.println(response);
assertThat(response.status(), equalTo(200));
assertThat(response, containsNoErrors());
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 begin_and_execute_periodic_commit__commit.
@Test
public void begin_and_execute_periodic_commit__commit() throws Exception {
ServerTestUtils.withCSVFile(1, url -> {
Response begin = http.POST("/db/data/transaction", quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE ()' } ] }"));
assertThat(begin, hasErrors(Status.Statement.SemanticError));
});
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin_create_two_nodes_delete_one.
@Test
public void begin_create_two_nodes_delete_one() throws Exception {
/*
* This issue was reported from the community. It resulted in a refactoring of the interaction
* between TxManager and TransactionContexts.
*/
// GIVEN
long nodesInDatabaseBeforeTransaction = countNodes();
Response response = http.POST("/db/data/transaction/commit", rawPayload("{ \"statements\" : [{\"statement\" : \"CREATE (n0:DecibelEntity :AlbumGroup{DecibelID : " + "'34a2201b-f4a9-420f-87ae-00a9c691cc5c', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', " + "OriginalReleaseDate : '2013-01-08', IsCanon : 'False'}) return id(n0)\"}, " + "{\"statement\" : \"CREATE (n1:DecibelEntity :AlbumRelease{DecibelID : " + "'9ed529fa-7c19-11e2-be78-bcaec5bea3c3', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', LabelName : 'Barsuk " + "Records', " + "FormatNames : 'File', TrackCount : '3', MediaCount : '1', Duration : '460.000000', " + "ReleaseDate : '2013-01-08', ReleaseYear : '2013', ReleaseRegion : 'USA', " + "Cline : 'Barsuk Records', Pline : 'Barsuk Records', CYear : '2013', PYear : '2013', " + "ParentalAdvisory : 'False', IsLimitedEdition : 'False'}) return id(n1)\"}]}"));
assertEquals(200, response.status());
JsonNode everything = jsonNode(response.rawContent());
JsonNode result = everything.get("results").get(0);
long id = result.get("data").get(0).get("row").get(0).getLongValue();
// WHEN
http.POST("/db/data/cypher", rawPayload("{\"query\":\"match (n) where id(n) = " + id + " delete n\"}"));
// THEN
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + 1));
}
use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.
the class TransactionIT method begin__rollback__execute.
@Test
public void begin__rollback__execute() throws Exception {
// begin
Response begin = http.POST("/db/data/transaction");
assertThat(begin.status(), equalTo(201));
assertHasTxLocation(begin);
// terminate
Response interrupt = http.DELETE(begin.location());
assertThat(interrupt.status(), equalTo(200));
// execute
Response execute = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertThat(execute.status(), equalTo(404));
}
Aggregations