use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.
the class NodeRecordCheckTest method shouldReportDynamicLabelsNotInUse.
@Test
public void shouldReportDynamicLabelsNotInUse() throws Exception {
// given
long[] labelIds = createLabels(100);
LabelTokenRecord labelRecordNotInUse = notInUse(new LabelTokenRecord(labelIds.length));
add(labelRecordNotInUse);
NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
add(node);
DynamicRecord labelsRecord1 = inUse(array(new DynamicRecord(1)));
DynamicRecord labelsRecord2 = inUse(array(new DynamicRecord(2)));
Collection<DynamicRecord> labelRecords = asList(labelsRecord1, labelsRecord2);
labelIds[12] = labelIds.length;
DynamicArrayStore.allocateFromNumbers(new ArrayList<>(), labelIds, new ReusableRecordsAllocator(52, labelRecords));
assertDynamicRecordChain(labelsRecord1, labelsRecord2);
node.setLabelField(DynamicNodeLabels.dynamicPointer(labelRecords), labelRecords);
addNodeDynamicLabels(labelsRecord1);
addNodeDynamicLabels(labelsRecord2);
// when
ConsistencyReport.NodeConsistencyReport report = check(node);
// then
verify(report).labelNotInUse(labelRecordNotInUse);
}
use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.
the class NodeRecordCheckTest method shouldProperlyReportOutOfOrderLabelsThatAreFarAway.
@Test
public void shouldProperlyReportOutOfOrderLabelsThatAreFarAway() throws Exception {
// given
final NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
// We need to do this override so we can put the labels unsorted, since InlineNodeLabels always sorts on insert
new InlineNodeLabels(node) {
@Override
public Collection<DynamicRecord> put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
return putSorted(node, labelIds, nodeStore, allocator);
}
}.put(new long[] { 1, 18, 13, 14, 15, 16, 12 }, null, null);
LabelTokenRecord label1 = inUse(new LabelTokenRecord(1));
LabelTokenRecord label12 = inUse(new LabelTokenRecord(12));
LabelTokenRecord label13 = inUse(new LabelTokenRecord(13));
LabelTokenRecord label14 = inUse(new LabelTokenRecord(14));
LabelTokenRecord label15 = inUse(new LabelTokenRecord(15));
LabelTokenRecord label16 = inUse(new LabelTokenRecord(16));
LabelTokenRecord label18 = inUse(new LabelTokenRecord(18));
add(label1);
add(label12);
add(label13);
add(label14);
add(label15);
add(label16);
add(label18);
add(node);
// when
ConsistencyReport.NodeConsistencyReport report = check(node);
// then
verify(report).labelsOutOfOrder(18, 13);
verify(report).labelsOutOfOrder(16, 12);
}
use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.
the class ReplicatedTokenHolderTest method mockedStorageEngine.
@SuppressWarnings("unchecked")
private StorageEngine mockedStorageEngine() throws Exception {
StorageEngine storageEngine = mock(StorageEngine.class);
doAnswer(invocation -> {
Collection<StorageCommand> target = invocation.getArgumentAt(0, Collection.class);
ReadableTransactionState txState = invocation.getArgumentAt(1, ReadableTransactionState.class);
txState.accept(new TxStateVisitor.Adapter() {
@Override
public void visitCreatedLabelToken(String name, int id) {
LabelTokenRecord before = new LabelTokenRecord(id);
LabelTokenRecord after = before.clone();
after.setInUse(true);
target.add(new Command.LabelTokenCommand(before, after));
}
});
return null;
}).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
StoreReadLayer readLayer = mock(StoreReadLayer.class);
when(readLayer.newStatement()).thenReturn(mock(StorageStatement.class));
when(storageEngine.storeReadLayer()).thenReturn(readLayer);
return storageEngine;
}
use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.
the class CoreReplicatedContentMarshalTest method shouldMarshalTokenRequest.
@Test
public void shouldMarshalTokenRequest() throws Exception {
ByteBuf buffer = Unpooled.buffer();
ArrayList<StorageCommand> commands = new ArrayList<>();
LabelTokenRecord before = new LabelTokenRecord(0);
LabelTokenRecord after = new LabelTokenRecord(0);
after.setInUse(true);
after.setCreated();
after.setNameId(3232);
commands.add(new Command.LabelTokenCommand(before, after));
ReplicatedContent message = new ReplicatedTokenRequest(TokenType.LABEL, "theLabel", ReplicatedTokenRequestSerializer.commandBytes(commands));
assertMarshalingEquality(buffer, message);
}
use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyLabelTokenCommandToTheStoreInRecovery.
@Test
public void shouldApplyLabelTokenCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
final LabelTokenRecord before = new LabelTokenRecord(42);
final LabelTokenRecord after = new LabelTokenRecord(42);
after.setInUse(true);
after.setNameId(323);
final Command.LabelTokenCommand command = new Command.LabelTokenCommand(before, after);
final Token token = new Token("token", 21);
when(labelTokenStore.getToken((int) command.getKey())).thenReturn(token);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(labelTokenStore, times(1)).setHighestPossibleIdInUse(after.getId());
verify(labelTokenStore, times(1)).updateRecord(after);
verify(cacheAccess, times(1)).addLabelToken(token);
}
Aggregations