Skip to content

Commit

Permalink
Fixed up warnings from generics and other minor warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwebber committed Jan 13, 2016
1 parent 751b4f4 commit 7191996
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
Expand Up @@ -187,10 +187,10 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
throw new RuntimeException( e ); throw new RuntimeException( e );
} }


VoteState voteState; VoteState<CoreMember> voteState;
try try
{ {
voteState = life.add( new OnDiskVoteState( fileSystem, raftLogsDirectory, voteState = life.add( new OnDiskVoteState<>( fileSystem, raftLogsDirectory,
config.get( CoreEdgeClusterSettings.vote_state_size ), databaseHealthSupplier, config.get( CoreEdgeClusterSettings.vote_state_size ), databaseHealthSupplier,
new CoreMember.CoreMemberMarshal() ) ); new CoreMember.CoreMemberMarshal() ) );
} }
Expand Down
Expand Up @@ -46,7 +46,7 @@ public VoteState<CoreMember> createVoteStore()
File directory = testDirectory.directory( "raft-log" ); File directory = testDirectory.directory( "raft-log" );
try try
{ {
return new OnDiskVoteState( fileSystem, directory, 100, mock( Supplier.class ), new CoreMember.CoreMemberMarshal() ); return new OnDiskVoteState<>( fileSystem, directory, 100, mock( Supplier.class ), new CoreMember.CoreMemberMarshal() );
} }
catch ( IOException e ) catch ( IOException e )
{ {
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class OnDiskVoteStateTest
public void shouldRoundTripVoteToDisk() throws Exception public void shouldRoundTripVoteToDisk() throws Exception
{ {
// given // given
OnDiskVoteState state = new OnDiskVoteState( new EphemeralFileSystemAbstraction(), testDir.directory(), 100, OnDiskVoteState<CoreMember> state = new OnDiskVoteState<>( new EphemeralFileSystemAbstraction(), testDir.directory(), 100,
mock( Supplier.class ), new CoreMember.CoreMemberMarshal() ); mock( Supplier.class ), new CoreMember.CoreMemberMarshal() );


// when // when
Expand All @@ -75,11 +75,11 @@ public void shouldCallWriteAllAndForceOnVoteUpdate() throws Exception
AdvertisedSocketAddress localhost = new AdvertisedSocketAddress( "localhost:" + 1234 ); AdvertisedSocketAddress localhost = new AdvertisedSocketAddress( "localhost:" + 1234 );
CoreMember member = new CoreMember( localhost, localhost ); CoreMember member = new CoreMember( localhost, localhost );


OnDiskVoteState store = new OnDiskVoteState( fsa, new File( testDir.directory(), "on.disk.state" ), 100, OnDiskVoteState<CoreMember> state = new OnDiskVoteState<>( fsa, new File( testDir.directory(), "on.disk.state" ), 100,
mock( Supplier.class ), new CoreMember.CoreMemberMarshal() ); mock( Supplier.class ), new CoreMember.CoreMemberMarshal() );


// When // When
store.votedFor( member, 0 ); state.votedFor( member, 0 );


// Then // Then
verify( channel ).writeAll( any( ByteBuffer.class ) ); verify( channel ).writeAll( any( ByteBuffer.class ) );
Expand All @@ -96,7 +96,7 @@ public void termShouldRemainUnchangedOnFailureToWriteToDisk() throws Exception
// Mock the first call to succeed, so we can first store a proper value // Mock the first call to succeed, so we can first store a proper value
doNothing().doThrow( new IOException() ).when( channel ).writeAll( any( ByteBuffer.class ) ); doNothing().doThrow( new IOException() ).when( channel ).writeAll( any( ByteBuffer.class ) );


OnDiskVoteState store = new OnDiskVoteState( fsa, new File( testDir.directory(), "on.disk.state" ), 100, OnDiskVoteState<CoreMember> state = new OnDiskVoteState<>( fsa, new File( testDir.directory(), "on.disk.state" ), 100,
mock( Supplier.class ), new CoreMember.CoreMemberMarshal() ); mock( Supplier.class ), new CoreMember.CoreMemberMarshal() );


// This has to be real because it will be serialized // This has to be real because it will be serialized
Expand All @@ -106,10 +106,10 @@ public void termShouldRemainUnchangedOnFailureToWriteToDisk() throws Exception
// When // When
// We do the first store successfully, so we can meaningfully compare the stored value after the failed // We do the first store successfully, so we can meaningfully compare the stored value after the failed
// invocation // invocation
store.votedFor( firstMember, 0 ); state.votedFor( firstMember, 0 );


// Then // Then
assertEquals( firstMember, store.votedFor() ); assertEquals( firstMember, state.votedFor() );


// This should not be stored // This should not be stored
AdvertisedSocketAddress secondLocalhost = new AdvertisedSocketAddress( "localhost:" + 1235 ); AdvertisedSocketAddress secondLocalhost = new AdvertisedSocketAddress( "localhost:" + 1235 );
Expand All @@ -118,16 +118,15 @@ public void termShouldRemainUnchangedOnFailureToWriteToDisk() throws Exception
// When // When
try try
{ {
store.votedFor( secondMember, 1 ); state.votedFor( secondMember, 1 );
fail( "Test setup should have caused an exception here" ); fail( "Test setup should have caused an exception here" );
} }
catch ( Exception e ) catch ( Exception e )
{ {
// Then
// The stored member should not be updated
assertEquals( firstMember, state.votedFor() );
} }

// Then
// The stored member should not be updated
assertEquals( firstMember, store.votedFor() );
} }


@Test @Test
Expand All @@ -138,11 +137,11 @@ public void shouldForceAndCloseOnShutdown() throws Throwable
FileSystemAbstraction fsa = mock( FileSystemAbstraction.class ); FileSystemAbstraction fsa = mock( FileSystemAbstraction.class );
when( fsa.open( any( File.class ), anyString() ) ).thenReturn( channel ); when( fsa.open( any( File.class ), anyString() ) ).thenReturn( channel );


OnDiskVoteState store = new OnDiskVoteState( fsa, new File( testDir.directory(), "on.disk.state" ), 100, OnDiskVoteState<CoreMember> state = new OnDiskVoteState<>( fsa, new File( testDir.directory(), "on.disk.state" ), 100,
mock( Supplier.class ), new CoreMember.CoreMemberMarshal() ); mock( Supplier.class ), new CoreMember.CoreMemberMarshal() );


// When // When
store.shutdown(); state.shutdown();


// Then // Then
verify( channel ).force( false ); verify( channel ).force( false );
Expand Down
Expand Up @@ -103,7 +103,7 @@ private VoteState<CoreMember> createVoteStore( FileSystemAbstraction fileSystem
final Supplier mock = mock( Supplier.class ); final Supplier mock = mock( Supplier.class );
when( mock.get() ).thenReturn( mock( DatabaseHealth.class ) ); when( mock.get() ).thenReturn( mock( DatabaseHealth.class ) );


return new OnDiskVoteState( fileSystem, testDir.directory(), 100, mock, return new OnDiskVoteState<>( fileSystem, testDir.directory(), 100, mock,
new CoreMember.CoreMemberMarshal() ); new CoreMember.CoreMemberMarshal() );
} }
} }
Expand Up @@ -42,7 +42,7 @@ public VoteState<CoreMember> createVoteStore( EphemeralFileSystemAbstraction fil
{ {
File directory = new File( "raft-log" ); File directory = new File( "raft-log" );
fileSystem.mkdir( directory ); fileSystem.mkdir( directory );
return new OnDiskVoteState( fileSystem, directory, 100, mock(Supplier.class), new CoreMember.CoreMemberMarshal() ); return new OnDiskVoteState<>( fileSystem, directory, 100, mock(Supplier.class), new CoreMember.CoreMemberMarshal() );
} }


@Test @Test
Expand Down

0 comments on commit 7191996

Please sign in to comment.