use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class RecordChangeSetTest method shouldClearStateOnClose.
@Test
public void shouldClearStateOnClose() throws Exception {
// GIVEN
NeoStores mockStore = mock(NeoStores.class);
when(mockStore.getNodeStore()).thenReturn(mock(NodeStore.class));
when(mockStore.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
when(mockStore.getPropertyStore()).thenReturn(mock(PropertyStore.class));
when(mockStore.getSchemaStore()).thenReturn(mock(SchemaStore.class));
when(mockStore.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
RecordChangeSet changeSet = new RecordChangeSet(new Loaders(mockStore));
// WHEN
/*
* We need to make sure some stuff is stored in the sets being managed. That is why forChangingLinkage() is
* called - otherwise, no changes will be stored and changeSize() would return 0 anyway.
*/
changeSet.getNodeRecords().create(1L, null).forChangingLinkage();
changeSet.getPropertyRecords().create(1L, null).forChangingLinkage();
changeSet.getRelRecords().create(1L, null).forChangingLinkage();
changeSet.getSchemaRuleChanges().create(1L, null).forChangingLinkage();
changeSet.getRelGroupRecords().create(1L, 1).forChangingLinkage();
changeSet.close();
// THEN
assertEquals(0, changeSet.getNodeRecords().changeSize());
assertEquals(0, changeSet.getPropertyRecords().changeSize());
assertEquals(0, changeSet.getRelRecords().changeSize());
assertEquals(0, changeSet.getSchemaRuleChanges().changeSize());
assertEquals(0, changeSet.getRelGroupRecords().changeSize());
}
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));
}
Aggregations