use of org.neo4j.test.Barrier in project neo4j by neo4j.
the class IdBufferingRoleSwitchIT method shouldNotSeeFreedIdsCrossRoleSwitch.
@Test
public void shouldNotSeeFreedIdsCrossRoleSwitch() throws Throwable {
// GIVEN
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase firstMaster = cluster.getMaster();
// WHEN
// a node with a property
Node node = createNodeWithProperties(firstMaster, 1);
// sync cluster
cluster.sync();
// a transaction on master which deletes the property
deleteNode(node, firstMaster);
triggerIdMaintenance(firstMaster);
// <-- this one reuses the same property id 0
createNodeWithProperties(firstMaster, 1);
// a transaction T on slave which will be kept open using a barrier
GraphDatabaseAPI slave = cluster.getAnySlave();
Barrier.Control barrier = new Barrier.Control();
Future<Void> t = t2.execute(barrierControlledReadTransaction(slave, barrier));
// pull updates on slave
barrier.await();
slave.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
// a role switch
cluster.shutdown(firstMaster);
cluster.await(masterAvailable(firstMaster));
// close T
barrier.release();
t.get();
triggerIdMaintenance(slave);
// THEN the deleted property record should now not be in freelist on new master
// <-- this transaction should introduce inconsistencies
createNodeWithProperties(slave, 10);
// <-- CC will be run here since that's configured above ^^^
cluster.stop();
}
use of org.neo4j.test.Barrier in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldTerminateQueriesEvenIfUsingPeriodicCommit.
@SuppressWarnings("unchecked")
@Test
public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Throwable {
for (int batchSize = 8; batchSize <= 11; batchSize++) {
// Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
// and checks that the query is visible when using listQueries()
// Given
final DoubleLatch latch = new DoubleLatch(3, true);
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, batchSize, 50 - batchSize);
server.start();
int localPort = getLocalPort(server);
// When
ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
try {
String writeQuery = write.executeEarly(threading, writeSubject, KernelTransaction.Type.implicit, format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line ", localPort) + "CREATE (n:A {id: line[0], square: line[1]}) RETURN count(*)");
latch.startAndWaitForAllToStart();
// Then
String writeQueryId = extractQueryId(writeQuery);
assertSuccess(adminSubject, "CALL dbms.killQuery('" + writeQueryId + "') YIELD username " + "RETURN count(username) AS count, username", r -> {
List<Map<String, Object>> actual = r.stream().collect(toList());
Matcher<Map<String, Object>> mapMatcher = allOf((Matcher) hasEntry(equalTo("count"), anyOf(equalTo(1), equalTo(1L))), (Matcher) hasEntry(equalTo("username"), equalTo("writeSubject")));
assertThat(actual, matchesOneToOneInAnyOrder(mapMatcher));
});
} finally {
// When
barrier.release();
latch.finishAndWaitForAllToFinish();
// Then
write.closeAndAssertTransactionTermination();
// stop server after assertion to avoid other kind of failures due to races (e.g., already closed
// lock clients )
server.stop();
}
}
}
use of org.neo4j.test.Barrier in project neo4j by neo4j.
the class BackupServiceIT method shouldContainTransactionsThatHappenDuringBackupProcess.
@Test
public void shouldContainTransactionsThatHappenDuringBackupProcess() throws Throwable {
// given
defaultBackupPortHostParams();
Config defaultConfig = dbRule.getConfigCopy();
dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
Config withOnlineBackupDisabled = dbRule.getConfigCopy();
final Barrier.Control barrier = new Barrier.Control();
final GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
// create some data
createAndIndexNode(db, 1);
final DependencyResolver resolver = db.getDependencyResolver();
long expectedLastTxId = resolver.resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
// This monitor is added server-side...
monitors.addMonitorListener(new StoreSnoopingMonitor(barrier));
Dependencies dependencies = new Dependencies(resolver);
dependencies.satisfyDependencies(defaultConfig, monitors, NullLogProvider.getInstance());
OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
backup.start();
// when
BackupService backupService = backupService();
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
barrier.awaitUninterruptibly();
createAndIndexNode(db, 1);
resolver.resolveDependency(StorageEngine.class).flushAndForce(limiter);
barrier.release();
});
BackupService.BackupOutcome backupOutcome = backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
backup.stop();
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
// then
checkPreviousCommittedTxIdFromLog(0, expectedLastTxId);
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long txIdFromOrigin = MetaDataStore.getRecord(resolver.resolveDependency(PageCache.class), neoStore, Position.LAST_TRANSACTION_ID);
checkLastCommittedTxIdInLogAndNeoStore(expectedLastTxId + 1, txIdFromOrigin);
assertEquals(DbRepresentation.of(db), getBackupDbRepresentation());
assertTrue(backupOutcome.isConsistent());
}
use of org.neo4j.test.Barrier in project neo4j by neo4j.
the class DeferringLocksIT method removeNodeChangeNodeProperty.
@Test(timeout = TEST_TIMEOUT)
public void removeNodeChangeNodeProperty() throws Exception {
// GIVEN
final Barrier.Control barrier = new Barrier.Control();
final long nodeId;
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
nodeId = node.getId();
node.setProperty(PROPERTY_KEY, VALUE_1);
tx.success();
}
// WHEN
Future<Void> future = t2.execute(new WorkerCommand<Void, Void>() {
@Override
public Void doWork(Void state) throws Exception {
try (Transaction tx = db.beginTx()) {
db.getNodeById(nodeId).delete();
tx.success();
barrier.reached();
}
return null;
}
});
try {
try (Transaction tx = db.beginTx()) {
barrier.await();
db.getNodeById(nodeId).setProperty(PROPERTY_KEY, VALUE_2);
tx.success();
barrier.release();
}
} catch (TransactionFailureException e) {
// Node was already deleted, fine.
assertThat(e.getCause(), instanceOf(InvalidRecordException.class));
}
future.get();
try (Transaction tx = db.beginTx()) {
try {
db.getNodeById(nodeId);
assertEquals(VALUE_2, db.getNodeById(nodeId).getProperty(PROPERTY_KEY, VALUE_2));
} catch (NotFoundException e) {
// Fine, its gone
}
tx.success();
}
}
use of org.neo4j.test.Barrier in project neo4j by neo4j.
the class DeferringLocksIT method firstRemoveSecondChangeProperty.
@Test(timeout = TEST_TIMEOUT)
public void firstRemoveSecondChangeProperty() throws Exception {
// GIVEN
final Barrier.Control barrier = new Barrier.Control();
final Node node;
try (Transaction tx = db.beginTx()) {
node = db.createNode();
node.setProperty(PROPERTY_KEY, VALUE_1);
tx.success();
}
// WHEN
Future<Void> future = t2.execute(new WorkerCommand<Void, Void>() {
@Override
public Void doWork(Void state) throws Exception {
try (Transaction tx = db.beginTx()) {
node.removeProperty(PROPERTY_KEY);
tx.success();
barrier.reached();
}
return null;
}
});
try (Transaction tx = db.beginTx()) {
barrier.await();
node.setProperty(PROPERTY_KEY, VALUE_2);
tx.success();
barrier.release();
}
future.get();
try (Transaction tx = db.beginTx()) {
assertEquals(VALUE_2, node.getProperty(PROPERTY_KEY, VALUE_2));
tx.success();
}
}
Aggregations