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"));
}
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();
}
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();
}
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();
}
}
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"));
}
Aggregations