Skip to content

Commit

Permalink
Move test case to existing test class
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Jul 27, 2018
1 parent 349561a commit 5d8cc78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 72 deletions.

This file was deleted.

Expand Up @@ -31,6 +31,7 @@

import org.neo4j.cursor.RawCursor;
import org.neo4j.helpers.collection.Pair;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.string.UTF8;
import org.neo4j.test.rule.PageCacheAndDependenciesRule;
import org.neo4j.test.rule.RandomRule;
Expand All @@ -40,6 +41,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.neo4j.test.Randoms.CSA_LETTERS_AND_DIGITS;
import static org.neo4j.test.rule.PageCacheRule.config;

public class LargeDynamicKeysIT
{
Expand All @@ -49,16 +51,34 @@ public class LargeDynamicKeysIT
@Rule
public final RandomRule random = new RandomRule();

@Test
public void mustStayCorrectWhenInsertingValuesOfIncreasingLength() throws IOException
{
Layout<RawBytes,RawBytes> layout = new SimpleByteArrayLayout();
try ( GBPTree<RawBytes,RawBytes> index = createIndex( layout );
Writer<RawBytes,RawBytes> writer = index.writer())
{
RawBytes emptyValue = layout.newValue();
emptyValue.bytes = new byte[0];
for ( int keySize = 1; keySize < index.keyValueSizeCap(); keySize++ )
{
RawBytes key = layout.newKey();
key.bytes = new byte[keySize];
writer.put( key, emptyValue );
}
}
}

@Test
public void shouldWriteAndReadKeysOfSizesCloseToTheLimits() throws IOException
{
// given
try ( GBPTree<RawBytes,RawBytes> tree =
new GBPTreeBuilder<>( storage.pageCache(), storage.directory().file( "index" ), new SimpleByteArrayLayout() ).build() )
try ( GBPTree<RawBytes,RawBytes> tree = createIndex( new SimpleByteArrayLayout() ) )
{
// when
Set<String> generatedStrings = new HashSet<>();
List<Pair<RawBytes,RawBytes>> entries = new ArrayList<>();
int keyValueSizeCap = tree.keyValueSizeCap();
try ( Writer<RawBytes,RawBytes> writer = tree.writer() )
{
for ( int i = 0; i < 1_000; i++ )
Expand All @@ -72,7 +92,8 @@ public void shouldWriteAndReadKeysOfSizesCloseToTheLimits() throws IOException
String string;
do
{
string = random.string( 3_000, 4_000, CSA_LETTERS_AND_DIGITS );
int keySizeCap = keyValueSizeCap - value.bytes.length;
string = random.string( keySizeCap - 1000, keySizeCap, CSA_LETTERS_AND_DIGITS );
}
while ( !generatedStrings.add( string ) );
RawBytes key = new RawBytes();
Expand All @@ -97,4 +118,11 @@ public void shouldWriteAndReadKeysOfSizesCloseToTheLimits() throws IOException
}
}
}

private GBPTree<RawBytes,RawBytes> createIndex( Layout<RawBytes,RawBytes> layout ) throws IOException
{
// some random padding
PageCache pageCache = storage.pageCacheRule().getPageCache( storage.fileSystem(), config().withAccessChecks( true ) );
return new GBPTreeBuilder<>( pageCache, storage.directory().file( "index" ), layout ).build();
}
}

0 comments on commit 5d8cc78

Please sign in to comment.