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