use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldExtractUpdateCommandsInCorrectOrder.
@Test
public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable {
// GIVEN
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long nodeId = 0, relId1 = 1, relId2 = 2, relId3 = 3;
recordState.nodeCreate(nodeId);
recordState.relCreate(relId1, 0, nodeId, nodeId);
recordState.relCreate(relId2, 0, nodeId, nodeId);
recordState.nodeAddProperty(nodeId, 0, 101);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
recordState = newTransactionRecordState(neoStores);
recordState.nodeChangeProperty(nodeId, 0, 102);
recordState.relCreate(relId3, 0, nodeId, nodeId);
recordState.relAddProperty(relId1, 0, 123);
// WHEN
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
// THEN
Iterator<StorageCommand> commandIterator = commands.iterator();
// added rel property
assertCommand(commandIterator.next(), PropertyCommand.class);
// created relationship relId3
assertCommand(commandIterator.next(), RelationshipCommand.class);
// rest is updates...
assertCommand(commandIterator.next(), PropertyCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
assertCommand(commandIterator.next(), NodeCommand.class);
assertFalse(commandIterator.hasNext());
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldExtractCreatedCommandsInCorrectOrder.
@Test
public void shouldExtractCreatedCommandsInCorrectOrder() throws Throwable {
// GIVEN
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long nodeId = 0, relId = 1;
recordState.nodeCreate(nodeId);
recordState.relCreate(relId++, 0, nodeId, nodeId);
recordState.relCreate(relId, 0, nodeId, nodeId);
recordState.nodeAddProperty(nodeId, 0, 101);
// WHEN
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
// THEN
Iterator<StorageCommand> commandIterator = commands.iterator();
assertCommand(commandIterator.next(), PropertyCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
assertCommand(commandIterator.next(), NodeCommand.class);
assertFalse(commandIterator.hasNext());
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.
@Test
public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
TransactionRecordState recordState = newTransactionRecordState(neoStores);
int nodeId = 1;
recordState.nodeCreate(nodeId);
int propertyKey = 1;
Object value = 5;
// WHEN
recordState.nodeAddProperty(nodeId, propertyKey, value);
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
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 shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx.
@Test
public void shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx() throws Exception {
/*
* This test verifies that there are no transaction commands generated for a state diff that contains a
* relationship group that is created and deleted in this tx. This case requires special handling because
* relationship groups can be created and then deleted from disjoint code paths. Look at
* TransactionRecordState.extractCommands() for more details.
*
* The test setup looks complicated but all it does is mock properly a NeoStoreTransactionContext to
* return an Iterable<RecordSet< that contains a RelationshipGroup record which has been created in this
* tx and also is set notInUse.
*/
// Given:
// - dense node threshold of 5
// - node with 4 rels of type A and 1 rel of type B
NeoStores neoStore = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "5");
int A = 0, B = 1;
TransactionRecordState state = newTransactionRecordState(neoStore);
state.nodeCreate(0);
state.relCreate(0, A, 0, 0);
state.relCreate(1, A, 0, 0);
state.relCreate(2, A, 0, 0);
state.relCreate(3, A, 0, 0);
state.relCreate(4, B, 0, 0);
apply(neoStore, state);
// When doing a tx where a relationship of type A for the node is create and rel of type B is deleted
state = newTransactionRecordState(neoStore);
// here this node should be converted to dense and the groups should be created
state.relCreate(5, A, 0, 0);
// here the group B should be delete
state.relDelete(4);
// Then
Collection<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands);
RelationshipGroupCommand group = singleRelationshipGroupCommand(commands);
assertEquals(A, group.getAfter().getType());
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldExtractDeleteCommandsInCorrectOrder.
@Test
public void shouldExtractDeleteCommandsInCorrectOrder() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long nodeId1 = 0, nodeId2 = 1, relId1 = 1, relId2 = 2, relId4 = 10;
recordState.nodeCreate(nodeId1);
recordState.nodeCreate(nodeId2);
recordState.relCreate(relId1, 0, nodeId1, nodeId1);
recordState.relCreate(relId2, 0, nodeId1, nodeId1);
recordState.relCreate(relId4, 1, nodeId1, nodeId1);
recordState.nodeAddProperty(nodeId1, 0, 101);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
recordState = newTransactionRecordState(neoStores);
recordState.relDelete(relId4);
recordState.nodeDelete(nodeId2);
recordState.nodeRemoveProperty(nodeId1, 0);
// WHEN
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
// THEN
Iterator<StorageCommand> commandIterator = commands.iterator();
// updated rel group to not point to the deleted one below
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
// updated node to point to the group after the deleted one
assertCommand(commandIterator.next(), NodeCommand.class);
// rest is deletions below...
assertCommand(commandIterator.next(), PropertyCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
assertCommand(commandIterator.next(), NodeCommand.class);
assertFalse(commandIterator.hasNext());
}
Aggregations