Search in sources :

Example 1 with HTTP

use of org.neo4j.test.server.HTTP in project neo4j by neo4j.

the class TransactionTerminationIT method terminateSingleInstanceRestTransactionThatWaitsForLock.

@Test
public void terminateSingleInstanceRestTransactionThatWaitsForLock() throws Exception {
    ServerControls server = cleanupRule.add(TestServerBuilders.newInProcessBuilder().withConfig(GraphDatabaseSettings.auth_enabled, Settings.FALSE).withConfig(GraphDatabaseFacadeFactory.Configuration.lock_manager, lockManagerName).newServer());
    GraphDatabaseService db = server.graph();
    HTTP.Builder http = withBaseUri(server.httpURI().toString());
    long value1 = 1L;
    long value2 = 2L;
    createNode(db);
    Response tx1 = startTx(http);
    Response tx2 = startTx(http);
    assertNumberOfActiveTransactions(2, db);
    Response update1 = executeUpdateStatement(tx1, value1, http);
    assertThat(update1.status(), equalTo(200));
    assertThat(update1, containsNoErrors());
    CountDownLatch latch = new CountDownLatch(1);
    Future<?> tx2Result = executeInSeparateThread("tx2", () -> {
        latch.countDown();
        Response update2 = executeUpdateStatement(tx2, value2, http);
        assertTxWasTerminated(update2);
    });
    await(latch);
    sleepForAWhile();
    terminate(tx2, http);
    commit(tx1, http);
    Response update3 = executeUpdateStatement(tx2, value2, http);
    assertThat(update3.status(), equalTo(404));
    tx2Result.get(1, TimeUnit.MINUTES);
    assertNodeExists(db, value1);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) HTTP(org.neo4j.test.server.HTTP) ServerControls(org.neo4j.harness.ServerControls) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with HTTP

use of org.neo4j.test.server.HTTP in project neo4j by neo4j.

the class TransactionTest method reset_transaction_timeout_of_an_open_transaction.

@Test
@Documented("Reset transaction timeout of an open transaction\n" + "\n" + "Every orphaned transaction is automatically expired after a period of inactivity.  This may be prevented\n" + "by resetting the transaction timeout.\n" + "\n" + "The timeout may be reset by sending a keep-alive request to the server that executes an empty list of statements.\n" + "This request will reset the transaction timeout and return the new time at which the transaction will\n" + "expire as an RFC1123 formatted timestamp value in the ``transaction'' section of the response.")
public void reset_transaction_timeout_of_an_open_transaction() throws JsonParseException, ParseException, InterruptedException {
    // Given
    HTTP.Response initialResponse = POST(getDataUri() + "transaction");
    String location = initialResponse.location();
    long initialExpirationTime = expirationTime(jsonToMap(initialResponse.rawContent()));
    // This generous wait time is necessary to compensate for limited resolution of RFC 1123 timestamps
    // and the fact that the system clock is allowed to run "backwards" between threads
    // (cf. http://stackoverflow.com/questions/2978598)
    //
    Thread.sleep(3000);
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ ] }")).post(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    long newExpirationTime = expirationTime(result);
    assertTrue("Expiration time was not increased", newExpirationTime > initialExpirationTime);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) HTTP(org.neo4j.test.server.HTTP) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 3 with HTTP

use of org.neo4j.test.server.HTTP in project neo4j by neo4j.

the class AuthenticationIT method successful_authentication.

@Test
@Documented("Authenticate to access the server\n" + "\n" + "Authenticate by sending a username and a password to Neo4j using HTTP Basic Auth.\n" + "Requests should include an +Authorization+ header, with a value of +Basic <payload>+,\n" + "where \"payload\" is a base64 encoded string of \"username:password\".")
public void successful_authentication() throws JsonParseException, IOException {
    // Given
    startServerWithConfiguredUser();
    // Then
    HTTP.Response response = HTTP.withBasicAuth("neo4j", "secret").POST(txCommitURL("system"), query("SHOW USERS"));
    assertThat(response.status()).isEqualTo(200);
    final JsonNode jsonNode = getResultRow(response);
    assertThat(jsonNode.get(0).asText()).isEqualTo("neo4j");
    assertThat(jsonNode.get(1).asBoolean()).isEqualTo(false);
}
Also used : HTTP(org.neo4j.test.server.HTTP) JsonNode(com.fasterxml.jackson.databind.JsonNode) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 4 with HTTP

use of org.neo4j.test.server.HTTP in project neo4j by neo4j.

the class TransactionTestIT method reset_transaction_timeout_of_an_open_transaction.

@Test
@Documented("Reset transaction timeout of an open transaction\n" + "\n" + "Every orphaned transaction is automatically expired after a period of inactivity.  This may be prevented\n" + "by resetting the transaction timeout.\n" + "\n" + "The timeout may be reset by sending a keep-alive request to the server that executes an empty list of statements.\n" + "This request will reset the transaction timeout and return the new time at which the transaction will\n" + "expire as an RFC1123 formatted timestamp value in the ``transaction'' section of the response.")
public void reset_transaction_timeout_of_an_open_transaction() throws JsonParseException, InterruptedException {
    // Given
    HTTP.Response initialResponse = POST(txUri());
    String location = initialResponse.location();
    long initialExpirationTime = expirationTime(jsonToMap(initialResponse.rawContent()));
    // This generous wait time is necessary to compensate for limited resolution of RFC 1123 timestamps
    // and the fact that the system clock is allowed to run "backwards" between threads
    // (cf. http://stackoverflow.com/questions/2978598)
    // 
    Thread.sleep(3000);
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ ] }")).post(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    long newExpirationTime = expirationTime(result);
    assertTrue(newExpirationTime > initialExpirationTime, "Expiration time was not increased");
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) HTTP(org.neo4j.test.server.HTTP) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Aggregations

HTTP (org.neo4j.test.server.HTTP)4 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 Documented (org.neo4j.annotations.documented.Documented)2 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 ServerControls (org.neo4j.harness.ServerControls)1 Documented (org.neo4j.kernel.impl.annotations.Documented)1 Response (org.neo4j.test.server.HTTP.Response)1