use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.
the class DBMSModuleTest method shouldRegisterAtRootByDefault.
@SuppressWarnings("unchecked")
@Test
public void shouldRegisterAtRootByDefault() throws Exception {
WebServer webServer = mock(WebServer.class);
Config config = mock(Config.class);
CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
when(neoServer.getWebServer()).thenReturn(webServer);
when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(true);
DBMSModule module = new DBMSModule(webServer, config);
module.start();
verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
}
use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.
the class DatabaseActions method start.
public void start() throws UnableToStartServerException {
if (isRunning()) {
throw new UnableToStartServerException("Already started");
}
Config config = model.getConfig();
Monitors monitors = new Monitors();
LogProvider userLogProvider = FormattedLogProvider.toOutputStream(System.out);
GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider).monitors(monitors);
server = new CommunityNeoServer(config, dependencies, userLogProvider);
try {
server.start();
} catch (ServerStartupException e) {
server = null;
Set<Class> causes = extractCauseTypes(e);
if (causes.contains(StoreLockException.class)) {
throw new UnableToStartServerException("Unable to lock store. Are you running another Neo4j process against this database?");
}
if (causes.contains(BindException.class)) {
throw new UnableToStartServerException("Unable to bind to port. Are you running another Neo4j process on this computer?");
}
throw new UnableToStartServerException(e.getMessage());
}
}
use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.
the class TransactionGuardIntegrationTest method terminateLongRunningDriverPeriodicCommitQuery.
@Test
public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception {
GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortCustomGuard, driverConfig);
Session session = driver.session()) {
URL url = prepareTestImportFile(8);
session.run("USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();").consume();
fail("Transaction should be already terminated by execution guard.");
} catch (Exception expected) {
//
}
assertDatabaseDoesNotHaveNodes(database);
}
use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.
the class TransactionGuardIntegrationTest method terminateLongRunningRestTransactionalEndpointQuery.
@Test
public void terminateLongRunningRestTransactionalEndpointQuery() throws Exception {
GraphDatabaseAPI database = startDatabaseWithTimeout();
CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
String transactionEndPoint = HTTP.POST(transactionUri(neoServer)).location();
fakeClock.forward(3, TimeUnit.SECONDS);
HTTP.Response response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertEquals("Response should be successful.", 200, response.status());
HTTP.Response commitResponse = HTTP.POST(transactionEndPoint + "/commit");
assertEquals("Transaction should be already closed and not found.", 404, commitResponse.status());
assertEquals("Transaction should be forcefully closed.", TransactionNotFound.code().serialize(), commitResponse.get("errors").findValue("code").asText());
assertDatabaseDoesNotHaveNodes(database);
}
use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.
the class TransactionGuardIntegrationTest method terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery.
@Test
public void terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery() throws Exception {
GraphDatabaseAPI database = startDatabaseWithTimeout();
CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
long customTimeout = TimeUnit.SECONDS.toMillis(10);
HTTP.Response beginResponse = HTTP.withHeaders(HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER, String.valueOf(customTimeout)).POST(transactionUri(neoServer), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertEquals("Response should be successful.", 201, beginResponse.status());
String transactionEndPoint = beginResponse.location();
fakeClock.forward(3, TimeUnit.SECONDS);
HTTP.Response response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertEquals("Response should be successful.", 200, response.status());
fakeClock.forward(11, TimeUnit.SECONDS);
response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertEquals("Response should be successful.", 200, response.status());
HTTP.Response commitResponse = HTTP.POST(transactionEndPoint + "/commit");
assertEquals("Transaction should be already closed and not found.", 404, commitResponse.status());
assertEquals("Transaction should be forcefully closed.", TransactionNotFound.code().serialize(), commitResponse.get("errors").findValue("code").asText());
assertDatabaseDoesNotHaveNodes(database);
}
Aggregations