use of org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats in project neo4j by neo4j.
the class CommitContentionTest method createDb.
private GraphDatabaseService createDb() {
Config cfg = Config.newBuilder().set(neo4j_home, testDirectory.absolutePath()).build();
managementService = new DatabaseManagementServiceFactory(DbmsInfo.COMMUNITY, globalModule -> new CommunityEditionModule(globalModule) {
@Override
public DatabaseTransactionStats createTransactionMonitor() {
return new SkipTransactionDatabaseStats();
}
}).build(cfg, GraphDatabaseDependencies.newDependencies().dependencies(noOpSystemGraphInitializer(cfg)));
return managementService.database(cfg.get(GraphDatabaseSettings.default_database));
}
use of org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats in project neo4j by neo4j.
the class TransactionIT method executing_single_statement_in_new_transaction_and_failing_to_read_the_output_should_interrupt.
@ParameterizedTest
@MethodSource("argumentsProvider")
@Timeout(30)
public void executing_single_statement_in_new_transaction_and_failing_to_read_the_output_should_interrupt(String txUri) throws Exception {
this.txUri = txUri;
// given
long initialNodes = countNodes();
DatabaseTransactionStats txMonitor = ((GraphDatabaseAPI) graphdb()).getDependencyResolver().resolveDependency(DatabaseTransactionStats.class);
long initialRollBacks = txMonitor.getNumberOfRolledBackTransactions();
// when sending a request and aborting in the middle of receiving the result
Socket socket = new Socket("localhost", getLocalHttpPort());
PrintStream out = new PrintStream(socket.getOutputStream());
String output = quotedJson("{ 'statements': [ { 'statement': 'UNWIND range(0, 9999) AS i CREATE (n {i: i}) RETURN n' } ] " + "}").get();
out.print(format("POST /%s/commit HTTP/1.1\r\n", txUri));
out.print("Host: localhost:7474\r\n");
out.print("Content-type: application/json; charset=utf-8\r\n");
out.print("Content-length: " + output.getBytes().length + "\r\n");
out.print("\r\n");
out.print(output);
out.print("\r\n");
InputStream inputStream = socket.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int numRead = 0;
while (numRead < 300) {
numRead += reader.read(new char[300]);
}
socket.close();
assertEquals(initialNodes, countNodes());
// then soon the transaction should have been terminated
long endTime = System.currentTimeMillis() + 5000;
long additionalRollBacks;
while (true) {
additionalRollBacks = txMonitor.getNumberOfRolledBackTransactions() - initialRollBacks;
if (additionalRollBacks > 0 || System.currentTimeMillis() > endTime) {
break;
}
Thread.sleep(100);
}
assertEquals(1, additionalRollBacks);
}
Aggregations