use of org.neo4j.logging.Log in project neo4j by neo4j.
the class AbstractCypherResource method commitNewTransaction.
@POST
@Path("/commit")
public Response commitNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
try (var memoryTracker = createMemoryTracker()) {
InputEventStream inputStream = ensureNotNull(inputEventStream);
Optional<GraphDatabaseAPI> graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
return graphDatabaseAPI.map(databaseAPI -> {
if (isDatabaseNotAvailable(databaseAPI)) {
return createNonAvailableDatabaseResponse(inputStream.getParameters());
}
memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
TransactionHandle transactionHandle = createNewTransactionHandle(transactionFacade, request, headers, memoryTracker, true);
Invocation invocation = new Invocation(log, transactionHandle, null, memoryPool, inputStream, true);
OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
return Response.ok(outputStream).build();
}).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
}
}
use of org.neo4j.logging.Log in project neo4j by neo4j.
the class AbstractCypherResource method executeInExistingTransaction.
private Response executeInExistingTransaction(long transactionId, InputEventStream inputEventStream, MemoryTracker memoryTracker, boolean finishWithCommit) {
InputEventStream inputStream = ensureNotNull(inputEventStream);
Optional<GraphDatabaseAPI> graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
return graphDatabaseAPI.map(databaseAPI -> {
if (isDatabaseNotAvailable(databaseAPI)) {
return createNonAvailableDatabaseResponse(inputStream.getParameters());
}
memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
TransactionHandle transactionHandle;
try {
transactionHandle = transactionFacade.findTransactionHandle(transactionId);
} catch (TransactionLifecycleException e) {
return invalidTransaction(e, inputStream.getParameters());
}
Invocation invocation = new Invocation(log, transactionHandle, uriScheme.txCommitUri(transactionHandle.getId()), memoryPool, inputStream, finishWithCommit);
OutputEventStreamImpl outputEventStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
return Response.ok(outputEventStream).build();
}).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
}
use of org.neo4j.logging.Log in project neo4j by neo4j.
the class JULBridge method getLog.
private Log getLog(String name) {
Log log = logs.get(name);
if (log == null) {
Log newLog = logProvider.getLog(name);
log = logs.putIfAbsent(name, newLog);
if (log == null) {
log = newLog;
}
}
return log;
}
use of org.neo4j.logging.Log in project neo4j by neo4j.
the class DefaultWinnerStrategyTest method theWinnerShouldHaveTheBestVoteCredentials.
@Test
public void theWinnerShouldHaveTheBestVoteCredentials() throws Exception {
// given
InstanceId instanceOne = new InstanceId(1);
InstanceId instanceTwo = new InstanceId(2);
ClusterContext clusterContext = mock(ClusterContext.class);
final Log log = mock(Log.class);
LogProvider logProvider = new LogProvider() {
@Override
public Log getLog(Class loggingClass) {
return log;
}
@Override
public Log getLog(String name) {
return log;
}
};
when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
// when
Collection<Vote> votes = Arrays.asList(new Vote(instanceOne, new IntegerElectionCredentials(1)), new Vote(instanceTwo, new IntegerElectionCredentials(2)));
DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
org.neo4j.cluster.InstanceId winner = strategy.pickWinner(votes);
// then
assertEquals(instanceTwo, winner);
}
use of org.neo4j.logging.Log in project neo4j by neo4j.
the class DefaultWinnerStrategyTest method shouldLogElectionProcess.
@Test
public void shouldLogElectionProcess() {
// given
ClusterContext clusterContext = mock(ClusterContext.class);
final Log log = mock(Log.class);
LogProvider logProvider = new LogProvider() {
@Override
public Log getLog(Class loggingClass) {
return log;
}
@Override
public Log getLog(String name) {
return log;
}
};
when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
// when
Collection<Vote> votes = Collections.emptyList();
DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
strategy.pickWinner(votes);
// then
verify(log).debug("Election: received votes [], eligible votes []");
}
Aggregations