use of org.neo4j.kernel.impl.api.TransactionApplier in project neo4j by neo4j.
the class CommandHandlerContract method apply.
/**
* In case the transactions do not have the commands to apply, use this method to apply any commands you want with a
* given {@link ApplyFunction} instead.
*
* @param applier to use
* @param function which knows what to do with the {@link TransactionApplier}.
* @param transactions are only used to create {@link TransactionApplier}s. The actual work is delegated to the
* function.
* @return the boolean-and result of all function operations.
*/
public static boolean apply(BatchTransactionApplier applier, ApplyFunction function, TransactionToApply... transactions) throws Exception {
boolean result = true;
for (TransactionToApply tx : transactions) {
try (TransactionApplier txApplier = applier.startTx(tx, new LockGroup())) {
result &= function.apply(txApplier);
}
}
applier.close();
return result;
}
use of org.neo4j.kernel.impl.api.TransactionApplier in project neo4j by neo4j.
the class IndexBatchTransactionApplierTest method shouldProvideLabelScanStoreUpdatesSortedByNodeId.
@Test
public void shouldProvideLabelScanStoreUpdatesSortedByNodeId() throws Exception {
// GIVEN
IndexingService indexing = mock(IndexingService.class);
LabelScanWriter writer = new OrderVerifyingLabelScanWriter(10, 15, 20);
WorkSync<Supplier<LabelScanWriter>, LabelUpdateWork> labelScanSync = spy(new WorkSync<>(singletonProvider(writer)));
WorkSync<IndexingService, IndexUpdatesWork> indexUpdatesSync = new WorkSync<>(indexing);
TransactionToApply tx = mock(TransactionToApply.class);
PropertyStore propertyStore = mock(PropertyStore.class);
try (IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier(indexing, labelScanSync, indexUpdatesSync, mock(NodeStore.class), mock(PropertyLoader.class), new PropertyPhysicalToLogicalConverter(propertyStore), TransactionApplicationMode.INTERNAL)) {
try (TransactionApplier txApplier = applier.startTx(tx)) {
// WHEN
txApplier.visitNodeCommand(node(15));
txApplier.visitNodeCommand(node(20));
txApplier.visitNodeCommand(node(10));
}
}
// THEN all assertions happen inside the LabelScanWriter#write and #close
verify(labelScanSync).apply(any());
}
use of org.neo4j.kernel.impl.api.TransactionApplier in project neo4j by neo4j.
the class NeoTransactionIndexApplierTest method shouldUpdateLabelStoreScanOnNodeCommands.
@Test
public void shouldUpdateLabelStoreScanOnNodeCommands() throws Exception {
// given
final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
final NodeRecord before = new NodeRecord(11);
before.setLabelField(17, emptyDynamicRecords);
final NodeRecord after = new NodeRecord(12);
after.setLabelField(18, emptyDynamicRecords);
final Command.NodeCommand command = new Command.NodeCommand(before, after);
when(labelScanStore.get()).thenReturn(mock(LabelScanWriter.class));
// when
boolean result;
try (TransactionApplier txApplier = applier.startTx(transactionToApply)) {
result = txApplier.visitNodeCommand(command);
}
// then
assertFalse(result);
}
use of org.neo4j.kernel.impl.api.TransactionApplier in project neo4j by neo4j.
the class NeoTransactionIndexApplierTest method shouldCreateIndexGivenCreateSchemaRuleCommand.
@Test
public void shouldCreateIndexGivenCreateSchemaRuleCommand() throws Exception {
// Given
final IndexRule indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR);
final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(emptyDynamicRecords, singleton(createdDynamicRecord(1)), indexRule);
// When
boolean result;
try (TransactionApplier txApplier = applier.startTx(transactionToApply)) {
result = txApplier.visitSchemaRuleCommand(command);
}
// Then
assertFalse(result);
verify(indexingService).createIndexes(indexRule);
}
use of org.neo4j.kernel.impl.api.TransactionApplier in project neo4j by neo4j.
the class NeoTransactionIndexApplierTest method shouldDropIndexGivenDropSchemaRuleCommand.
@Test
public void shouldDropIndexGivenDropSchemaRuleCommand() throws Exception {
// Given
final IndexRule indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR);
final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(createdDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule);
// When
boolean result;
try (TransactionApplier txApplier = applier.startTx(transactionToApply)) {
result = txApplier.visitSchemaRuleCommand(command);
}
// Then
assertFalse(result);
verify(indexingService).dropIndex(indexRule);
}
Aggregations