Search in sources :

Example 1 with DatabaseTransactionStats

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));
}
Also used : DatabaseManagementServiceFactory(org.neo4j.graphdb.facade.DatabaseManagementServiceFactory) CommunityEditionModule(org.neo4j.graphdb.factory.module.edition.CommunityEditionModule) Config(org.neo4j.configuration.Config) DatabaseTransactionStats(org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats)

Example 2 with DatabaseTransactionStats

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);
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DatabaseTransactionStats(org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Socket(java.net.Socket) Timeout(org.junit.jupiter.api.Timeout) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DatabaseTransactionStats (org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 Reader (java.io.Reader)1 Socket (java.net.Socket)1 Timeout (org.junit.jupiter.api.Timeout)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Config (org.neo4j.configuration.Config)1 DatabaseManagementServiceFactory (org.neo4j.graphdb.facade.DatabaseManagementServiceFactory)1 CommunityEditionModule (org.neo4j.graphdb.factory.module.edition.CommunityEditionModule)1