Skip to content

Commit

Permalink
Ensures MetaDataStoreTest race tests runs at least some operations
Browse files Browse the repository at this point in the history
even on really slow machines. Also corrected some confusing test access
methods.
  • Loading branch information
tinwelint committed Sep 19, 2016
1 parent 328f992 commit 1107550
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Expand Up @@ -1106,7 +1106,6 @@ private void dumpConfiguration( Map<String,String> config, PrintStream out )
// test-access
NeoStores getNeoStores()
{
forceFlushChanges();
return neoStores;
}

Expand Down
Expand Up @@ -400,15 +400,18 @@ public void setUpgradeTransactionMustBeAtomic() throws Throwable
AtomicLong writeCount = new AtomicLong();
AtomicLong fileReadCount = new AtomicLong();
AtomicLong apiReadCount = new AtomicLong();
int limit = 10_000;
long endTime = currentTimeMillis() + SECONDS.toMillis( 1 );
int upperLimit = 10_000;
int lowerLimit = 100;
long endTime = currentTimeMillis() + SECONDS.toMillis( 10 );

Race race = new Race();
BooleanSupplier end = () ->
{
boolean doContinue = writeCount.get() < limit ||
fileReadCount.get() < limit || apiReadCount.get() < limit;
return !doContinue || currentTimeMillis() >= endTime;
boolean upperBoundReached = writeCount.get() >= upperLimit &&
fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit;
boolean lowerBoundReached = writeCount.get() >= lowerLimit &&
fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit;
return !upperBoundReached || (currentTimeMillis() >= endTime && lowerBoundReached);
};
// writers
race.addContestants( 3, until( end, () -> {
Expand Down Expand Up @@ -481,13 +484,17 @@ public void transactionCommittedMustBeAtomic() throws Throwable
AtomicLong writeCount = new AtomicLong();
AtomicLong fileReadCount = new AtomicLong();
AtomicLong apiReadCount = new AtomicLong();
long endTime = currentTimeMillis() + SECONDS.toMillis( 1 );
int upperLimit = 10_000;
int lowerLimit = 100;
long endTime = currentTimeMillis() + SECONDS.toMillis( 10 );

BooleanSupplier end = () ->
{
boolean doContinue = writeCount.get() < 10_000 ||
fileReadCount.get() < 10_000 || apiReadCount.get() < 10_000;
return !doContinue || currentTimeMillis() >= endTime;
boolean upperBoundReached = writeCount.get() >= upperLimit &&
fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit;
boolean lowerBoundReached = writeCount.get() >= lowerLimit &&
fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit;
return !upperBoundReached || (currentTimeMillis() >= endTime && lowerBoundReached);
};
Race race = new Race();
race.addContestants( 3, until( end, () ->
Expand Down Expand Up @@ -534,13 +541,17 @@ public void transactionClosedMustBeAtomic() throws Throwable
AtomicLong writeCount = new AtomicLong();
AtomicLong fileReadCount = new AtomicLong();
AtomicLong apiReadCount = new AtomicLong();
long endTime = currentTimeMillis() + SECONDS.toMillis( 1 );
int upperLimit = 10_000;
int lowerLimit = 100;
long endTime = currentTimeMillis() + SECONDS.toMillis( 10 );

BooleanSupplier end = () ->
{
boolean doContinue = writeCount.get() < 10_000 ||
fileReadCount.get() < 10_000 || apiReadCount.get() < 10_000;
return !doContinue || currentTimeMillis() >= endTime;
boolean upperBoundReached = writeCount.get() >= upperLimit &&
fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit;
boolean lowerBoundReached = writeCount.get() >= lowerLimit &&
fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit;
return !upperBoundReached || (currentTimeMillis() >= endTime && lowerBoundReached);
};
Race race = new Race();
race.addContestants( 3, until( end, () -> {
Expand Down
Expand Up @@ -207,7 +207,7 @@ public static void startGlobalInserter() throws IOException
// Global inserter can be used in tests which simply want to verify "local" behaviour,
// e.g. create a node with some properties and read them back.
globalInserter = BatchInserters.inserter(
TestDirectory.testDataDirectoryOf( REAL_FS, BatchInsertTest.class, true ),
TestDirectory.testDataDirectoryOf( fs, BatchInsertTest.class, true ),
fs, stringMap() );
}

Expand Down Expand Up @@ -1172,7 +1172,7 @@ public void mustSplitUpRelationshipChainsWhenCreatingDenseNodes() throws Excepti
}
}

NeoStores neoStores = ((BatchInserterImpl) inserter).getNeoStores();
NeoStores neoStores = getFlushedNeoStores( inserter );
NodeRecord record = getRecord( neoStores.getNodeStore(), node1 );
assertTrue( "Node " + record + " should have been dense", record.isDense() );
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public void shouldNotCreateSameLabelTwiceOnSameNode() throws Exception
label( "Item" ) );

// THEN
NodeStore nodeStore = ((BatchInserterImpl) inserter).getNeoStores().getNodeStore();
NodeStore nodeStore = getFlushedNeoStores( inserter ).getNodeStore();
NodeRecord node = nodeStore.getRecord( nodeId, nodeStore.newRecord(), NORMAL );
NodeLabels labels = NodeLabelsField.parseLabelsField( node );
long[] labelIds = labels.get( nodeStore );
Expand All @@ -1224,7 +1224,7 @@ public void shouldSortLabelIdsWhenGetOrCreate() throws Exception
label( "DD" ), label( "EE" ), label( "FF" ) );

// THEN
NodeStore nodeStore = ((BatchInserterImpl) inserter).getNeoStores().getNodeStore();
NodeStore nodeStore = getFlushedNeoStores( inserter ).getNodeStore();
NodeRecord node = nodeStore.getRecord( nodeId, nodeStore.newRecord(), RecordLoad.NORMAL );
NodeLabels labels = NodeLabelsField.parseLabelsField( node );

Expand Down Expand Up @@ -1569,7 +1569,13 @@ private Node getNodeInTx( long nodeId, GraphDatabaseService db )

private void forceFlush( BatchInserter inserter )
{
((BatchInserterImpl)inserter).getNeoStores();
((BatchInserterImpl)inserter).forceFlushChanges();
}

private NeoStores getFlushedNeoStores( BatchInserter inserter )
{
forceFlush( inserter );
return ((BatchInserterImpl) inserter).getNeoStores();
}

private enum Labels implements Label
Expand Down

0 comments on commit 1107550

Please sign in to comment.