Search in sources :

Example 16 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldTerminateOnlyGivenUsersTransaction.

//@Test
public void shouldTerminateOnlyGivenUsersTransaction() throws Throwable {
    DoubleLatch latch = new DoubleLatch(3);
    ThreadedTransaction<S> schema = new ThreadedTransaction<>(neo, latch);
    ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
    schema.executeCreateNode(threading, schemaSubject);
    write.executeCreateNode(threading, writeSubject);
    latch.startAndWaitForAllToStart();
    assertSuccess(adminSubject, "CALL dbms.terminateTransactionsForUser( 'schemaSubject' )", r -> assertKeyIsMap(r, "username", "transactionsTerminated", map("schemaSubject", "1")));
    assertSuccess(adminSubject, "CALL dbms.listTransactions()", r -> assertKeyIsMap(r, "username", "activeTransactions", map("adminSubject", "1", "writeSubject", "1")));
    latch.finishAndWaitForAllToFinish();
    schema.closeAndAssertTransactionTermination();
    write.closeAndAssertSuccess();
    assertSuccess(adminSubject, "MATCH (n:Test) RETURN n.name AS name", r -> assertKeyIs(r, "name", "writeSubject-node"));
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch)

Example 17 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldListAllQueriesWithAuthDisabled.

@Test
public void shouldListAllQueriesWithAuthDisabled() throws Throwable {
    neo.tearDown();
    neo = setUpNeoServer(stringMap(GraphDatabaseSettings.auth_enabled.name(), "false"));
    DoubleLatch latch = new DoubleLatch(2, true);
    OffsetDateTime startTime = OffsetDateTime.now();
    ThreadedTransaction<S> read = new ThreadedTransaction<>(neo, latch);
    String q = read.execute(threading, neo.login("user1", ""), "UNWIND [1,2,3] AS x RETURN x");
    latch.startAndWaitForAllToStart();
    String query = "CALL dbms.listQueries()";
    try {
        assertSuccess(neo.login("admin", ""), query, r -> {
            Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
            Matcher<Map<String, Object>> thisQuery = listedQueryOfInteractionLevel(startTime, "", query);
            Matcher<Map<String, Object>> matcher1 = listedQuery(startTime, "", q);
            assertThat(maps, matchesOneToOneInAnyOrder(matcher1, thisQuery));
        });
    } finally {
        latch.finishAndWaitForAllToFinish();
    }
    read.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 18 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldListAllQueryIncludingMetaData.

/*
    ==================================================================================
     */
//---------- list running queries -----------
@Test
public void shouldListAllQueryIncludingMetaData() throws Throwable {
    String setMetaDataQuery = "CALL dbms.setTXMetaData( { realUser: 'MyMan' } )";
    String matchQuery = "MATCH (n) RETURN n";
    String listQueriesQuery = "CALL dbms.listQueries()";
    DoubleLatch latch = new DoubleLatch(2);
    OffsetDateTime startTime = OffsetDateTime.now();
    ThreadedTransaction<S> tx = new ThreadedTransaction<>(neo, latch);
    tx.execute(threading, writeSubject, setMetaDataQuery, matchQuery);
    latch.startAndWaitForAllToStart();
    assertSuccess(adminSubject, listQueriesQuery, r -> {
        Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
        Matcher<Map<String, Object>> thisQuery = listedQueryOfInteractionLevel(startTime, "adminSubject", listQueriesQuery);
        Matcher<Map<String, Object>> matchQueryMatcher = listedQueryWithMetaData(startTime, "writeSubject", matchQuery, map("realUser", "MyMan"));
        assertThat(maps, matchesOneToOneInAnyOrder(thisQuery, matchQueryMatcher));
    });
    latch.finishAndWaitForAllToFinish();
    tx.closeAndAssertSuccess();
}
Also used : OffsetDateTime(java.time.OffsetDateTime) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DoubleLatch(org.neo4j.test.DoubleLatch) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 19 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldTerminateRestrictedTransaction.

//@Test
public void shouldTerminateRestrictedTransaction() {
    final DoubleLatch doubleLatch = new DoubleLatch(2);
    ClassWithProcedures.setTestLatch(new ClassWithProcedures.LatchedRunnables(doubleLatch, () -> {
    }, () -> {
    }));
    new Thread(() -> assertFail(writeSubject, "CALL test.waitForLatch()", "Explicitly terminated by the user.")).start();
    doubleLatch.startAndWaitForAllToStart();
    try {
        assertSuccess(adminSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", r -> assertKeyIsMap(r, "username", "transactionsTerminated", map("writeSubject", "1")));
    } finally {
        doubleLatch.finishAndWaitForAllToFinish();
    }
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch)

Example 20 with DoubleLatch

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

the class BuiltInProceduresInteractionTestBase method shouldNotTerminateTransactionsIfNotAdmin.

//@Test
public void shouldNotTerminateTransactionsIfNotAdmin() throws Throwable {
    DoubleLatch latch = new DoubleLatch(2);
    ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
    write.executeCreateNode(threading, writeSubject);
    latch.startAndWaitForAllToStart();
    assertFail(noneSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", PERMISSION_DENIED);
    assertFail(pwdSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", CHANGE_PWD_ERR_MSG);
    assertFail(readSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", PERMISSION_DENIED);
    assertFail(schemaSubject, "CALL dbms.terminateTransactionsForUser( 'writeSubject' )", PERMISSION_DENIED);
    assertSuccess(adminSubject, "CALL dbms.listTransactions()", r -> assertKeyIs(r, "username", "adminSubject", "writeSubject"));
    latch.finishAndWaitForAllToFinish();
    write.closeAndAssertSuccess();
    assertSuccess(adminSubject, "MATCH (n:Test) RETURN n.name AS name", r -> assertKeyIs(r, "name", "writeSubject-node"));
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch)

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