Search in sources :

Example 36 with DoubleLatch

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();
}
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 37 with DoubleLatch

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();
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 38 with DoubleLatch

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];
    }
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 39 with DoubleLatch

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();
    }
}
Also used : DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 40 with DoubleLatch

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();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

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