Search in sources :

Example 86 with Response

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

Example 87 with Response

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

Example 88 with Response

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

Example 89 with Response

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)));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Transaction(org.neo4j.graphdb.Transaction) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) JsonHelper.jsonNode(org.neo4j.server.rest.domain.JsonHelper.jsonNode) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 90 with Response

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

Aggregations

Response (org.neo4j.test.server.HTTP.Response)151 Test (org.junit.Test)69 Test (org.junit.jupiter.api.Test)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 HTTP (org.neo4j.test.server.HTTP)13 JsonNode (org.codehaus.jackson.JsonNode)12 Node (org.neo4j.graphdb.Node)11 Transaction (org.neo4j.graphdb.Transaction)11 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 Duration (java.time.Duration)5 ZonedDateTime (java.time.ZonedDateTime)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 HttpResponse (java.net.http.HttpResponse)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)2