use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldListAllQueriesWhenRunningAsAdmin.
@SuppressWarnings("unchecked")
@Test
public void shouldListAllQueriesWhenRunningAsAdmin() 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 q2 = read2.execute(threading, writeSubject, "UNWIND [4,5,6] AS y RETURN y");
latch.startAndWaitForAllToStart();
String query = "CALL dbms.listQueries()";
assertSuccess(adminSubject, query, r -> {
Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
Matcher<Map<String, Object>> thisQuery = listedQueryOfInteractionLevel(startTime, "adminSubject", query);
Matcher<Map<String, Object>> matcher1 = listedQuery(startTime, "readSubject", q1);
Matcher<Map<String, Object>> matcher2 = listedQuery(startTime, "writeSubject", q2);
assertThat(maps, matchesOneToOneInAnyOrder(matcher1, matcher2, thisQuery));
});
latch.finishAndWaitForAllToFinish();
read1.closeAndAssertSuccess();
read2.closeAndAssertSuccess();
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class FileRoleRepositoryTest method shouldProvideRolesByUsernameEvenIfMidSetRoles.
@Test
public void shouldProvideRolesByUsernameEvenIfMidSetRoles() throws Throwable {
// Given
roleRepository = new FileRoleRepository(fs, roleFile, logProvider);
roleRepository.create(new RoleRecord("admin", "oskar"));
DoubleLatch latch = new DoubleLatch(2);
// When
Future<Object> setUsers = threading.execute(o -> {
roleRepository.setRoles(new HangingListSnapshot(latch, 10L, Collections.emptyList()));
return null;
}, null);
latch.startAndWaitForAllToStart();
// Then
assertThat(roleRepository.getRoleNamesByUsername("oskar"), containsInAnyOrder("admin"));
latch.finish();
setUsers.get();
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class LdapAuthIT method shouldKeepAuthorizationForLifetimeOfTransaction.
@Test
public void shouldKeepAuthorizationForLifetimeOfTransaction() throws Throwable {
restartNeo4jServerWithOverriddenSettings(settings -> {
settings.put(SecuritySettings.ldap_authorization_use_system_account, "false");
});
DoubleLatch latch = new DoubleLatch(2);
final Throwable[] threadFail = { null };
Thread readerThread = new Thread(() -> {
try {
assertAuth("neo", "abc123");
assertBeginTransactionSucceeds();
assertReadSucceeds();
latch.startAndWaitForAllToStart();
latch.finishAndWaitForAllToFinish();
assertReadSucceeds();
} catch (Throwable t) {
threadFail[0] = t;
// Always release the latch so we get the failure in the main thread
latch.start();
latch.finish();
}
});
readerThread.start();
latch.startAndWaitForAllToStart();
clearAuthCacheFromDifferentConnection();
latch.finishAndWaitForAllToFinish();
readerThread.join();
if (threadFail[0] != null) {
throw threadFail[0];
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class SchemaIndexWaitingAcceptanceTest method shouldTimeoutWatingForAllIndexesToComeOnline.
@Test
public void shouldTimeoutWatingForAllIndexesToComeOnline() throws Exception {
// given
GraphDatabaseService db = rule.getGraphDatabaseAPI();
DoubleLatch latch = provider.installPopulationJobCompletionLatch();
try (Transaction tx = db.beginTx()) {
db.schema().indexFor(Label.label("Person")).on("name").create();
tx.success();
}
latch.waitForAllToStart();
// when
try (Transaction tx = db.beginTx()) {
// then
db.schema().awaitIndexesOnline(1, TimeUnit.MILLISECONDS);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
// good
assertThat(e.getMessage(), containsString("come online"));
} finally {
latch.finish();
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class SchemaIndexWaitingAcceptanceTest method shouldTimeoutWatingForIndexToComeOnline.
@Test
public void shouldTimeoutWatingForIndexToComeOnline() throws Exception {
// given
GraphDatabaseService db = rule.getGraphDatabaseAPI();
DoubleLatch latch = provider.installPopulationJobCompletionLatch();
IndexDefinition index;
try (Transaction tx = db.beginTx()) {
index = db.schema().indexFor(Label.label("Person")).on("name").create();
tx.success();
}
latch.waitForAllToStart();
// when
try (Transaction tx = db.beginTx()) {
// then
db.schema().awaitIndexOnline(index, 1, TimeUnit.MILLISECONDS);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
// good
assertThat(e.getMessage(), containsString("come online"));
} finally {
latch.finish();
}
}
Aggregations