use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class NeoStoresTest method commitTx.
private void commitTx() throws Exception {
try (CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE)) {
CursorContext cursorContext = NULL;
commandCreationContext.initialize(cursorContext);
List<StorageCommand> commands = new ArrayList<>();
storageEngine.createCommands(commands, transactionState, storageReader, commandCreationContext, IGNORE, NONE, storageEngine.testAccessNeoStores().getMetaDataStore().getLastClosedTransactionId(), tx -> tx, cursorContext, INSTANCE);
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(EMPTY_BYTE_ARRAY, -1, -1, -1, -1, AUTH_DISABLED);
storageEngine.apply(new TransactionToApply(tx, cursorContext), INTERNAL);
}
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class RecordStorageEngineTest method shouldCloseLockGroupAfterAppliers.
@Test
void shouldCloseLockGroupAfterAppliers() throws Exception {
// given
long nodeId = 5;
LockService lockService = mock(LockService.class);
Lock nodeLock = mock(Lock.class);
when(lockService.acquireNodeLock(nodeId, EXCLUSIVE)).thenReturn(nodeLock);
// <-- simply so that we can use InOrder mockito construct
Consumer<Boolean> applierCloseCall = mock(Consumer.class);
CapturingTransactionApplierFactoryChain applier = new CapturingTransactionApplierFactoryChain(applierCloseCall);
RecordStorageEngine engine = recordStorageEngineBuilder().lockService(lockService).transactionApplierTransformer(applier::wrapAroundActualApplier).build();
CommandsToApply commandsToApply = mock(CommandsToApply.class);
when(commandsToApply.cursorContext()).thenReturn(NULL);
when(commandsToApply.accept(any())).thenAnswer(invocationOnMock -> {
// Visit one node command
Visitor<StorageCommand, IOException> visitor = invocationOnMock.getArgument(0);
NodeRecord after = new NodeRecord(nodeId);
after.setInUse(true);
visitor.visit(new Command.NodeCommand(new NodeRecord(nodeId), after));
return null;
});
// when
engine.apply(commandsToApply, TransactionApplicationMode.INTERNAL);
// then
InOrder inOrder = inOrder(lockService, applierCloseCall, nodeLock);
inOrder.verify(lockService).acquireNodeLock(nodeId, EXCLUSIVE);
inOrder.verify(applierCloseCall).accept(true);
inOrder.verify(nodeLock).release();
inOrder.verifyNoMoreInteractions();
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method deletingSchemaRuleMustAlsoDeletePropertyChain.
@Test
void deletingSchemaRuleMustAlsoDeletePropertyChain() throws Exception {
neoStores = createStores();
TransactionRecordState state = newTransactionRecordState();
long ruleId = neoStores.getSchemaStore().nextId(NULL);
IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
state.schemaRuleCreate(ruleId, false, rule);
state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
apply(state);
state = newTransactionRecordState();
state.schemaRuleDelete(ruleId, rule);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
assertThat(commands.size()).isEqualTo(2);
// Order matters. Rule deletes before property deletes.
SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(0);
assertThat(schemaCmd.getKey()).isEqualTo(ruleId);
assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
assertThat(schemaCmd.getAfter().inUse()).isEqualTo(false);
PropertyCommand propCmd = (PropertyCommand) commands.get(1);
assertThat(propCmd.getKey()).isEqualTo(schemaCmd.getBefore().getNextProp());
assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
assertThat(propCmd.getAfter().inUse()).isEqualTo(false);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.
@Test
void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
neoStores = createStores();
// GIVEN
TransactionRecordState recordState = newTransactionRecordState();
int nodeId = 1;
recordState.nodeCreate(nodeId);
// WHEN
recordState.nodeAddProperty(nodeId, propertyId1, value1);
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands, INSTANCE);
PropertyCommand propertyCommand = singlePropertyCommand(commands);
// THEN
PropertyRecord before = propertyCommand.getBefore();
assertFalse(before.inUse());
assertFalse(before.iterator().hasNext());
PropertyRecord after = propertyCommand.getAfter();
assertTrue(after.inUse());
assertEquals(1, count(after));
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges.
@Test
void settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges() throws Exception {
neoStores = createStores();
TransactionRecordState state = newTransactionRecordState();
long ruleId = neoStores.getSchemaStore().nextId(NULL);
IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
state.schemaRuleCreate(ruleId, false, rule);
apply(state);
state = newTransactionRecordState();
state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
assertThat(commands.size()).isEqualTo(2);
// Order matters. Props added before schema.
PropertyCommand propCmd = (PropertyCommand) commands.get(0);
assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
assertThat(propCmd.getBefore().inUse()).isEqualTo(false);
assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
assertThat(propCmd.getAfter().isCreated()).isEqualTo(true);
assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
apply(transaction(commands));
state = newTransactionRecordState();
state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(false), rule);
commands.clear();
state.extractCommands(commands, INSTANCE);
assertThat(commands.size()).isEqualTo(1);
propCmd = (PropertyCommand) commands.get(0);
assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
assertThat(propCmd.getAfter().isCreated()).isEqualTo(false);
}
Aggregations