Skip to content

Commit

Permalink
Cleanups in AdversarialReadPageCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 20, 2016
1 parent 6728dbf commit 573744a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Expand Up @@ -152,6 +152,15 @@ private boolean hasInconsistentRead()
}
return false;
}

public boolean isInconsistent()
{
if ( currentReadIsPreparingInconsistent )
{
callCounter++;
}
return currentReadIsInconsistent;
}
}

private final PageCursor delegate;
Expand Down Expand Up @@ -342,19 +351,22 @@ public void rewind()
@Override
public boolean next() throws IOException
{
boolean currentReadIsPreparingInconsistent = state.injectFailureOrMischief( FileNotFoundException.class, IOException.class,
SecurityException.class, IllegalStateException.class );
state.reset( currentReadIsPreparingInconsistent );
prepareNext();
return delegate.next();
}

@Override
public boolean next( long pageId ) throws IOException
{
prepareNext();
return delegate.next( pageId );
}

private void prepareNext()
{
boolean currentReadIsPreparingInconsistent = state.injectFailureOrMischief( FileNotFoundException.class, IOException.class,
SecurityException.class, IllegalStateException.class );
state.reset( currentReadIsPreparingInconsistent );
return delegate.next( pageId );
}

@Override
Expand Down Expand Up @@ -395,11 +407,7 @@ private void resetDelegate() throws IOException
public int copyTo( int sourceOffset, PageCursor targetCursor, int targetOffset, int lengthInBytes )
{
state.injectFailure( IndexOutOfBoundsException.class );
if ( state.currentReadIsPreparingInconsistent )
{
state.callCounter++;
}
if ( !state.currentReadIsInconsistent )
if ( !state.isInconsistent() )
{
delegate.copyTo( sourceOffset, targetCursor, targetOffset, lengthInBytes );
}
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void read( PropertyRecord record, PageCursor cursor, RecordLoad mode, int
return;
}
int additionalBlocks = numberOfBlocksUsed - 1;
if ( additionalBlocks * 8 > RECORD_SIZE - (cursor.getOffset() - offsetAtBeginning ) )
if ( additionalBlocks * Long.BYTES > RECORD_SIZE - (cursor.getOffset() - offsetAtBeginning) )
{
cursor.setCursorException( "PropertyRecord claims to have more property blocks than can fit in a record" );
return;
Expand Down

0 comments on commit 573744a

Please sign in to comment.