use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.
the class LogCommandSerializationV3_0_10 method readIndexAddRelationshipCommand.
@Override
protected Command readIndexAddRelationshipCommand(ReadableChannel channel) throws IOException {
IndexCommandHeader header = readIndexCommandHeader(channel);
Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt();
Object value = readIndexValue(header.valueType, channel);
Number startNode = header.startNodeNeedsLong ? channel.getLong() : channel.getInt();
Number endNode = header.endNodeNeedsLong ? channel.getLong() : channel.getInt();
AddRelationshipCommand command = new AddRelationshipCommand();
command.init(header.indexNameId, entityId.longValue(), header.keyId, value, startNode.longValue(), endNode.longValue());
return command;
}
use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.
the class PhysicalLogNeoCommandReaderTest method shouldProperlyMaskIndexIdFieldInIndexHeader.
@Test
void shouldProperlyMaskIndexIdFieldInIndexHeader() throws Exception {
/* This is how the index command header is laid out
* [x , ] start node needs long
* [ x , ] end node needs long
* [ xx,xxxx] index name id
* This means that the index name id can be in the range of 0 to 63. This test verifies that
* this constraint is actually respected
*/
// GIVEN
CommandReader reader = LogCommandSerializationV3_0_10.INSTANCE;
InMemoryClosableChannel data = new InMemoryClosableChannel();
// Here we take advantage of the fact that all index commands have the same header written out
AddRelationshipCommand command = new AddRelationshipCommand();
long entityId = 123;
byte keyId = (byte) 1;
Object value = "test value";
long startNode = 14;
long endNode = 15;
for (byte indexByteId = 0; indexByteId < 63; indexByteId++) {
// WHEN
command.init(indexByteId, entityId, keyId, value, startNode, endNode);
command.serialize(data);
// THEN
AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
assertEquals(indexByteId, readCommand.getIndexNameId());
assertEquals(entityId, readCommand.getEntityId());
assertEquals(keyId, readCommand.getKeyId());
assertEquals(value, readCommand.getValue());
assertEquals(startNode, readCommand.getStartNode());
assertEquals(endNode, readCommand.getEndNode());
data.reset();
}
}
use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.
the class PhysicalLogNeoCommandReaderTest method shouldReadIndexCommandHeaderCorrectly.
@Test
void shouldReadIndexCommandHeaderCorrectly() throws Exception {
// This bug manifested in header byte[1] {0,1,2}, which contains:
// [x , ] start node needs long
// [ x , ] end node needs long
// [ xx,xxxx] index name id
// would have the mask for reading "start node needs long" to 0x8, where it should have been 0x80.
// So we need an index name id which has the 0x8 bit set to falsely read that value as "true".
// Number 12 will do just fine.
// GIVEN
CommandReader reader = LogCommandSerializationV3_0_10.INSTANCE;
InMemoryClosableChannel data = new InMemoryClosableChannel();
AddRelationshipCommand command = new AddRelationshipCommand();
byte indexNameId = (byte) 12;
long entityId = 123;
byte keyId = (byte) 1;
Object value = "test value";
long startNode = 14;
long endNode = 15;
// WHEN
command.init(indexNameId, entityId, keyId, value, startNode, endNode);
command.serialize(data);
// THEN
AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
assertEquals(indexNameId, readCommand.getIndexNameId());
assertEquals(entityId, readCommand.getEntityId());
assertEquals(keyId, readCommand.getKeyId());
assertEquals(value, readCommand.getValue());
assertEquals(startNode, readCommand.getStartNode());
assertEquals(endNode, readCommand.getEndNode());
}
Aggregations