Search in sources :

Example 1 with TransactionApplier

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;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier)

Example 2 with TransactionApplier

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());
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) WorkSync(org.neo4j.concurrent.WorkSync) PropertyPhysicalToLogicalConverter(org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) PropertyLoader(org.neo4j.kernel.impl.transaction.state.PropertyLoader) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Supplier(java.util.function.Supplier) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 3 with TransactionApplier

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);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 4 with TransactionApplier

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);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) Test(org.junit.Test)

Example 5 with TransactionApplier

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);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) Test(org.junit.Test)

Aggregations

TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)5 Test (org.junit.Test)4 LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)2 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)2 Supplier (java.util.function.Supplier)1 WorkSync (org.neo4j.concurrent.WorkSync)1 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)1 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)1 PropertyPhysicalToLogicalConverter (org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter)1 LockGroup (org.neo4j.kernel.impl.locking.LockGroup)1 NodeStore (org.neo4j.kernel.impl.store.NodeStore)1 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 PropertyLoader (org.neo4j.kernel.impl.transaction.state.PropertyLoader)1