Skip to content

Commit

Permalink
Fix StoreCopyClientIT by force sending page cache file.
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Mar 20, 2018
1 parent 3761293 commit 8665f4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestCatchupServerHandler implements CatchupServerHandler
private final Set<FakeFile> indexFiles = new HashSet<>();
private final Map<String,Integer> pathToRequestCountMapping = new HashMap<>();
private final Log log;
private final CatchupServerProtocol protocol;
final CatchupServerProtocol protocol;
private TestDirectory testDirectory;
private FileSystemAbstraction fileSystemAbstraction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

public class StoreCopyClientIT
{
Expand Down Expand Up @@ -178,7 +180,7 @@ public void failedFileCopyShouldRetry() throws StoreCopyFailedException
public void reconnectingWorks() throws StoreCopyFailedException
{
// given local client has a store
InMemoryStoreStreamProvider storeFileStream = new InMemoryStoreStreamProvider(
InMemoryStoreStreamProvider storeFileStream = new InMemoryStoreStreamProvider();

// and file B is broken once (after retry it works)
fileB.setRemainingNoResponse( 1 );
Expand Down Expand Up @@ -220,12 +222,12 @@ protected void channelRead0( ChannelHandlerContext ctx, GetStoreFileRequest msg
File file = new File( fileName );
String thisConent = contents.next();
writeContents( fsa, file, thisConent );
PageCache pageCache = StandalonePageCacheFactory.createPageCache( fsa );
PageCache pageCache = neverSupportingFileOperationPageCache( StandalonePageCacheFactory.createPageCache( fsa ) );
PagedFile pagedFile =
pageCache.map( new File( pageCacheFileName ), pageCache.pageSize(), StandardOpenOption.CREATE, StandardOpenOption.WRITE );
try ( WritableByteChannel writableByteChannel = pagedFile.openWritableByteChannel() )
{
writableByteChannel.write( ByteBuffer.wrap( thisConent.getBytes() ) );
writableByteChannel.write( ByteBuffer.wrap( thisConent.getBytes( Charsets.UTF_8 ) ) );
}

sendFile( ctx, file, pageCache );
Expand Down Expand Up @@ -281,11 +283,12 @@ protected void channelRead0( ChannelHandlerContext ctx, GetIndexFilesRequest msg
{
// when
ListenSocketAddress listenAddress = new ListenSocketAddress( "localhost", PortAuthority.allocatePort() );
halfWayFailingServer = new CatchupServerBuilder( protocol -> serverHandler ).listenAddress( listenAddress ).build();
halfWayFailingServer = new CatchupServerBuilder( protocol -> halfWayFailingServerhandler ).listenAddress( listenAddress ).build();
halfWayFailingServer.start();

CatchupAddressProvider addressProvider = CatchupAddressProvider.fromSingleAddress( ListenSocketAddress
listenAddress = new ListenSocketAddress( "localhost", PortAuthority.allocatePort() );
CatchupAddressProvider addressProvider =
CatchupAddressProvider.fromSingleAddress( new AdvertisedSocketAddress( listenAddress.getHostname(), listenAddress.getPort() ) );

StoreId storeId = halfWayFailingServerhandler.getStoreId();
File storeDir = testDirectory.makeGraphDbDir();
PageCache pageCache = StandalonePageCacheFactory.createPageCache( fsa );
Expand Down Expand Up @@ -313,6 +316,13 @@ protected void channelRead0( ChannelHandlerContext ctx, GetIndexFilesRequest msg
}
}

private PageCache neverSupportingFileOperationPageCache( PageCache pageCache )
{
PageCache spy = spy( pageCache );
when( spy.fileSystemSupportsFileOperations() ).thenReturn( false );
return spy;
}

private static AdvertisedSocketAddress from( int port )
{
return new AdvertisedSocketAddress( "localhost", port );
Expand Down

0 comments on commit 8665f4d

Please sign in to comment.