Search in sources :

Example 31 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyNodeCommandToTheStoreAndInvalidateTheCache.

@Test
public void shouldApplyNodeCommandToTheStoreAndInvalidateTheCache() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final NodeRecord before = new NodeRecord(11);
    before.setLabelField(42, Arrays.asList(one, two));
    final NodeRecord after = new NodeRecord(12);
    after.setInUse(false);
    after.setLabelField(42, Arrays.asList(one, two, three));
    final Command.NodeCommand command = new Command.NodeCommand(before, after);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(lockService, times(1)).acquireNodeLock(command.getKey(), LockService.LockType.WRITE_LOCK);
    verify(nodeStore, times(1)).updateRecord(after);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 32 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier 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 33 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyRelPropertyCommandToTheStore.

@Test
public void shouldApplyRelPropertyCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final PropertyRecord before = new PropertyRecord(11);
    final PropertyRecord after = new PropertyRecord(12);
    after.setRelId(42);
    final Command command = new Command.PropertyCommand(before, after);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(propertyStore, times(1)).updateRecord(after);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 34 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setCreated();
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 35 with BatchTransactionApplier

use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyRelationshipGroupCommandToTheStore.

// RELATIONSHIP GROUP COMMAND
@Test
public void shouldApplyRelationshipGroupCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    // when
    final RelationshipGroupRecord before = new RelationshipGroupRecord(42, 1);
    final RelationshipGroupRecord after = new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true);
    final Command command = new Command.RelationshipGroupCommand(before, after);
    final boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(relationshipGroupStore, times(1)).updateRecord(after);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Aggregations

BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)45 Test (org.junit.Test)41 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)34 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)34 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)34 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)13 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)10 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)8 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)7 NeoStores (org.neo4j.kernel.impl.store.NeoStores)7 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)7 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)6 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)4 ArrayList (java.util.ArrayList)3 RelationshipTypeToken (org.neo4j.kernel.impl.core.RelationshipTypeToken)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BatchTransactionApplierFacade (org.neo4j.kernel.impl.api.BatchTransactionApplierFacade)2