Search in sources :

Example 16 with Response

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));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 17 with Response

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)));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Test(org.junit.Test)

Example 18 with Response

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));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 19 with Response

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));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 20 with Response

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));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Aggregations

Response (org.neo4j.test.server.HTTP.Response)73 Test (org.junit.Test)69 JsonNode (org.codehaus.jackson.JsonNode)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Before (org.junit.Before)2 HTTP (org.neo4j.test.server.HTTP)2 HashSet (java.util.HashSet)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 ServerControls (org.neo4j.harness.ServerControls)1 JsonHelper.jsonNode (org.neo4j.server.rest.domain.JsonHelper.jsonNode)1