Skip to content

Commit

Permalink
Private builder fields and generics diamonds added
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 29, 2017
1 parent 7247caa commit a5e2de9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
Expand Up @@ -95,7 +95,7 @@ public void shouldDetectFormatChange() throws Throwable
// THEN everything should work, otherwise there has likely been a format change
PageCache pageCache = pageCacheRule.getPageCache( fsRule.get() );
try ( GBPTree<MutableLong,MutableLong> tree =
new GBPTreeBuilder( pageCache, storeFile, new SimpleLongLayout() ).build() )
new GBPTreeBuilder<>( pageCache, storeFile, new SimpleLongLayout() ).build() )
{
try
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private void createAndZipTree( File storeFile ) throws IOException
{
PageCache pageCache = pageCacheRule.getPageCache( fsRule.get() );
try ( GBPTree<MutableLong,MutableLong> tree =
new GBPTreeBuilder( pageCache, storeFile, new SimpleLongLayout() ).build() )
new GBPTreeBuilder<>( pageCache, storeFile, new SimpleLongLayout() ).build() )
{
MutableLong insertKey = new MutableLong();
MutableLong insertValue = new MutableLong();
Expand Down
Expand Up @@ -40,13 +40,13 @@
*/
class GBPTreeBuilder<KEY,VALUE>
{
PageCache pageCache;
File file;
int tentativePageSize = 0;
Monitor monitor = NO_MONITOR;
Header.Reader headerReader = NO_HEADER_READER;
Layout<KEY,VALUE> layout;
Consumer<PageCursor> headerWriter = NO_HEADER_WRITER;
private PageCache pageCache;
private File file;
private int tentativeIndexPageSize;
private Monitor monitor = NO_MONITOR;
private Header.Reader headerReader = NO_HEADER_READER;
private Layout<KEY,VALUE> layout;
private Consumer<PageCursor> headerWriter = NO_HEADER_WRITER;

GBPTreeBuilder()
{
Expand Down Expand Up @@ -77,9 +77,9 @@ GBPTreeBuilder<KEY,VALUE> with( PageCache pageCache )
return this;
}

GBPTreeBuilder<KEY,VALUE> withIndexPageSize( int tentativePageSize )
GBPTreeBuilder<KEY,VALUE> withIndexPageSize( int tentativeIndexPageSize )
{
this.tentativePageSize = tentativePageSize;
this.tentativeIndexPageSize = tentativeIndexPageSize;
return this;
}

Expand All @@ -103,6 +103,6 @@ GBPTreeBuilder<KEY,VALUE> with( Consumer<PageCursor> headerWriter )

GBPTree<KEY,VALUE> build() throws IOException
{
return new GBPTree<>( pageCache, file, layout, tentativePageSize, monitor, headerReader, headerWriter );
return new GBPTree<>( pageCache, file, layout, tentativeIndexPageSize, monitor, headerReader, headerWriter );
}
}
Expand Up @@ -104,7 +104,7 @@ private GBPTree<MutableLong,MutableLong> createIndex( GBPTree.Monitor monitor )
int pageSize = 256;
PageCache pageCache =
pageCacheRule.getPageCache( fs.get(), config().withPageSize( pageSize ).withAccessChecks( true ) );
return index = new GBPTreeBuilder( pageCache, directory.file( "index" ), layout ).build();
return index = new GBPTreeBuilder<>( pageCache, directory.file( "index" ), layout ).build();
}

@After
Expand Down
Expand Up @@ -73,7 +73,7 @@ private GBPTree<MutableLong,MutableLong> createIndex( int pageSize, GBPTree.Moni
throws IOException
{
pageCache = pageCacheRule.getPageCache( fs.get(), config().withPageSize( pageSize ).withAccessChecks( true ) );
return index = new GBPTreeBuilder( pageCache, directory.file( "index" ), layout ).build();
return index = new GBPTreeBuilder<>( pageCache, directory.file( "index" ), layout ).build();
}

@After
Expand Down
Expand Up @@ -379,7 +379,7 @@ private long[] modificationData( int min, int max )

private static GBPTree<MutableLong,MutableLong> createIndex( PageCache pageCache, File file ) throws IOException
{
return new GBPTreeBuilder( pageCache, file, new SimpleLongLayout() ).build();
return new GBPTreeBuilder<>( pageCache, file, new SimpleLongLayout() ).build();
}

private PageCache createPageCache()
Expand Down
Expand Up @@ -360,11 +360,12 @@ public void shouldFailWhenTryingToOpenWithDifferentFormatVersion() throws Except
{
// GIVEN
int pageSize = 256;
GBPTreeBuilder<MutableLong,MutableLong> builder = index( pageSize );
PageCache pageCache = createPageCache( pageSize );
GBPTreeBuilder<MutableLong,MutableLong> builder = new GBPTreeBuilder<>( pageCache, indexFile, layout );
try ( GBPTree<MutableLong,MutableLong> ignored = builder.build() )
{ // Open/close is enough
}
setFormatVersion( builder.pageCache, pageSize, GBPTree.FORMAT_VERSION - 1 );
setFormatVersion( pageCache, pageSize, GBPTree.FORMAT_VERSION - 1 );

try
{
Expand Down Expand Up @@ -454,7 +455,7 @@ public void failureDuringInitializeWriterShouldNotFailNextInitialize() throws Ex
AtomicBoolean throwOnNextIO = new AtomicBoolean();
PageCache controlledPageCache = pageCacheThatThrowExceptionWhenToldTo( no, throwOnNextIO );
try ( GBPTree<MutableLong, MutableLong> index =
new GBPTreeBuilder( controlledPageCache, indexFile, layout ).build() )
new GBPTreeBuilder<>( controlledPageCache, indexFile, layout ).build() )
{
// WHEN
assert throwOnNextIO.compareAndSet( false, true );
Expand Down Expand Up @@ -697,7 +698,8 @@ public void closeShouldLockOutWriter() throws Exception
AtomicBoolean enabled = new AtomicBoolean();
Barrier.Control barrier = new Barrier.Control();
PageCache pageCacheWithBarrier = pageCacheWithBarrierInClose( enabled, barrier );
GBPTree<MutableLong,MutableLong> index = new GBPTreeBuilder( pageCacheWithBarrier, indexFile, layout ).build();
GBPTree<MutableLong,MutableLong> index =
new GBPTreeBuilder<>( pageCacheWithBarrier, indexFile, layout ).build();
long key = 10;
try ( Writer<MutableLong,MutableLong> writer = index.writer() )
{
Expand Down Expand Up @@ -1064,7 +1066,8 @@ public void indexMustBeDirtyWhenCrashedWithChangesSinceLastCheckpoint() throws E
ephemeralFs.mkdirs( indexFile.getParentFile() );
PageCache pageCache = pageCacheRule.getPageCache( ephemeralFs );
EphemeralFileSystemAbstraction snapshot;
try ( GBPTree<MutableLong, MutableLong> index = new GBPTreeBuilder( pageCache, indexFile, layout ).build() )
try ( GBPTree<MutableLong, MutableLong> index =
new GBPTreeBuilder<>( pageCache, indexFile, layout ).build() )
{
insert( index, 0, 1 );

Expand All @@ -1077,7 +1080,7 @@ public void indexMustBeDirtyWhenCrashedWithChangesSinceLastCheckpoint() throws E
// THEN
MonitorDirty monitorDirty = new MonitorDirty();
pageCache = pageCacheRule.getPageCache( snapshot );
try ( GBPTree<MutableLong, MutableLong> ignored = new GBPTreeBuilder( pageCache, indexFile, layout )
try ( GBPTree<MutableLong, MutableLong> ignored = new GBPTreeBuilder<>( pageCache, indexFile, layout )
.with( pageCache ).with( monitorDirty ).build() )
{
}
Expand Down Expand Up @@ -1136,7 +1139,7 @@ public void shouldThrowIfTreeStatePointToRootWithValidSuccessor() throws Excepti
try ( PageCache specificPageCache = createPageCache( pageSize ) )
{
try ( GBPTree<MutableLong,MutableLong> ignore =
new GBPTreeBuilder( specificPageCache, indexFile, layout ).build() )
new GBPTreeBuilder<>( specificPageCache, indexFile, layout ).build() )
{
}

Expand All @@ -1157,7 +1160,7 @@ public void shouldThrowIfTreeStatePointToRootWithValidSuccessor() throws Excepti

// WHEN
try ( GBPTree<MutableLong,MutableLong> index =
new GBPTreeBuilder( specificPageCache, indexFile, layout ).build() )
new GBPTreeBuilder<>( specificPageCache, indexFile, layout ).build() )
{
try ( Writer<MutableLong, MutableLong> ignored = index.writer() )
{
Expand All @@ -1180,7 +1183,7 @@ public void mustRetryCloseIfFailure() throws Exception
AtomicBoolean throwOnNext = new AtomicBoolean();
IOException exception = new IOException( "My failure" );
PageCache pageCache = pageCacheThatThrowExceptionWhenToldTo( exception, throwOnNext );
try ( GBPTree<MutableLong, MutableLong> index = new GBPTreeBuilder( pageCache, indexFile, layout ).build() )
try ( GBPTree<MutableLong, MutableLong> index = new GBPTreeBuilder<>( pageCache, indexFile, layout ).build() )
{
// WHEN
throwOnNext.set( true );
Expand Down

0 comments on commit a5e2de9

Please sign in to comment.