Search in sources :

Example 6 with PhysicalFlushableChannel

use of org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel in project neo4j by neo4j.

the class InMemoryCountsStoreCountsSnapshotSerializerIntegrationTest method largeWorkloadOnPhysicalLogTest.

@Test
public void largeWorkloadOnPhysicalLogTest() throws IOException {
    //GIVEN
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        File tempFile = new File(testDir.directory(), "temp");
        StoreChannel rawChannel = fs.create(tempFile);
        Map<CountsKey, long[]> map = CountsStoreMapGenerator.simpleCountStoreMap(100000);
        CountsSnapshot countsSnapshot = new CountsSnapshot(1, map);
        CountsSnapshot recovered;
        //WHEN
        try (FlushableChannel tempChannel = new PhysicalFlushableChannel(rawChannel)) {
            serialize(tempChannel, countsSnapshot);
        }
        // close() here is necessary to flush the temp buffer into the channel so we can read it next
        // The try-with-resources closes the channel, need to reopen
        rawChannel = fs.open(tempFile, "r");
        try (ReadAheadChannel<StoreChannel> readAheadChannel = new ReadAheadChannel<>(rawChannel)) {
            recovered = deserialize(readAheadChannel);
            //THEN
            Assert.assertEquals(countsSnapshot.getTxId(), recovered.getTxId());
            for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
                long[] value = recovered.getMap().get(pair.getKey());
                Assert.assertNotNull(value);
                Assert.assertArrayEquals(value, pair.getValue());
            }
            for (Map.Entry<CountsKey, long[]> pair : recovered.getMap().entrySet()) {
                long[] value = countsSnapshot.getMap().get(pair.getKey());
                Assert.assertNotNull(value);
                Assert.assertArrayEquals(value, pair.getValue());
            }
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) File(java.io.File) Map(java.util.Map) ReadAheadChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadChannel) Test(org.junit.Test)

Aggregations

PhysicalFlushableChannel (org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel)6 StoreChannel (org.neo4j.io.fs.StoreChannel)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 FlushableChannel (org.neo4j.kernel.impl.transaction.log.FlushableChannel)2 File (java.io.File)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)1 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1 ReadAheadChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadChannel)1 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)1 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)1