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);
}
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);
}
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);
}
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");
}
Aggregations