use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method preparingIndexRulesMustMarkSchemaRecordAsChanged.
@Test
void preparingIndexRulesMustMarkSchemaRecordAsChanged() 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);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
assertThat(commands.size()).isEqualTo(1);
SchemaRuleCommand command = (SchemaRuleCommand) commands.get(0);
assertThat(command.getMode()).isEqualTo(Command.Mode.CREATE);
assertThat(command.getSchemaRule()).isEqualTo(rule);
assertThat(command.getKey()).isEqualTo(ruleId);
assertThat(command.getBefore().inUse()).isEqualTo(false);
assertThat(command.getAfter().inUse()).isEqualTo(true);
assertThat(command.getAfter().isConstraint()).isEqualTo(false);
assertThat(command.getAfter().isCreated()).isEqualTo(true);
assertThat(command.getAfter().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class RecordStorageEngineTestUtils method applyLogicalChanges.
public static void applyLogicalChanges(RecordStorageEngine storageEngine, ThrowingBiConsumer<ReadableTransactionState, TxStateVisitor, Exception> changes) throws Exception {
ReadableTransactionState txState = mock(ReadableTransactionState.class);
doAnswer(invocationOnMock -> {
TxStateVisitor visitor = invocationOnMock.getArgument(0);
changes.accept(txState, visitor);
return null;
}).when(txState).accept(any());
List<StorageCommand> commands = new ArrayList<>();
NeoStores neoStores = storageEngine.testAccessNeoStores();
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
CursorContext cursorContext = CursorContext.NULL;
try (RecordStorageCommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(EmptyMemoryTracker.INSTANCE)) {
commandCreationContext.initialize(cursorContext);
storageEngine.createCommands(commands, txState, storageEngine.newReader(), commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, metaDataStore.getLastCommittedTransactionId(), t -> t, cursorContext, EmptyMemoryTracker.INSTANCE);
storageEngine.apply(new GroupOfCommands(metaDataStore.nextCommittingTransactionId(), commands.toArray(new StorageCommand[0])), TransactionApplicationMode.EXTERNAL);
}
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class LogCommandSerializationV4_0Test method readPropertyCommandWithSecondaryUnit.
@Test
void readPropertyCommandWithSecondaryUnit() throws IOException {
InMemoryClosableChannel channel = new InMemoryClosableChannel();
PropertyRecord before = new PropertyRecord(1);
PropertyRecord after = new PropertyRecord(1);
after.setSecondaryUnitIdOnCreate(78);
new Command.PropertyCommand(writer(), before, after).serialize(channel);
CommandReader reader = createReader();
StorageCommand command = reader.read(channel);
assertTrue(command instanceof Command.PropertyCommand);
Command.PropertyCommand propertyCommand = (Command.PropertyCommand) command;
// Then
assertBeforeAndAfterEquals(propertyCommand, before, after);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class LogCommandSerializationV4_0Test method readPropertyCommandWithNonRequiredSecondaryUnit.
@Test
void readPropertyCommandWithNonRequiredSecondaryUnit() throws IOException {
InMemoryClosableChannel channel = new InMemoryClosableChannel();
PropertyRecord before = new PropertyRecord(1);
PropertyRecord after = new PropertyRecord(1);
after.setSecondaryUnitIdOnCreate(78);
new Command.PropertyCommand(writer(), before, after).serialize(channel);
CommandReader reader = createReader();
StorageCommand command = reader.read(channel);
assertTrue(command instanceof Command.PropertyCommand);
Command.PropertyCommand propertyCommand = (Command.PropertyCommand) command;
// Then
assertBeforeAndAfterEquals(propertyCommand, before, after);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class LogCommandSerializationV4_3D_3Test method shouldReadRelationshipGroupExtendedCommandIncludingExternalDegrees.
@Test
void shouldReadRelationshipGroupExtendedCommandIncludingExternalDegrees() throws Throwable {
// Given
InMemoryClosableChannel channel = new InMemoryClosableChannel();
RelationshipGroupRecord before = new RelationshipGroupRecord(42).initialize(false, 3, NULL_REF, NULL_REF, NULL_REF, NULL_REF, NULL_REF);
RelationshipGroupRecord after = new RelationshipGroupRecord(42).initialize(true, (1 << Short.SIZE) + 10, 4, 5, 6, 7, 8);
after.setHasExternalDegreesOut(random.nextBoolean());
after.setHasExternalDegreesIn(random.nextBoolean());
after.setHasExternalDegreesLoop(random.nextBoolean());
after.setCreated();
new Command.RelationshipGroupCommand(writer(), before, after).serialize(channel);
// When
CommandReader reader = createReader();
StorageCommand command = reader.read(channel);
assertTrue(command instanceof Command.RelationshipGroupCommand);
Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
// Then
assertBeforeAndAfterEquals(relationshipGroupCommand, before, after);
}
Aggregations