use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class LogTruncationTest method testInMemoryLogChannel.
@Test
public void testInMemoryLogChannel() throws Exception {
InMemoryClosableChannel channel = new InMemoryClosableChannel();
for (int i = 0; i < 25; i++) {
channel.putInt(i);
}
for (int i = 0; i < 25; i++) {
assertEquals(i, channel.getInt());
}
channel.reset();
for (long i = 0; i < 12; i++) {
channel.putLong(i);
}
for (long i = 0; i < 12; i++) {
assertEquals(i, channel.getLong());
}
channel.reset();
for (long i = 0; i < 8; i++) {
channel.putLong(i);
channel.putInt((int) i);
}
for (long i = 0; i < 8; i++) {
assertEquals(i, channel.getLong());
assertEquals(i, channel.getInt());
}
channel.close();
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class PhysicalLogCommandReaderV3_0Test method readRelationshipGroupCommandWithNonRequiredSecondaryUnit.
@Test
public void readRelationshipGroupCommandWithNonRequiredSecondaryUnit() throws IOException {
// Given
InMemoryClosableChannel channel = new InMemoryClosableChannel();
RelationshipGroupRecord before = new RelationshipGroupRecord(42, 3);
RelationshipGroupRecord after = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);
after.setRequiresSecondaryUnit(false);
after.setSecondaryUnitId(17);
after.setCreated();
new Command.RelationshipGroupCommand(before, after).serialize(channel);
// When
PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
Command command = reader.read(channel);
assertTrue(command instanceof Command.RelationshipGroupCommand);
Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
// Then
assertEquals(before, relationshipGroupCommand.getBefore());
assertEquals(after, relationshipGroupCommand.getAfter());
verifySecondaryUnit(after, relationshipGroupCommand.getAfter());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class PhysicalLogNeoCommandReaderV2Test method shouldProperlyMaskIndexIdFieldInIndexHeader.
@Test
public 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
PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
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.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_1Test method shouldReadPropertyCommandWithDeletedDynamicRecords.
@Test
public void shouldReadPropertyCommandWithDeletedDynamicRecords() throws Exception {
// GIVEN
PhysicalLogCommandReaderV2_1 reader = new PhysicalLogCommandReaderV2_1();
InMemoryClosableChannel data = new InMemoryClosableChannel();
long id = 5;
int keyId = 6;
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
long value = 1234;
PropertyRecord property = new PropertyRecord(id);
property.setInUse(true);
property.addPropertyBlock(propertyBlockWithSomeDynamicRecords(keyId, STRING, value, data1, data2));
property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
// WHEN
new PropertyCommand(new PropertyRecord(id), property).serialize(data);
// THEN
PropertyCommand readCommand = (PropertyCommand) reader.read(data);
PropertyRecord readRecord = readCommand.getAfter();
assertEquals(id, readRecord.getId());
PropertyBlock readBlock = Iterables.single((Iterable<PropertyBlock>) readRecord);
assertArrayEquals(data1, readBlock.getValueRecords().get(0).getData());
assertArrayEquals(data2, readBlock.getValueRecords().get(1).getData());
assertEquals(2, readRecord.getDeletedRecords().size());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_2_4Test method shouldReadNoKeyIdAsMinusOne.
@Test
public void shouldReadNoKeyIdAsMinusOne() throws Exception {
// GIVEN
InMemoryClosableChannel channel = new InMemoryClosableChannel();
IndexDefineCommand definitions = new IndexDefineCommand();
int indexNameId = 10;
definitions.init(MapUtil.<String, Integer>genericMap("myindex", indexNameId), MapUtil.<String, Integer>genericMap());
definitions.serialize(channel);
RemoveCommand removeCommand = new IndexCommand.RemoveCommand();
removeCommand.init(indexNameId, IndexEntityType.Node.id(), 1234, -1, null);
removeCommand.serialize(channel);
// WHEN
PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
assertTrue(reader.read(channel) instanceof IndexDefineCommand);
RemoveCommand readRemoveCommand = (RemoveCommand) reader.read(channel);
// THEN
assertEquals(removeCommand.getIndexNameId(), readRemoveCommand.getIndexNameId());
assertEquals(removeCommand.getEntityType(), readRemoveCommand.getEntityType());
assertEquals(removeCommand.getEntityId(), readRemoveCommand.getEntityId());
assertEquals(removeCommand.getKeyId(), readRemoveCommand.getKeyId());
assertNull(removeCommand.getValue());
}
Aggregations