Search in sources :

Example 1 with InMemoryVersionableReadableClosablePositionAwareChannel

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
    }
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) Test(org.junit.Test)

Example 2 with InMemoryVersionableReadableClosablePositionAwareChannel

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);
}
Also used : InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) Test(org.junit.Test)

Example 3 with InMemoryVersionableReadableClosablePositionAwareChannel

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 InMemoryVersionableReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)1 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1