Search in sources :

Example 21 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldOnlyListOwnQueriesWhenNotRunningAsAdmin.

@Test
public void shouldOnlyListOwnQueriesWhenNotRunningAsAdmin() throws Throwable {
    DoubleLatch latch = new DoubleLatch(3, true);
    OffsetDateTime startTime = OffsetDateTime.now();
    ThreadedTransaction<S> read1 = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> read2 = new ThreadedTransaction<>(neo, latch);
    String q1 = read1.execute(threading, readSubject, "UNWIND [1,2,3] AS x RETURN x");
    String ignored = read2.execute(threading, writeSubject, "UNWIND [4,5,6] AS y RETURN y");
    latch.startAndWaitForAllToStart();
    String query = "CALL dbms.listQueries()";
    assertSuccess(readSubject, query, r -> {
        Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
        Matcher<Map<String, Object>> thisQuery = listedQuery(startTime, "readSubject", query);
        Matcher<Map<String, Object>> queryMatcher = listedQuery(startTime, "readSubject", q1);
        assertThat(maps, matchesOneToOneInAnyOrder(queryMatcher, thisQuery));
    });
    latch.finishAndWaitForAllToFinish();
    read1.closeAndAssertSuccess();
    read2.closeAndAssertSuccess();
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 22 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldListTransactions.

//@Test
public void shouldListTransactions() throws Throwable {
    DoubleLatch latch = new DoubleLatch(3);
    ThreadedTransaction<S> write1 = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> write2 = new ThreadedTransaction<>(neo, latch);
    String q1 = write1.executeCreateNode(threading, writeSubject);
    String q2 = write2.executeCreateNode(threading, writeSubject);
    latch.startAndWaitForAllToStart();
    assertSuccess(adminSubject, "CALL dbms.listTransactions()", r -> assertKeyIsMap(r, "username", "activeTransactions", map("adminSubject", "1", "writeSubject", "2")));
    latch.finishAndWaitForAllToFinish();
    write1.closeAndAssertSuccess();
    write2.closeAndAssertSuccess();
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 23 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldKillMultipleUserQueries.

@Test
public void shouldKillMultipleUserQueries() throws Throwable {
    DoubleLatch latch = new DoubleLatch(5);
    ThreadedTransaction<S> read1 = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> read2 = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> read3 = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
    String q1 = read1.execute(threading, readSubject, "UNWIND [1,2,3] AS x RETURN x");
    String q2 = read2.execute(threading, readSubject, "UNWIND [4,5,6] AS y RETURN y");
    read3.execute(threading, readSubject, "UNWIND [7,8,9] AS z RETURN z");
    write.execute(threading, writeSubject, "UNWIND [11,12,13] AS q RETURN q");
    latch.startAndWaitForAllToStart();
    String id1 = extractQueryId(q1);
    String id2 = extractQueryId(q2);
    String idParam = "['" + id1 + "', '" + id2 + "']";
    assertSuccess(adminSubject, "CALL dbms.killQueries(" + idParam + ") YIELD username " + "RETURN count(username) AS count, username", r -> {
        List<Map<String, Object>> actual = r.stream().collect(toList());
        Matcher<Map<String, Object>> mapMatcher = allOf((Matcher) hasEntry(equalTo("count"), anyOf(equalTo(2), equalTo(2L))), (Matcher) hasEntry(equalTo("username"), equalTo("readSubject")));
        assertThat(actual, matchesOneToOneInAnyOrder(mapMatcher));
    });
    latch.finishAndWaitForAllToFinish();
    read1.closeAndAssertTransactionTermination();
    read2.closeAndAssertTransactionTermination();
    read3.closeAndAssertSuccess();
    write.closeAndAssertSuccess();
    assertEmpty(adminSubject, "CALL dbms.listQueries() YIELD query WITH * WHERE NOT query CONTAINS 'listQueries' RETURN *");
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 24 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldTerminateTransactionForUser.

/*
    This surface is hidden in 3.1, to possibly be completely removed or reworked later
    ==================================================================================
     */
//---------- terminate transactions for user -----------
//@Test
public void shouldTerminateTransactionForUser() throws Throwable {
    DoubleLatch latch = new DoubleLatch(2);
    ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
    write.executeCreateNode(threading, writeSubject);
    latch.startAndWaitForAllToStart();
    assertSuccess(adminSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", r -> assertKeyIsMap(r, "username", "transactionsTerminated", map("writeSubject", "1")));
    assertSuccess(adminSubject, "CALL dbms.listTransactions()", r -> assertKeyIsMap(r, "username", "activeTransactions", map("adminSubject", "1")));
    latch.finishAndWaitForAllToFinish();
    write.closeAndAssertTransactionTermination();
    assertEmpty(adminSubject, "MATCH (n:Test) RETURN n.name AS name");
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch)

Example 25 with DoubleLatch

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

the class AuthProceduresInteractionTestBase method shouldInheritSecurityContextWhenProcedureStartingTransactionInNewThread.

@Test
public void shouldInheritSecurityContextWhenProcedureStartingTransactionInNewThread() throws Throwable {
    exceptionsInProcedure.clear();
    DoubleLatch latch = new DoubleLatch(2);
    ClassWithProcedures.doubleLatch = latch;
    latch.start();
    assertEmpty(readSubject, "CALL test.threadReadDoingWriteTransaction");
    latch.finishAndWaitForAllToFinish();
    assertThat(exceptionsInProcedure.size(), equalTo(1));
    assertThat(exceptionsInProcedure.get(0).getMessage(), containsString(WRITE_OPS_NOT_ALLOWED));
    assertSuccess(adminSubject, "MATCH (:VeryUniqueLabel) RETURN toString(count(*)) as n", r -> assertKeyIs(r, "n", "0"));
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Aggregations

DoubleLatch (org.neo4j.test.DoubleLatch)48 Test (org.junit.Test)37 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 Collections.emptyMap (java.util.Collections.emptyMap)9 Map (java.util.Map)9 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)9 OffsetDateTime (java.time.OffsetDateTime)5 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Server (org.eclipse.jetty.server.Server)3 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)3 Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.never (org.mockito.Mockito.never)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2