use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class SegmentHeaderTest method shouldThrowExceptionWhenReadingIncompleteHeader.
@Test
public void shouldThrowExceptionWhenReadingIncompleteHeader() throws Exception {
// given
long prevFileLastIndex = 1;
long version = 2;
long prevIndex = 3;
long prevTerm = 4;
SegmentHeader writtenHeader = new SegmentHeader(prevFileLastIndex, version, prevIndex, prevTerm);
InMemoryClosableChannel channel = new InMemoryClosableChannel();
channel.putLong(writtenHeader.version());
channel.putLong(writtenHeader.prevIndex());
// when
try {
marshal.unmarshal(channel);
fail();
} catch (EndOfStreamException e) {
// expected
}
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class PhysicalLogNeoCommandReaderV2Test method shouldReadIndexCommandHeaderCorrectly.
@Test
public 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
PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
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());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class LogEntryParserDispatcherV6Test method shouldParserStartEntry.
@Test
public void shouldParserStartEntry() throws IOException {
// given
final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[] { 5 }, position);
final InMemoryClosableChannel channel = new InMemoryClosableChannel();
channel.putInt(start.getMasterId());
channel.putInt(start.getLocalId());
channel.putLong(start.getTimeWritten());
channel.putLong(start.getLastCommittedTxWhenTransactionStarted());
channel.putInt(start.getAdditionalHeader().length);
channel.put(start.getAdditionalHeader(), start.getAdditionalHeader().length);
channel.getCurrentPosition(marker);
// when
final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_START);
final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
// then
assertEquals(start, logEntry);
assertFalse(parser.skip());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class LogEntryParserDispatcherV6Test method shouldParserOnePhaseCommitEntry.
@Test
public void shouldParserOnePhaseCommitEntry() throws IOException {
// given
final LogEntryCommit commit = new OnePhaseCommit(version, 42, 21);
final InMemoryClosableChannel channel = new InMemoryClosableChannel();
channel.putLong(commit.getTxId());
channel.putLong(commit.getTimeWritten());
channel.getCurrentPosition(marker);
// when
final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_1P_COMMIT);
final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
// then
assertEquals(commit, logEntry);
assertFalse(parser.skip());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class LogEntryParserDispatcherV6Test method shouldParseEmptyEntry.
@Test
public void shouldParseEmptyEntry() throws IOException {
// when
final LogEntryParser parser = version.entryParser(LogEntryByteCodes.EMPTY);
final LogEntry logEntry = parser.parse(version, new InMemoryClosableChannel(), marker, commandReader);
// then
assertNull(logEntry);
assertFalse(parser.skip());
}
Aggregations