use of org.neo4j.kernel.impl.store.NeoStores 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.kernel.impl.store.NeoStores 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.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNode.
@Test
public void shouldDeleteDynamicLabelsForDeletedNode() throws Throwable {
// GIVEN a store that has got a node with a dynamic label record
NeoStores store = neoStoresRule.open();
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
AtomicLong nodeId = new AtomicLong();
AtomicLong dynamicLabelRecordId = new AtomicLong();
apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
// WHEN applying a transaction where the node is deleted
apply(applier, transaction(deleteNode(store, nodeId.get())));
// THEN the dynamic label record should also be deleted
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode.
@Test
public void shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode() throws Exception {
/* There was an issue where recovering a tx where a node with a label and a property
* was created resulted in two exact copies of NodePropertyUpdates. */
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
int labelId = 5, propertyKeyId = 7;
// -- an index
long ruleId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
SchemaRule rule = indexRule(ruleId, forLabel(labelId, propertyKeyId), PROVIDER_DESCRIPTOR);
recordState.createSchemaRule(rule);
apply(neoStores, recordState);
// -- and a tx creating a node with that label and property key
recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.addLabelToNode(labelId, nodeId);
recordState.nodeAddProperty(nodeId, propertyKeyId, "Neo");
// WHEN
PhysicalTransactionRepresentation transaction = transactionRepresentationOf(recordState);
NodePropertyCommandsExtractor extractor = new NodePropertyCommandsExtractor();
transaction.accept(extractor);
// THEN
// -- later recovering that tx, there should be only one update
assertTrue(extractor.containsAnyNodeOrPropertyUpdate());
PrimitiveLongSet recoveredNodeIds = Primitive.longSet();
recoveredNodeIds.addAll(extractor.nodeCommandsById().iterator());
recoveredNodeIds.addAll(extractor.propertyCommandsByNodeIds().iterator());
assertEquals(1, recoveredNodeIds.size());
assertEquals(nodeId, recoveredNodeIds.iterator().next());
}
use of org.neo4j.kernel.impl.store.NeoStores 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());
}
Aggregations