use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldSortRelationshipGroups.
@Test
public void shouldSortRelationshipGroups() throws Throwable {
// GIVEN
int type5 = 5, type10 = 10, type15 = 15;
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
neoStores.getRelationshipTypeTokenStore().setHighId(16);
recordState.createRelationshipTypeToken("5", type5);
recordState.createRelationshipTypeToken("10", type10);
recordState.createRelationshipTypeToken("15", type15);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
}
long nodeId = neoStores.getNodeStore().nextId();
{
long otherNode1Id = neoStores.getNodeStore().nextId();
long otherNode2Id = neoStores.getNodeStore().nextId();
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeCreate(otherNode1Id);
recordState.nodeCreate(otherNode2Id);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode1Id);
// This relationship will cause the switch to dense
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode2Id);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// Just a little validation of assumptions
assertRelationshipGroupsInOrder(neoStores, nodeId, type10);
}
// WHEN inserting a relationship of type 5
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long otherNodeId = neoStores.getNodeStore().nextId();
recordState.nodeCreate(otherNodeId);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// THEN that group should end up first in the chain
assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10);
}
// WHEN inserting a relationship of type 15
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long otherNodeId = neoStores.getNodeStore().nextId();
recordState.nodeCreate(otherNodeId);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// THEN that group should end up last in the chain
assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10, type15);
}
}
use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldInvalidateTheCacheWhenTheNodeBecomesDense.
@Test
public void shouldInvalidateTheCacheWhenTheNodeBecomesDense() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(false);
final NodeRecord before = new NodeRecord(11);
before.setLabelField(42, Arrays.asList(one));
before.setInUse(true);
before.setDense(false);
final NodeRecord after = new NodeRecord(12);
after.setInUse(true);
after.setDense(true);
after.setLabelField(42, Arrays.asList(one, two, three));
final Command.NodeCommand command = new Command.NodeCommand(before, after);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(lockService, times(1)).acquireNodeLock(command.getKey(), LockService.LockType.WRITE_LOCK);
verify(nodeStore, times(1)).updateRecord(after);
}
use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore.
@Test
public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(false);
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
record.setCreated();
final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(schemaStore, times(1)).updateRecord(record);
verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
verify(cacheAccess, times(1)).addSchemaRule(rule);
}
use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore.
@Test
public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(false);
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
record.setInUse(false);
final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(schemaStore, times(1)).updateRecord(record);
verify(metaDataStore, never()).setLatestConstraintIntroducingTx(transactionId);
verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
use of org.neo4j.kernel.impl.api.BatchTransactionApplier in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyNeoStoreCommandToTheStoreInRecovery.
@Test
public void shouldApplyNeoStoreCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
final NeoStoreRecord before = new NeoStoreRecord();
final NeoStoreRecord after = new NeoStoreRecord();
after.setNextProp(42);
final Command command = new Command.NeoStoreCommand(before, after);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(metaDataStore, times(1)).setGraphNextProp(after.getNextProp());
}
Aggregations