use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class AuthProceduresInteractionTestBase method shouldAllowProcedureStartingTransactionInNewThread.
@Test
public void shouldAllowProcedureStartingTransactionInNewThread() throws Throwable {
exceptionsInProcedure.clear();
DoubleLatch latch = new DoubleLatch(2);
ClassWithProcedures.doubleLatch = latch;
latch.start();
assertEmpty(writeSubject, "CALL test.threadTransaction");
latch.finishAndWaitForAllToFinish();
assertThat(exceptionsInProcedure.size(), equalTo(0));
assertSuccess(adminSubject, "MATCH (:VeryUniqueLabel) RETURN toString(count(*)) as n", r -> assertKeyIs(r, "n", "1"));
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class FileUserRepositoryTest method shouldProvideUserByUsernameEvenIfMidSetUsers.
@Test
public void shouldProvideUserByUsernameEvenIfMidSetUsers() throws Throwable {
// Given
FileUserRepository users = new FileUserRepository(fs, authFile, logProvider);
users.create(new User.Builder("oskar", Credential.forPassword("hidden")).build());
DoubleLatch latch = new DoubleLatch(2);
// When
Future<Object> setUsers = threading.execute(o -> {
users.setUsers(new HangingListSnapshot(latch, 10L, Collections.emptyList()));
return null;
}, null);
latch.startAndWaitForAllToStart();
// Then
assertNotNull(users.getUserByName("oskar"));
latch.finish();
setUsers.get();
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class TransactionIT method shouldTerminateQueriesEvenIfUsingPeriodicCommit.
@Test
public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception {
// Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
// and checks that the query able to be terminated
// We start with 3, because that is how many actors we have -
// 1. the http server
// 2. the running query
// 3. the one terminating 2
final DoubleLatch latch = new DoubleLatch(3, true);
// This is used to block the http server between the first and second batch
final Barrier.Control barrier = new Barrier.Control();
// Serve CSV via local web server, let Jetty find a random port for us
Server server = createHttpServer(latch, barrier, 20, 30);
server.start();
int localPort = getLocalPort(server);
final BoltStateMachine[] machine = { null };
Thread thread = new Thread() {
@Override
public void run() {
try (BoltStateMachine stateMachine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<writeServer>", 7468)))) {
machine[0] = stateMachine;
stateMachine.init(USER_AGENT, emptyMap(), null);
String query = format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + "CREATE (n:ShouldNotExist)", localPort);
try {
latch.start();
stateMachine.run(query, emptyMap(), nullResponseHandler());
stateMachine.pullAll(nullResponseHandler());
} finally {
latch.finish();
}
} catch (BoltConnectionFatality connectionFatality) {
throw new RuntimeException(connectionFatality);
}
}
};
thread.setName("query runner");
thread.start();
// We block this thread here, waiting for the http server to spin up and the running query to get started
latch.startAndWaitForAllToStart();
Thread.sleep(1000);
// This is the call that RESETs the Bolt connection and will terminate the running query
machine[0].reset(nullResponseHandler());
barrier.release();
// We block again here, waiting for the running query to have been terminated, and for the server to have
// wrapped up and finished streaming http results
latch.finishAndWaitForAllToFinish();
// And now we check that the last node did not get created
try (Transaction ignored = env.graph().beginTx()) {
assertFalse("Query was not terminated in time - nodes were created!", env.graph().findNodes(Label.label("ShouldNotExist")).hasNext());
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class AuthScenariosInteractionTestBase method roleManagement5.
/*
Admin creates user Henrik with password bar
Admin adds user Henrik to role Publisher
Henrik logs in with correct password
Henrik starts transaction with long running writing query Q
Admin removes user Henrik from role Publisher (while Q still running)
Q finishes and transaction is committed → ok
Henrik starts new transaction with write query → permission denied
*/
@Test
public void roleManagement5() throws Throwable {
assertEmpty(adminSubject, "CALL dbms.security.createUser('Henrik', 'bar', false)");
assertEmpty(adminSubject, "CALL dbms.security.addRoleToUser('" + PUBLISHER + "', 'Henrik')");
S henrik = neo.login("Henrik", "bar");
neo.assertAuthenticated(henrik);
DoubleLatch latch = new DoubleLatch(2);
ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
write.executeCreateNode(threading, henrik);
latch.startAndWaitForAllToStart();
assertEmpty(adminSubject, "CALL dbms.security.removeRoleFromUser('" + PUBLISHER + "', 'Henrik')");
latch.finishAndWaitForAllToFinish();
write.closeAndAssertSuccess();
testFailWrite(henrik);
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldTerminateAllTransactionsForGivenUser.
//@Test
public void shouldTerminateAllTransactionsForGivenUser() throws Throwable {
DoubleLatch latch = new DoubleLatch(3);
ThreadedTransaction<S> schema1 = new ThreadedTransaction<>(neo, latch);
ThreadedTransaction<S> schema2 = new ThreadedTransaction<>(neo, latch);
schema1.executeCreateNode(threading, schemaSubject);
schema2.executeCreateNode(threading, schemaSubject);
latch.startAndWaitForAllToStart();
assertSuccess(adminSubject, "CALL dbms.terminateTransactionsForUser( 'schemaSubject' )", r -> assertKeyIsMap(r, "username", "transactionsTerminated", map("schemaSubject", "2")));
assertSuccess(adminSubject, "CALL dbms.listTransactions()", r -> assertKeyIsMap(r, "username", "activeTransactions", map("adminSubject", "1")));
latch.finishAndWaitForAllToFinish();
schema1.closeAndAssertTransactionTermination();
schema2.closeAndAssertTransactionTermination();
assertEmpty(adminSubject, "MATCH (n:Test) RETURN n.name AS name");
}
Aggregations