Search in sources :

Example 1 with FakeMemoryTracker

use of org.neo4j.test.FakeMemoryTracker in project neo4j by neo4j.

the class ExecutingQueryTest method shouldTransitionBetweenStates.

@Test
void shouldTransitionBetweenStates() {
    // initial
    assertEquals("parsing", query.snapshot().status());
    // when
    query.onObfuscatorReady(null);
    // then
    assertEquals("planning", query.snapshot().status());
    // when
    query.onCompilationCompleted(new CompilerInfo("the-planner", "the-runtime", emptyList()), READ_ONLY, null);
    // then
    assertEquals("planned", query.snapshot().status());
    // when
    query.onExecutionStarted(new FakeMemoryTracker());
    // then
    assertEquals("running", query.snapshot().status());
    // when
    try (LockWaitEvent ignored = lock("NODE", 17)) {
        // then
        assertEquals("waiting", query.snapshot().status());
    }
    // then
    assertEquals("running", query.snapshot().status());
}
Also used : FakeMemoryTracker(org.neo4j.test.FakeMemoryTracker) LockWaitEvent(org.neo4j.lock.LockWaitEvent) Test(org.junit.jupiter.api.Test)

Example 2 with FakeMemoryTracker

use of org.neo4j.test.FakeMemoryTracker in project neo4j by neo4j.

the class ExecutingQueryTest method shouldAllowRetryingAfterStartingExecutiong.

@Test
void shouldAllowRetryingAfterStartingExecutiong() {
    assertEquals("parsing", query.snapshot().status());
    query.onObfuscatorReady(null);
    assertEquals("planning", query.snapshot().status());
    query.onCompilationCompleted(null, null, null);
    assertEquals("planned", query.snapshot().status());
    query.onExecutionStarted(new FakeMemoryTracker());
    assertEquals("running", query.snapshot().status());
    query.onRetryAttempted();
    assertEquals("parsing", query.snapshot().status());
}
Also used : FakeMemoryTracker(org.neo4j.test.FakeMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 3 with FakeMemoryTracker

use of org.neo4j.test.FakeMemoryTracker in project neo4j by neo4j.

the class ExecutingQueryTest method shouldReportWaitTime.

@Test
void shouldReportWaitTime() {
    // given
    query.onObfuscatorReady(null);
    query.onCompilationCompleted(new CompilerInfo("the-planner", "the-runtime", emptyList()), READ_ONLY, null);
    query.onExecutionStarted(new FakeMemoryTracker());
    // then
    assertEquals("running", query.snapshot().status());
    // when
    clock.forward(10, TimeUnit.SECONDS);
    try (LockWaitEvent ignored = lock("NODE", 17)) {
        clock.forward(5, TimeUnit.SECONDS);
        // then
        QuerySnapshot snapshot = query.snapshot();
        assertEquals("waiting", snapshot.status());
        assertThat(snapshot.resourceInformation()).containsEntry("waitTimeMillis", 5_000L).containsEntry("resourceType", "NODE").containsEntry("transactionId", 10L).containsEntry("resourceIds", new long[] { 17 });
        assertEquals(5_000_000, snapshot.waitTimeMicros());
    }
    {
        QuerySnapshot snapshot = query.snapshot();
        assertEquals("running", snapshot.status());
        assertEquals(5_000_000, snapshot.waitTimeMicros());
    }
    // when
    clock.forward(2, TimeUnit.SECONDS);
    try (LockWaitEvent ignored = lock("RELATIONSHIP", 612)) {
        clock.forward(1, TimeUnit.SECONDS);
        // then
        QuerySnapshot snapshot = query.snapshot();
        assertEquals("waiting", snapshot.status());
        assertThat(snapshot.resourceInformation()).containsEntry("waitTimeMillis", 1_000L).containsEntry("resourceType", "RELATIONSHIP").containsEntry("transactionId", 10L).containsEntry("resourceIds", new long[] { 612 });
        assertEquals(6_000_000, snapshot.waitTimeMicros());
    }
    {
        QuerySnapshot snapshot = query.snapshot();
        assertEquals("running", snapshot.status());
        assertEquals(6_000_000, snapshot.waitTimeMicros());
    }
}
Also used : FakeMemoryTracker(org.neo4j.test.FakeMemoryTracker) LockWaitEvent(org.neo4j.lock.LockWaitEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 FakeMemoryTracker (org.neo4j.test.FakeMemoryTracker)3 LockWaitEvent (org.neo4j.lock.LockWaitEvent)2