use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldValidateConstraintIndexAsPartOfExtraction.
@Test
public void shouldValidateConstraintIndexAsPartOfExtraction() throws Throwable {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
TransactionRecordState recordState = newTransactionRecordState(neoStores);
final long indexId = neoStores.getSchemaStore().nextId();
final long constraintId = neoStores.getSchemaStore().nextId();
recordState.createSchemaRule(constraintRule(constraintId, uniqueForLabel(1, 1), indexId));
// WHEN
recordState.extractCommands(new ArrayList<>());
// THEN
verify(integrityValidator).validateSchemaRule(any());
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDifferentTypes.
@Test
public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDifferentTypes() throws Exception {
// GIVEN a node with a total of denseNodeThreshold-1 relationships
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "50");
TransactionRecordState tx = newTransactionRecordState(neoStores);
long nodeId = neoStores.getNodeStore().nextId();
int typeA = 0, typeB = 1, typeC = 2;
tx.nodeCreate(nodeId);
tx.createRelationshipTypeToken("A", typeA);
createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 6);
createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 7);
tx.createRelationshipTypeToken("B", typeB);
createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 8);
createRelationships(neoStores, tx, nodeId, typeB, INCOMING, 9);
tx.createRelationshipTypeToken("C", typeC);
createRelationships(neoStores, tx, nodeId, typeC, OUTGOING, 10);
createRelationships(neoStores, tx, nodeId, typeC, INCOMING, 10);
// here we're at the edge
assertFalse(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
// WHEN creating the relationship that pushes us over the threshold
createRelationships(neoStores, tx, nodeId, typeC, INCOMING, 1);
// THEN the node should have been converted into a dense node
assertTrue(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 6, 7);
assertDenseRelationshipCounts(recordChangeSet, nodeId, typeB, 8, 9);
assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 10, 11);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction.
@Test
public void shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction() 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, which has first round-tripped through a log (written then read)
TransactionRepresentation transaction = transaction(deleteNode(store, nodeId.get()));
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
writeToChannel(transaction, channel);
CommittedTransactionRepresentation recoveredTransaction = readFromChannel(channel);
// and applying that recovered transaction
apply(applier, recoveredTransaction.getTransactionRepresentation());
// THEN should have the dynamic label record should be deleted as well
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates.
@Test
public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
addLabelsToNode(recordState, nodeId, bothLabelIds);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
removeLabelsFromNode(recordState, nodeId, secondLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).added(property2.propertyKeyId(), property2.value()).buildWithExistingProperties(property1, property2);
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldPrepareRelevantRecords.
@Test
public void shouldPrepareRelevantRecords() throws Exception {
// GIVEN
PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
NeoStores neoStores = neoStoresRule.open(format, GraphDatabaseSettings.dense_node_threshold.name(), "1");
// WHEN
TransactionRecordState state = newTransactionRecordState(neoStores);
state.nodeCreate(0);
state.relCreate(0, 0, 0, 0);
state.relCreate(1, 0, 0, 0);
state.relCreate(2, 0, 0, 0);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands);
// THEN
int nodes = 0, rels = 0, groups = 0;
for (StorageCommand command : commands) {
if (command instanceof NodeCommand) {
assertTrue(format.node().prepared(((NodeCommand) command).getAfter()));
nodes++;
} else if (command instanceof RelationshipCommand) {
assertTrue(format.relationship().prepared(((RelationshipCommand) command).getAfter()));
rels++;
} else if (command instanceof RelationshipGroupCommand) {
assertTrue(format.relationshipGroup().prepared(((RelationshipGroupCommand) command).getAfter()));
groups++;
}
}
assertEquals(1, nodes);
assertEquals(3, rels);
assertEquals(1, groups);
}
Aggregations