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