Skip to content

Commit

Permalink
Making the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwebber committed Jan 18, 2016
1 parent 4e23e9e commit 77a1020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void shouldCallWriteAllAndForceOnVoteUpdate() throws Exception
state.update( 100L );

// Then
verify( channel ).write( any( ByteBuffer.class ) );
verify( channel ).writeAll( any( ByteBuffer.class ) );
verify( channel ).flush();
}

Expand All @@ -82,7 +82,7 @@ public void termShouldRemainUnchangedOnFailureToWriteToDisk() throws Exception
when( channel.read( any( ByteBuffer.class ) ) ).thenReturn( -1 );
FileSystemAbstraction fsa = mock( FileSystemAbstraction.class );
when( fsa.open( any( File.class ), anyString() ) ).thenReturn( channel );
doThrow( new IOException() ).when( channel ).write( any( ByteBuffer.class ) );
doThrow( new IOException() ).when( channel ).writeAll( any( ByteBuffer.class ) );

OnDiskTermState store = new OnDiskTermState( fsa, testDir.directory(), 100, mock( Supplier.class ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.junit.Rule;
import org.junit.Test;
import org.mockito.stubbing.Stubber;

import org.neo4j.coreedge.raft.state.vote.OnDiskVoteState;
import org.neo4j.coreedge.server.AdvertisedSocketAddress;
Expand All @@ -40,6 +41,7 @@
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void shouldCallWriteAndFlushOnVoteUpdate() throws Exception
state.votedFor( member, 0 );

// Then
verify( channel ).write( any( ByteBuffer.class ) );
verify( channel ).writeAll( any( ByteBuffer.class ) );
verify( channel ).flush();
}

Expand All @@ -83,8 +85,10 @@ public void termShouldRemainUnchangedOnFailureToWriteToDisk() throws Exception

FileSystemAbstraction fsa = mock( FileSystemAbstraction.class );
when( fsa.open( any( File.class ), anyString() ) ).thenReturn( channel );
// Mock the first call to succeed, so we can first store a proper value
when( channel.write( any( ByteBuffer.class ) ) ).thenReturn( 99 ).thenThrow( new IOException() );

final Stubber stubber = doNothing();
stubber.when( channel ).writeAll( any( ByteBuffer.class ) );
stubber.doThrow( new IOException() ).when( channel ).writeAll( any( ByteBuffer.class ) );

final Supplier databaseHealthSupplier = mock( Supplier.class );
when( databaseHealthSupplier.get() ).thenReturn( mock( DatabaseHealth.class ) );
Expand Down

0 comments on commit 77a1020

Please sign in to comment.