Skip to content

Commit

Permalink
Make sure we always read at least one line of data from the metric file
Browse files Browse the repository at this point in the history
and try to unflake RotatableCsvOutputIT
  • Loading branch information
klaren committed Mar 14, 2018
1 parent 620f689 commit a9a3590
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Expand Up @@ -135,14 +135,23 @@ private static <T, FIELD extends Enum<FIELD> & CsvField> T readValueAndAssert( F

T currentValue = startValue;
String line;
while ( (line = reader.readLine()) != null )

// Always read at least one line of data
do
{
line = reader.readLine();
}
while ( line == null );

do
{
String[] fields = line.split( "," );
T newValue = parser.apply( fields[metricsValue.ordinal()] );
assertTrue( "assertion failed on " + newValue + " " + currentValue,
assumption.test( newValue, currentValue ) );
currentValue = newValue;
}
while ( (line = reader.readLine()) != null );
return currentValue;
}
}
Expand Down
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.IOException;
import java.util.function.BiPredicate;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
Expand All @@ -50,6 +51,7 @@ public class RotatableCsvOutputIT

private File outputPath;
private GraphDatabaseService database;
private static final BiPredicate<Long,Long> MONOTONIC = ( newValue, currentValue ) -> newValue >= currentValue;

@Before
public void setup()
Expand All @@ -71,27 +73,32 @@ public void tearDown()
@Test
public void rotateMetricsFile() throws InterruptedException, IOException
{
try ( Transaction transaction = database.beginTx() )
{
database.createNode();
transaction.success();
}
File metricsFile = metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED );
long committedTransactions = readLongValueAndAssert( metricsFile,
( newValue, currentValue ) -> newValue >= currentValue );
doTransaction();

// wait for rotation to happen
File metricsFile1 = metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED, 1 );
long committedTransactions = readLongValueAndAssert( metricsFile1, MONOTONIC );
assertEquals( 1, committedTransactions );

metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED, 1 );
doTransaction();

// Wait for rotation, since we rotated twice, file 3 is actually the original file
File metricsFile2 = metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED, 2 );
long oldCommittedTransactions = readLongValueAndAssert( metricsFile2, MONOTONIC );
assertEquals( 1, oldCommittedTransactions );

File metricsFile = metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED );
long lastCommittedTransactions = readLongValueAndAssert( metricsFile, MONOTONIC );
assertEquals( 2, lastCommittedTransactions );
}

private void doTransaction()
{
try ( Transaction transaction = database.beginTx() )
{
database.createNode();
transaction.success();
}
// Since we rotated twice, file 3 is actually the original file
File metricsFile3 = metricsCsv( outputPath, TransactionMetrics.TX_COMMITTED, 2 );
long oldCommittedTransactions = readLongValueAndAssert( metricsFile3,
( newValue, currentValue ) -> newValue >= currentValue );
assertEquals( 1, oldCommittedTransactions );
}

private static File metricsCsv( File dbDir, String metric ) throws InterruptedException
Expand Down

0 comments on commit a9a3590

Please sign in to comment.