use of org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class IdAllocationStateTest method shouldThrowExceptionForHalfWrittenEntries.
@Test
public void shouldThrowExceptionForHalfWrittenEntries() throws IOException, EndOfStreamException {
// given
final IdAllocationState state = new IdAllocationState();
for (int i = 1; i <= 3; i++) {
state.firstUnallocated(IdType.NODE, 1024 * i);
state.logIndex(i);
}
final IdAllocationState.Marshal marshal = new IdAllocationState.Marshal();
// when
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
marshal.marshal(state, channel);
// append some garbage
channel.putInt(1).putInt(2).putInt(3).putLong(4L);
// read back in the first one
marshal.unmarshal(channel);
// the second one will be half read (the ints and longs appended above).
try {
marshal.unmarshal(channel);
fail();
} catch (EndOfStreamException e) {
// expected
}
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class IdAllocationStateTest method shouldRoundtripToChannel.
@Test
public void shouldRoundtripToChannel() throws Exception {
// given
final IdAllocationState state = new IdAllocationState();
for (int i = 1; i <= 3; i++) {
state.firstUnallocated(IdType.NODE, 1024 * i);
state.logIndex(i);
}
final IdAllocationState.Marshal marshal = new IdAllocationState.Marshal();
// when
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
marshal.marshal(state, channel);
IdAllocationState unmarshalled = marshal.unmarshal(channel);
// then
assertEquals(state, unmarshalled);
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction.
@Test
public void shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction() throws Throwable {
// GIVEN a store that has got a node with a dynamic label record
NeoStores store = neoStoresRule.open();
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
AtomicLong nodeId = new AtomicLong();
AtomicLong dynamicLabelRecordId = new AtomicLong();
apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
// WHEN applying a transaction, which has first round-tripped through a log (written then read)
TransactionRepresentation transaction = transaction(deleteNode(store, nodeId.get()));
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
writeToChannel(transaction, channel);
CommittedTransactionRepresentation recoveredTransaction = readFromChannel(channel);
// and applying that recovered transaction
apply(applier, recoveredTransaction.getTransactionRepresentation());
// THEN should have the dynamic label record should be deleted as well
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Aggregations