Search in sources :

Example 31 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class MeasureUpdatePullingRecordAndIndexGap method shouldMeasureThatGap.

@Test
public void shouldMeasureThatGap() throws Exception {
    // GIVEN
    ManagedCluster cluster = clusterRule.startCluster();
    createIndexes(cluster.getMaster());
    cluster.sync();
    awaitIndexes(cluster);
    final AtomicBoolean halter = new AtomicBoolean();
    AtomicLong[] highIdNodes = new AtomicLong[numberOfIndexes];
    CountDownLatch endLatch = new CountDownLatch(numberOfIndexes + 1);
    for (int i = 0; i < highIdNodes.length; i++) {
        highIdNodes[i] = new AtomicLong();
    }
    startLoadOn(cluster.getMaster(), halter, highIdNodes, endLatch);
    GraphDatabaseAPI slave = cluster.getAnySlave();
    startCatchingUp(slave, halter, endLatch);
    // WHEN measuring...
    final AtomicInteger good = new AtomicInteger(), bad = new AtomicInteger(), ugly = new AtomicInteger();
    startMeasuringTheGap(good, bad, ugly, halter, highIdNodes, slave);
    for (long endTime = currentTimeMillis() + SECONDS.toMillis(30); currentTimeMillis() < endTime; ) {
        printStats(good.get(), bad.get(), ugly.get());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    halter.set(true);
    endLatch.await();
    // THEN
    printStats(good.get(), bad.get(), ugly.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class TxPushStrategyConfigIT method twoRoundRobin.

@Test
public void twoRoundRobin() throws Exception {
    ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.round_robin);
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    Monitors monitors = master.getDependencyResolver().resolveDependency(Monitors.class);
    AtomicInteger totalMissedReplicas = new AtomicInteger();
    monitors.addMonitorListener((MasterTransactionCommitProcess.Monitor) totalMissedReplicas::addAndGet);
    long txId = getLastTx(master);
    int count = 15;
    for (int i = 0; i < count; i++) {
        createTransactionOnMaster(cluster);
    }
    long min = -1, max = -1;
    for (GraphDatabaseAPI db : cluster.getAllMembers()) {
        long tx = getLastTx(db);
        min = min == -1 ? tx : min(min, tx);
        max = max == -1 ? tx : max(max, tx);
    }
    assertEquals(txId + count, max);
    assertTrue("There should be members with transactions in the cluster", min != -1 && max != -1);
    int minLaggingBehindThreshold = 1 + /* this is the value without errors */
    totalMissedReplicas.get();
    assertThat("There should at most be a txId gap of 1 among the cluster members since the transaction pushing " + "goes in a round robin fashion. min:" + min + ", max:" + max, (int) (max - min), lessThanOrEqualTo(minLaggingBehindThreshold));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 33 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class LdapAuthIT method shouldBeAbleToUseProcedureAllowedAnnotationWithLdapGroupToRoleMapping.

@Test
public void shouldBeAbleToUseProcedureAllowedAnnotationWithLdapGroupToRoleMapping() throws Throwable {
    // When
    restartNeo4jServerWithOverriddenSettings(ldapOnlyAuthSettings.andThen(settings -> {
        settings.put(SecuritySettings.ldap_authorization_group_to_role_mapping, "500=role1");
    }));
    GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) server.graphDatabaseService();
    graphDatabaseAPI.getDependencyResolver().resolveDependency(Procedures.class).registerProcedure(ProcedureInteractionTestBase.ClassWithProcedures.class);
    assertAuth("neo", "abc123");
    assertAllowedReadProcedure();
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) CreateTransport(org.apache.directory.server.annotations.CreateTransport) EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) ContextEntry(org.apache.directory.server.core.annotations.ContextEntry) URL(java.net.URL) Status(org.neo4j.kernel.api.exceptions.Status) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer) RunMessage.run(org.neo4j.bolt.v1.messaging.message.RunMessage.run) LDAP_CONNECTION_TIMEOUT_CLIENT_MESSAGE(org.neo4j.server.security.enterprise.auth.LdapRealm.LDAP_CONNECTION_TIMEOUT_CLIENT_MESSAGE) CreatePartition(org.apache.directory.server.core.annotations.CreatePartition) SecuritySettings(org.neo4j.server.security.enterprise.configuration.SecuritySettings) StreamMatchers.eqRecord(org.neo4j.bolt.v1.runtime.spi.StreamMatchers.eqRecord) BaseInterceptor(org.apache.directory.server.core.api.interceptor.BaseInterceptor) Map(java.util.Map) MessageMatchers.msgRecord(org.neo4j.bolt.v1.messaging.util.MessageMatchers.msgRecord) LoadSchema(org.apache.directory.server.core.annotations.LoadSchema) Collections.emptyList(java.util.Collections.emptyList) TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) DoubleLatch(org.neo4j.test.DoubleLatch) Category(org.junit.experimental.categories.Category) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) JndiLdapContextFactory(org.apache.shiro.realm.ldap.JndiLdapContextFactory) LdapContext(javax.naming.ldap.LdapContext) InitMessage.init(org.neo4j.bolt.v1.messaging.message.InitMessage.init) EntryFilteringCursor(org.apache.directory.server.core.api.filtering.EntryFilteringCursor) SaslMechanism(org.apache.directory.server.annotations.SaslMechanism) EnterpriseAuthAndUserManager(org.neo4j.server.security.enterprise.auth.EnterpriseAuthAndUserManager) ProcedureInteractionTestBase(org.neo4j.server.security.enterprise.auth.ProcedureInteractionTestBase) TransportTestUtil(org.neo4j.bolt.v1.transport.integration.TransportTestUtil) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) RunWith(org.junit.runner.RunWith) CreateDS(org.apache.directory.server.core.annotations.CreateDS) Interceptor(org.apache.directory.server.core.api.interceptor.Interceptor) BasicAttribute(javax.naming.directory.BasicAttribute) ApplyLdifFiles(org.apache.directory.server.core.annotations.ApplyLdifFiles) LDAP_READ_TIMEOUT_CLIENT_MESSAGE(org.neo4j.server.security.enterprise.auth.LdapRealm.LDAP_READ_TIMEOUT_CLIENT_MESSAGE) LDAP_AUTHORIZATION_FAILURE_CLIENT_MESSAGE(org.neo4j.server.security.enterprise.auth.LdapRealm.LDAP_AUTHORIZATION_FAILURE_CLIENT_MESSAGE) PredefinedRoles(org.neo4j.server.security.enterprise.auth.plugin.api.PredefinedRoles) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LdapOperationErrorException(org.apache.directory.api.ldap.model.exception.LdapOperationErrorException) FrameworkRunner(org.apache.directory.server.core.integ.FrameworkRunner) Before(org.junit.Before) StartTlsHandler(org.apache.directory.server.ldap.handlers.extended.StartTlsHandler) SearchOperationContext(org.apache.directory.server.core.api.interceptor.context.SearchOperationContext) DirContext(javax.naming.directory.DirContext) Setting(org.neo4j.graphdb.config.Setting) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) Procedures(org.neo4j.kernel.impl.proc.Procedures) MessageMatchers.msgSuccess(org.neo4j.bolt.v1.messaging.util.MessageMatchers.msgSuccess) MessageMatchers.msgFailure(org.neo4j.bolt.v1.messaging.util.MessageMatchers.msgFailure) TransportTestUtil.eventuallyDisconnects(org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyDisconnects) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) TransportTestUtil.eventuallyReceives(org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives) PullAllMessage.pullAll(org.neo4j.bolt.v1.messaging.message.PullAllMessage.pullAll) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Procedures(org.neo4j.kernel.impl.proc.Procedures) ProcedureInteractionTestBase(org.neo4j.server.security.enterprise.auth.ProcedureInteractionTestBase) Test(org.junit.Test)

Example 34 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class LdapAuthIT method shouldKeepAuthorizationForLifetimeOfTransactionWithProcedureAllowed.

@Test
public void shouldKeepAuthorizationForLifetimeOfTransactionWithProcedureAllowed() throws Throwable {
    restartNeo4jServerWithOverriddenSettings(settings -> {
        settings.put(SecuritySettings.ldap_authorization_use_system_account, "false");
        settings.put(SecuritySettings.ldap_authorization_group_to_role_mapping, "503=admin;504=role1");
    });
    GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) server.graphDatabaseService();
    graphDatabaseAPI.getDependencyResolver().resolveDependency(Procedures.class).registerProcedure(ProcedureInteractionTestBase.ClassWithProcedures.class);
    DoubleLatch latch = new DoubleLatch(2);
    final Throwable[] threadFail = { null };
    Thread readerThread = new Thread(() -> {
        try {
            assertAuth("smith", "abc123");
            assertBeginTransactionSucceeds();
            assertAllowedReadProcedure();
            latch.startAndWaitForAllToStart();
            latch.finishAndWaitForAllToFinish();
            assertAllowedReadProcedure();
        } 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 : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Procedures(org.neo4j.kernel.impl.proc.Procedures) DoubleLatch(org.neo4j.test.DoubleLatch) ProcedureInteractionTestBase(org.neo4j.server.security.enterprise.auth.ProcedureInteractionTestBase) Test(org.junit.Test)

Example 35 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningShellPeriodicCommitQuery.

@Test
public void terminateLongRunningShellPeriodicCommitQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    GraphDatabaseShellServer shellServer = getGraphDatabaseShellServer(database);
    try {
        SameJvmClient client = getShellClient(shellServer);
        CollectingOutput commandOutput = new CollectingOutput();
        URL url = prepareTestImportFile(8);
        execute(shellServer, commandOutput, client.getId(), "USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();");
        fail("Transaction should be already terminated.");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("Transaction timeout."));
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : SameJvmClient(org.neo4j.shell.impl.SameJvmClient) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) CollectingOutput(org.neo4j.shell.impl.CollectingOutput) ShellException(org.neo4j.shell.ShellException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)133 Test (org.junit.Test)96 Transaction (org.neo4j.graphdb.Transaction)50 File (java.io.File)25 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)25 Node (org.neo4j.graphdb.Node)20 DependencyResolver (org.neo4j.graphdb.DependencyResolver)19 Config (org.neo4j.kernel.configuration.Config)15 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 IOException (java.io.IOException)8 PageCache (org.neo4j.io.pagecache.PageCache)8 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)8 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)6 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)6 Before (org.junit.Before)5 Label (org.neo4j.graphdb.Label)5 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)5