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