Skip to content

Commit

Permalink
Add support for ReadableByteChannel views to AdversarialPagedFile
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 16, 2016
1 parent f9a287c commit 843e141
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache.impl.muninn;
package org.neo4j.io.pagecache.impl;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -27,7 +27,7 @@
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;

final class PagedReadableByteChannel implements ReadableByteChannel
public final class PagedReadableByteChannel implements ReadableByteChannel
{
private final PageCursor cursor;
private boolean open = true;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.io.pagecache.PageSwapper;
import org.neo4j.io.pagecache.PageSwapperFactory;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.io.pagecache.impl.PagedReadableByteChannel;
import org.neo4j.io.pagecache.tracing.FlushEvent;
import org.neo4j.io.pagecache.tracing.FlushEventOpportunity;
import org.neo4j.io.pagecache.tracing.MajorFlushEvent;
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.io.pagecache.impl.PagedReadableByteChannel;

/**
* A {@linkplain PagedFile paged file} that wraps another paged file and an {@linkplain Adversary adversary} to provide
Expand All @@ -37,12 +38,12 @@
* or {@link IOException} like {@link FileNotFoundException}.
*/
@SuppressWarnings( "unchecked" )
class AdversarialPagedFile implements PagedFile
public class AdversarialPagedFile implements PagedFile
{
private final PagedFile delegate;
private final Adversary adversary;

AdversarialPagedFile( PagedFile delegate, Adversary adversary )
public AdversarialPagedFile( PagedFile delegate, Adversary adversary )
{
this.delegate = Objects.requireNonNull( delegate );
this.adversary = Objects.requireNonNull( adversary );
Expand Down Expand Up @@ -95,8 +96,8 @@ public void close() throws IOException
}

@Override
public ReadableByteChannel openReadableByteChannel()
public ReadableByteChannel openReadableByteChannel() throws IOException
{
throw new UnsupportedOperationException( "Not implemented for AdversarialPagedFile" );
return new PagedReadableByteChannel( this );
}
}
Expand Up @@ -48,6 +48,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import org.neo4j.adversaries.RandomAdversary;
import org.neo4j.adversaries.pagecache.AdversarialPagedFile;
import org.neo4j.concurrent.BinaryLatch;
import org.neo4j.function.ThrowingConsumer;
import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
Expand Down Expand Up @@ -4029,6 +4031,24 @@ public void readableByteChannelMustReadAllBytesInFile() throws Exception
}
}

@RepeatRule.Repeat( times = 20 )
@Test
public void readableByteChannelMustReadAllBytesInFileConsistently() throws Exception
{
File file = file( "a" );
generateFileWithRecords( file, recordCount, recordSize );
getPageCache( fs, maxPages, pageCachePageSize, PageCacheTracer.NULL );
try ( PagedFile pf = pageCache.map( file, filePageSize ) )
{
RandomAdversary adversary = new RandomAdversary( 0.9, 0, 0 );
AdversarialPagedFile apf = new AdversarialPagedFile( pf, adversary );
try ( ReadableByteChannel channel = apf.openReadableByteChannel() )
{
verifyRecordsInFile( channel, recordCount );
}
}
}

@Test( expected = ClosedChannelException.class )
public void readingFromClosedReadableByteChannelMustThrow() throws Exception
{
Expand Down

0 comments on commit 843e141

Please sign in to comment.