@ -5,12 +5,14 @@
package org.rocksdb ;
package org.rocksdb ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.junit.Assert.* ;
import java.nio.charset.StandardCharsets ;
import java.nio.file.Path ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
import java.nio.file.Paths ;
import java.util.* ;
import java.util.* ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.concurrent.atomic.AtomicBoolean ;
import org.assertj.core.api.AbstractObjectAssert ;
import org.assertj.core.api.ObjectAssert ;
import org.junit.ClassRule ;
import org.junit.ClassRule ;
import org.junit.Rule ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.Test ;
@ -37,7 +39,7 @@ public class EventListenerTest {
rand . nextBytes ( value ) ;
rand . nextBytes ( value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
db . flush ( new FlushOptions ( ) ) ;
db . flush ( new FlushOptions ( ) ) ;
assertTrue ( wasCbCalled . get ( ) ) ;
assertThat ( wasCbCalled . get ( ) ) . isTrue ( ) ;
}
}
}
}
@ -47,8 +49,8 @@ public class EventListenerTest {
final AbstractEventListener onFlushCompletedListener = new AbstractEventListener ( ) {
final AbstractEventListener onFlushCompletedListener = new AbstractEventListener ( ) {
@Override
@Override
public void onFlushCompleted ( final RocksDB rocksDb , final FlushJobInfo flushJobInfo ) {
public void onFlushCompleted ( final RocksDB rocksDb , final FlushJobInfo flushJobInfo ) {
assertNotNull ( flushJobInfo . getColumnFamilyName ( ) ) ;
assertThat ( flushJobInfo . getColumnFamilyName ( ) ) . isNotNull ( ) ;
assertEquals ( FlushReason . MANUAL_FLUSH , flushJobInfo . getFlushReason ( ) ) ;
assertThat ( flushJobInfo . getFlushReason ( ) ) . isEqualTo ( FlushReason . MANUAL_FLUSH ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -61,8 +63,8 @@ public class EventListenerTest {
final AbstractEventListener onFlushBeginListener = new AbstractEventListener ( ) {
final AbstractEventListener onFlushBeginListener = new AbstractEventListener ( ) {
@Override
@Override
public void onFlushBegin ( final RocksDB rocksDb , final FlushJobInfo flushJobInfo ) {
public void onFlushBegin ( final RocksDB rocksDb , final FlushJobInfo flushJobInfo ) {
assertNotNull ( flushJobInfo . getColumnFamilyName ( ) ) ;
assertThat ( flushJobInfo . getColumnFamilyName ( ) ) . isNotNull ( ) ;
assertEquals ( FlushReason . MANUAL_FLUSH , flushJobInfo . getFlushReason ( ) ) ;
assertThat ( flushJobInfo . getFlushReason ( ) ) . isEqualTo ( FlushReason . MANUAL_FLUSH ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -79,21 +81,21 @@ public class EventListenerTest {
rand . nextBytes ( value ) ;
rand . nextBytes ( value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
final RocksDB . LiveFiles liveFiles = db . getLiveFiles ( ) ;
final RocksDB . LiveFiles liveFiles = db . getLiveFiles ( ) ;
assertNotNull ( liveFiles ) ;
assertThat ( liveFiles ) . isNotNull ( ) ;
assertNotNull ( liveFiles . files ) ;
assertThat ( liveFiles . files ) . isNotNull ( ) ;
assertFalse ( liveFiles . files . isEmpty ( ) ) ;
assertThat ( liveFiles . files . isEmpty ( ) ) . isFalse ( ) ;
db . deleteFile ( liveFiles . files . get ( 0 ) ) ;
db . deleteFile ( liveFiles . files . get ( 0 ) ) ;
assertTrue ( wasCbCalled . get ( ) ) ;
assertThat ( wasCbCalled . get ( ) ) . isTrue ( ) ;
}
}
}
}
@Test
@Test
public void onTableFileDeleted ( ) throws RocksDBException , InterruptedException {
public void onTableFileDeleted ( ) throws RocksDBException {
final AtomicBoolean wasCbCalled = new AtomicBoolean ( ) ;
final AtomicBoolean wasCbCalled = new AtomicBoolean ( ) ;
final AbstractEventListener onTableFileDeletedListener = new AbstractEventListener ( ) {
final AbstractEventListener onTableFileDeletedListener = new AbstractEventListener ( ) {
@Override
@Override
public void onTableFileDeleted ( final TableFileDeletionInfo tableFileDeletionInfo ) {
public void onTableFileDeleted ( final TableFileDeletionInfo tableFileDeletionInfo ) {
assertNotNull ( tableFileDeletionInfo . getDbName ( ) ) ;
assertThat ( tableFileDeletionInfo . getDbName ( ) ) . isNotNull ( ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -110,7 +112,7 @@ public class EventListenerTest {
rand . nextBytes ( value ) ;
rand . nextBytes ( value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
db . compactRange ( ) ;
db . compactRange ( ) ;
assertTrue ( wasCbCalled . get ( ) ) ;
assertThat ( wasCbCalled . get ( ) ) . isTrue ( ) ;
}
}
}
}
@ -120,7 +122,8 @@ public class EventListenerTest {
final AbstractEventListener onCompactionBeginListener = new AbstractEventListener ( ) {
final AbstractEventListener onCompactionBeginListener = new AbstractEventListener ( ) {
@Override
@Override
public void onCompactionBegin ( final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
public void onCompactionBegin ( final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
assertEquals ( CompactionReason . kManualCompaction , compactionJobInfo . compactionReason ( ) ) ;
assertThat ( compactionJobInfo . compactionReason ( ) )
. isEqualTo ( CompactionReason . kManualCompaction ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -134,7 +137,8 @@ public class EventListenerTest {
@Override
@Override
public void onCompactionCompleted (
public void onCompactionCompleted (
final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
assertEquals ( CompactionReason . kManualCompaction , compactionJobInfo . compactionReason ( ) ) ;
assertThat ( compactionJobInfo . compactionReason ( ) )
. isEqualTo ( CompactionReason . kManualCompaction ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -147,7 +151,7 @@ public class EventListenerTest {
final AbstractEventListener onTableFileCreatedListener = new AbstractEventListener ( ) {
final AbstractEventListener onTableFileCreatedListener = new AbstractEventListener ( ) {
@Override
@Override
public void onTableFileCreated ( final TableFileCreationInfo tableFileCreationInfo ) {
public void onTableFileCreated ( final TableFileCreationInfo tableFileCreationInfo ) {
assertEquals ( TableFileCreationReason . FLUSH , tableFileCreationInfo . getReason ( ) ) ;
assertThat ( tableFileCreationInfo . getReason ( ) ) . isEqualTo ( TableFileCreationReason . FLUSH ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -161,7 +165,7 @@ public class EventListenerTest {
@Override
@Override
public void onTableFileCreationStarted (
public void onTableFileCreationStarted (
final TableFileCreationBriefInfo tableFileCreationBriefInfo ) {
final TableFileCreationBriefInfo tableFileCreationBriefInfo ) {
assertEquals ( TableFileCreationReason . FLUSH , tableFileCreationBriefInfo . getReason ( ) ) ;
assertThat ( tableFileCreationBriefInfo . getReason ( ) ) . isEqualTo ( TableFileCreationReason . FLUSH ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -179,7 +183,7 @@ public class EventListenerTest {
db . put ( "testKey" . getBytes ( ) , value ) ;
db . put ( "testKey" . getBytes ( ) , value ) ;
ColumnFamilyHandle columnFamilyHandle = db . getDefaultColumnFamily ( ) ;
ColumnFamilyHandle columnFamilyHandle = db . getDefaultColumnFamily ( ) ;
columnFamilyHandle . close ( ) ;
columnFamilyHandle . close ( ) ;
assertTrue ( wasCbCalled . get ( ) ) ;
assertThat ( wasCbCalled . get ( ) ) . isTrue ( ) ;
}
}
}
}
@ -191,7 +195,7 @@ public class EventListenerTest {
@Override
@Override
public void onColumnFamilyHandleDeletionStarted (
public void onColumnFamilyHandleDeletionStarted (
final ColumnFamilyHandle columnFamilyHandle ) {
final ColumnFamilyHandle columnFamilyHandle ) {
assertNotNull ( columnFamilyHandle ) ;
assertThat ( columnFamilyHandle ) . isNotNull ( ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -212,7 +216,7 @@ public class EventListenerTest {
sstFileWriter . finish ( ) ;
sstFileWriter . finish ( ) ;
db . ingestExternalFile (
db . ingestExternalFile (
Collections . singletonList ( externalFilePath . toString ( ) ) , new IngestExternalFileOptions ( ) ) ;
Collections . singletonList ( externalFilePath . toString ( ) ) , new IngestExternalFileOptions ( ) ) ;
assertTrue ( wasCbCalled . get ( ) ) ;
assertThat ( wasCbCalled . get ( ) ) . isTrue ( ) ;
}
}
}
}
@ -223,7 +227,7 @@ public class EventListenerTest {
@Override
@Override
public void onExternalFileIngested (
public void onExternalFileIngested (
final RocksDB db , final ExternalFileIngestionInfo externalFileIngestionInfo ) {
final RocksDB db , final ExternalFileIngestionInfo externalFileIngestionInfo ) {
assertNotNull ( db ) ;
assertThat ( db ) . isNotNull ( ) ;
wasCbCalled . set ( true ) ;
wasCbCalled . set ( true ) ;
}
}
} ;
} ;
@ -232,7 +236,6 @@ public class EventListenerTest {
@Test
@Test
public void testAllCallbacksInvocation ( ) {
public void testAllCallbacksInvocation ( ) {
final int TEST_INT_VAL = - 1 ;
final long TEST_LONG_VAL = - 1 ;
final long TEST_LONG_VAL = - 1 ;
// Expected test data objects
// Expected test data objects
final Map < String , String > userCollectedPropertiesTestData =
final Map < String , String > userCollectedPropertiesTestData =
@ -272,75 +275,79 @@ public class EventListenerTest {
@Override
@Override
public void onFlushCompleted ( final RocksDB db , final FlushJobInfo flushJobInfo ) {
public void onFlushCompleted ( final RocksDB db , final FlushJobInfo flushJobInfo ) {
super . onFlushCompleted ( db , flushJobInfo ) ;
super . onFlushCompleted ( db , flushJobInfo ) ;
assertEquals ( flushJobInfoTestData , flushJobInfo ) ;
assertThat ( flushJobInfo ) . isEqualTo ( flushJobInfoTestData ) ;
}
}
@Override
@Override
public void onFlushBegin ( final RocksDB db , final FlushJobInfo flushJobInfo ) {
public void onFlushBegin ( final RocksDB db , final FlushJobInfo flushJobInfo ) {
super . onFlushBegin ( db , flushJobInfo ) ;
super . onFlushBegin ( db , flushJobInfo ) ;
assertEquals ( flushJobInfoTestData , flushJobInfo ) ;
assertThat ( flushJobInfo ) . isEqualTo ( flushJobInfoTestData ) ;
}
}
@Override
@Override
public void onTableFileDeleted ( final TableFileDeletionInfo tableFileDeletionInfo ) {
public void onTableFileDeleted ( final TableFileDeletionInfo tableFileDeletionInfo ) {
super . onTableFileDeleted ( tableFileDeletionInfo ) ;
super . onTableFileDeleted ( tableFileDeletionInfo ) ;
assertEquals ( tableFileDeletionInfoTestData , tableFileDeletionInfo ) ;
assertThat ( tableFileDeletionInfo ) . isEqualTo ( tableFileDeletionInfoTestData ) ;
}
}
@Override
@Override
public void onCompactionBegin ( final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
public void onCompactionBegin ( final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
super . onCompactionBegin ( db , compactionJobInfo ) ;
super . onCompactionBegin ( db , compactionJobInfo ) ;
assertArrayEquals (
assertThat ( new String ( compactionJobInfo . columnFamilyName ( ) , StandardCharsets . UTF_8 ) )
"compactionColumnFamily" . getBytes ( ) , compactionJobInfo . columnFamilyName ( ) ) ;
. isEqualTo ( "compactionColumnFamily" ) ;
assertEquals ( statusTestData , compactionJobInfo . status ( ) ) ;
assertThat ( compactionJobInfo . status ( ) ) . isEqualTo ( statusTestData ) ;
assertEquals ( TEST_LONG_VAL , compactionJobInfo . threadId ( ) ) ;
assertThat ( compactionJobInfo . threadId ( ) ) . isEqualTo ( TEST_LONG_VAL ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . jobId ( ) ) ;
assertThat ( compactionJobInfo . jobId ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . baseInputLevel ( ) ) ;
assertThat ( compactionJobInfo . baseInputLevel ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . outputLevel ( ) ) ;
assertThat ( compactionJobInfo . outputLevel ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Collections . singletonList ( "inputFile.sst" ) , compactionJobInfo . inputFiles ( ) ) ;
assertThat ( compactionJobInfo . inputFiles ( ) )
assertEquals ( Collections . singletonList ( "outputFile.sst" ) , compactionJobInfo . outputFiles ( ) ) ;
. isEqualTo ( Collections . singletonList ( "inputFile.sst" ) ) ;
assertEquals ( Collections . singletonMap ( "tableProperties" , tablePropertiesTestData ) ,
assertThat ( compactionJobInfo . outputFiles ( ) )
compactionJobInfo . tableProperties ( ) ) ;
. isEqualTo ( Collections . singletonList ( "outputFile.sst" ) ) ;
assertEquals ( CompactionReason . kFlush , compactionJobInfo . compactionReason ( ) ) ;
assertThat ( compactionJobInfo . tableProperties ( ) )
assertEquals ( CompressionType . SNAPPY_COMPRESSION , compactionJobInfo . compression ( ) ) ;
. isEqualTo ( Collections . singletonMap ( "tableProperties" , tablePropertiesTestData ) ) ;
assertThat ( compactionJobInfo . compactionReason ( ) ) . isEqualTo ( CompactionReason . kFlush ) ;
assertThat ( compactionJobInfo . compression ( ) ) . isEqualTo ( CompressionType . SNAPPY_COMPRESSION ) ;
}
}
@Override
@Override
public void onCompactionCompleted (
public void onCompactionCompleted (
final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
final RocksDB db , final CompactionJobInfo compactionJobInfo ) {
super . onCompactionCompleted ( db , compactionJobInfo ) ;
super . onCompactionCompleted ( db , compactionJobInfo ) ;
assertArrayEquals (
assertThat ( new String ( compactionJobInfo . columnFamilyName ( ) ) )
"compactionColumnFamily" . getBytes ( ) , compactionJobInfo . columnFamilyName ( ) ) ;
. isEqualTo ( "compactionColumnFamily" ) ;
assertEquals ( statusTestData , compactionJobInfo . status ( ) ) ;
assertThat ( compactionJobInfo . status ( ) ) . isEqualTo ( statusTestData ) ;
assertEquals ( TEST_LONG_VAL , compactionJobInfo . threadId ( ) ) ;
assertThat ( compactionJobInfo . threadId ( ) ) . isEqualTo ( TEST_LONG_VAL ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . jobId ( ) ) ;
assertThat ( compactionJobInfo . jobId ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . baseInputLevel ( ) ) ;
assertThat ( compactionJobInfo . baseInputLevel ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Integer . MAX_VALUE , compactionJobInfo . outputLevel ( ) ) ;
assertThat ( compactionJobInfo . outputLevel ( ) ) . isEqualTo ( Integer . MAX_VALUE ) ;
assertEquals ( Collections . singletonList ( "inputFile.sst" ) , compactionJobInfo . inputFiles ( ) ) ;
assertThat ( compactionJobInfo . inputFiles ( ) )
assertEquals ( Collections . singletonList ( "outputFile.sst" ) , compactionJobInfo . outputFiles ( ) ) ;
. isEqualTo ( Collections . singletonList ( "inputFile.sst" ) ) ;
assertEquals ( Collections . singletonMap ( "tableProperties" , tablePropertiesTestData ) ,
assertThat ( compactionJobInfo . outputFiles ( ) )
compactionJobInfo . tableProperties ( ) ) ;
. isEqualTo ( Collections . singletonList ( "outputFile.sst" ) ) ;
assertEquals ( CompactionReason . kFlush , compactionJobInfo . compactionReason ( ) ) ;
assertThat ( compactionJobInfo . tableProperties ( ) )
assertEquals ( CompressionType . SNAPPY_COMPRESSION , compactionJobInfo . compression ( ) ) ;
. isEqualTo ( Collections . singletonMap ( "tableProperties" , tablePropertiesTestData ) ) ;
assertThat ( compactionJobInfo . compactionReason ( ) ) . isEqualTo ( CompactionReason . kFlush ) ;
assertThat ( compactionJobInfo . compression ( ) ) . isEqualTo ( CompressionType . SNAPPY_COMPRESSION ) ;
}
}
@Override
@Override
public void onTableFileCreated ( final TableFileCreationInfo tableFileCreationInfo ) {
public void onTableFileCreated ( final TableFileCreationInfo tableFileCreationInfo ) {
super . onTableFileCreated ( tableFileCreationInfo ) ;
super . onTableFileCreated ( tableFileCreationInfo ) ;
assertEquals ( tableFileCreationInfoTestData , tableFileCreationInfo ) ;
assertThat ( tableFileCreationInfo ) . isEqualTo ( tableFileCreationInfoTestData ) ;
}
}
@Override
@Override
public void onTableFileCreationStarted (
public void onTableFileCreationStarted (
final TableFileCreationBriefInfo tableFileCreationBriefInfo ) {
final TableFileCreationBriefInfo tableFileCreationBriefInfo ) {
super . onTableFileCreationStarted ( tableFileCreationBriefInfo ) ;
super . onTableFileCreationStarted ( tableFileCreationBriefInfo ) ;
assertEquals ( tableFileCreationBriefInfoTestData , tableFileCreationBriefInfo ) ;
assertThat ( tableFileCreationBriefInfo ) . isEqualTo ( tableFileCreationBriefInfoTestData ) ;
}
}
@Override
@Override
public void onMemTableSealed ( final MemTableInfo memTableInfo ) {
public void onMemTableSealed ( final MemTableInfo memTableInfo ) {
super . onMemTableSealed ( memTableInfo ) ;
super . onMemTableSealed ( memTableInfo ) ;
assertEquals ( memTableInfoTestData , memTableInfo ) ;
assertThat ( memTableInfo ) . isEqualTo ( memTableInfoTestData ) ;
}
}
@Override
@Override
@ -352,7 +359,7 @@ public class EventListenerTest {
public void onExternalFileIngested (
public void onExternalFileIngested (
final RocksDB db , final ExternalFileIngestionInfo externalFileIngestionInfo ) {
final RocksDB db , final ExternalFileIngestionInfo externalFileIngestionInfo ) {
super . onExternalFileIngested ( db , externalFileIngestionInfo ) ;
super . onExternalFileIngested ( db , externalFileIngestionInfo ) ;
assertEquals ( externalFileIngestionInfoTestData , externalFileIngestionInfo ) ;
assertThat ( externalFileIngestionInfo ) . isEqualTo ( externalFileIngestionInfoTestData ) ;
}
}
@Override
@Override
@ -364,49 +371,49 @@ public class EventListenerTest {
@Override
@Override
public void onStallConditionsChanged ( final WriteStallInfo writeStallInfo ) {
public void onStallConditionsChanged ( final WriteStallInfo writeStallInfo ) {
super . onStallConditionsChanged ( writeStallInfo ) ;
super . onStallConditionsChanged ( writeStallInfo ) ;
assertEquals ( writeStallInfoTestData , writeStallInfo ) ;
assertThat ( writeStallInfo ) . isEqualTo ( writeStallInfoTestData ) ;
}
}
@Override
@Override
public void onFileReadFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileReadFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileReadFinish ( fileOperationInfo ) ;
super . onFileReadFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileWriteFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileWriteFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileWriteFinish ( fileOperationInfo ) ;
super . onFileWriteFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileFlushFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileFlushFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileFlushFinish ( fileOperationInfo ) ;
super . onFileFlushFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileSyncFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileSyncFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileSyncFinish ( fileOperationInfo ) ;
super . onFileSyncFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileRangeSyncFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileRangeSyncFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileRangeSyncFinish ( fileOperationInfo ) ;
super . onFileRangeSyncFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileTruncateFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileTruncateFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileTruncateFinish ( fileOperationInfo ) ;
super . onFileTruncateFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
public void onFileCloseFinish ( final FileOperationInfo fileOperationInfo ) {
public void onFileCloseFinish ( final FileOperationInfo fileOperationInfo ) {
super . onFileCloseFinish ( fileOperationInfo ) ;
super . onFileCloseFinish ( fileOperationInfo ) ;
assertEquals ( fileOperationInfoTestData , fileOperationInfo ) ;
assertThat ( fileOperationInfo ) . isEqualTo ( fileOperationInfoTestData ) ;
}
}
@Override
@Override
@ -419,15 +426,15 @@ public class EventListenerTest {
public boolean onErrorRecoveryBegin (
public boolean onErrorRecoveryBegin (
final BackgroundErrorReason backgroundErrorReason , final Status backgroundError ) {
final BackgroundErrorReason backgroundErrorReason , final Status backgroundError ) {
super . onErrorRecoveryBegin ( backgroundErrorReason , backgroundError ) ;
super . onErrorRecoveryBegin ( backgroundErrorReason , backgroundError ) ;
assertEquals ( BackgroundErrorReason . FLUSH , backgroundErrorReason ) ;
assertThat ( backgroundErrorReason ) . isEqualTo ( BackgroundErrorReason . FLUSH ) ;
assertEquals ( statusTestData , backgroundError ) ;
assertThat ( backgroundError ) . isEqualTo ( statusTestData ) ;
return true ;
return true ;
}
}
@Override
@Override
public void onErrorRecoveryCompleted ( final Status oldBackgroundError ) {
public void onErrorRecoveryCompleted ( final Status oldBackgroundError ) {
super . onErrorRecoveryCompleted ( oldBackgroundError ) ;
super . onErrorRecoveryCompleted ( oldBackgroundError ) ;
assertEquals ( statusTestData , oldBackgroundError ) ;
assertThat ( oldBackgroundError ) . isEqualTo ( statusTestData ) ;
}
}
} ;
} ;
@ -436,11 +443,13 @@ public class EventListenerTest {
// assert
// assert
assertAllEventsCalled ( listener ) ;
assertAllEventsCalled ( listener ) ;
assertNoCallbackErrors ( listener ) ;
}
}
@Test
@Test
public void testEnabledCallbacks ( ) {
public void testEnabledCallbacks ( ) {
final EnabledEventCallback enabledEvents [ ] = {
final EnabledEventCallback [ ] enabledEvents = {
EnabledEventCallback . ON_MEMTABLE_SEALED , EnabledEventCallback . ON_ERROR_RECOVERY_COMPLETED } ;
EnabledEventCallback . ON_MEMTABLE_SEALED , EnabledEventCallback . ON_ERROR_RECOVERY_COMPLETED } ;
final CapturingTestableEventListener listener =
final CapturingTestableEventListener listener =
@ -464,146 +473,65 @@ public class EventListenerTest {
assertEventsCalled ( capturingTestableEventListener , EnumSet . copyOf ( Arrays . asList ( expected ) ) ) ;
assertEventsCalled ( capturingTestableEventListener , EnumSet . copyOf ( Arrays . asList ( expected ) ) ) ;
}
}
private static void assertNoCallbackErrors (
final CapturingTestableEventListener capturingTestableEventListener ) {
for ( AssertionError error : capturingTestableEventListener . capturedAssertionErrors ) {
throw new Error ( "An assertion failed in callback" , error ) ;
}
}
private static void assertEventsCalled (
private static void assertEventsCalled (
final CapturingTestableEventListener capturingTestableEventListener ,
final CapturingTestableEventListener capturingTestableEventListener ,
final EnumSet < EnabledEventCallback > expected ) {
final EnumSet < EnabledEventCallback > expected ) {
final ListenerEvents capturedEvents = capturingTestableEventListener . capturedListenerEvents ;
final ListenerEvents capturedEvents = capturingTestableEventListener . capturedListenerEvents ;
if ( expected . contains ( EnabledEventCallback . ON_FLUSH_COMPLETED ) ) {
assertThat ( capturedEvents . flushCompleted )
assertTrue ( "onFlushCompleted was not called" , capturedEvents . flushCompleted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FLUSH_COMPLETED ) ) ;
} else {
assertThat ( capturedEvents . flushBegin )
assertFalse ( "onFlushCompleted was not called" , capturedEvents . flushCompleted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FLUSH_BEGIN ) ) ;
}
assertThat ( capturedEvents . tableFileDeleted )
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_DELETED ) ) ;
if ( expected . contains ( EnabledEventCallback . ON_FLUSH_BEGIN ) ) {
assertThat ( capturedEvents . compactionBegin )
assertTrue ( "onFlushBegin was not called" , capturedEvents . flushBegin ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_COMPACTION_BEGIN ) ) ;
} else {
assertThat ( capturedEvents . compactionCompleted )
assertFalse ( "onFlushBegin was called" , capturedEvents . flushBegin ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_COMPACTION_COMPLETED ) ) ;
}
assertThat ( capturedEvents . tableFileCreated )
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_CREATED ) ) ;
if ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_DELETED ) ) {
assertThat ( capturedEvents . tableFileCreationStarted )
assertTrue ( "onTableFileDeleted was not called" , capturedEvents . tableFileDeleted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_CREATION_STARTED ) ) ;
} else {
assertThat ( capturedEvents . memTableSealed )
assertFalse ( "onTableFileDeleted was called" , capturedEvents . tableFileDeleted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_MEMTABLE_SEALED ) ) ;
}
assertThat ( capturedEvents . columnFamilyHandleDeletionStarted )
. isEqualTo (
if ( expected . contains ( EnabledEventCallback . ON_COMPACTION_BEGIN ) ) {
expected . contains ( EnabledEventCallback . ON_COLUMN_FAMILY_HANDLE_DELETION_STARTED ) ) ;
assertTrue ( "onCompactionBegin was not called" , capturedEvents . compactionBegin ) ;
assertThat ( capturedEvents . externalFileIngested )
} else {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_EXTERNAL_FILE_INGESTED ) ) ;
assertFalse ( "onCompactionBegin was called" , capturedEvents . compactionBegin ) ;
assertThat ( capturedEvents . backgroundError )
}
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_BACKGROUND_ERROR ) ) ;
assertThat ( capturedEvents . stallConditionsChanged )
if ( expected . contains ( EnabledEventCallback . ON_COMPACTION_COMPLETED ) ) {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_STALL_CONDITIONS_CHANGED ) ) ;
assertTrue ( "onCompactionCompleted was not called" , capturedEvents . compactionCompleted ) ;
assertThat ( capturedEvents . fileReadFinish )
} else {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_READ_FINISH ) ) ;
assertFalse ( "onCompactionCompleted was called" , capturedEvents . compactionCompleted ) ;
assertThat ( capturedEvents . fileWriteFinish )
}
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_WRITE_FINISH ) ) ;
assertThat ( capturedEvents . fileFlushFinish )
if ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_CREATED ) ) {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_FLUSH_FINISH ) ) ;
assertTrue ( "onTableFileCreated was not called" , capturedEvents . tableFileCreated ) ;
assertThat ( capturedEvents . fileSyncFinish )
} else {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_SYNC_FINISH ) ) ;
assertFalse ( "onTableFileCreated was called" , capturedEvents . tableFileCreated ) ;
assertThat ( capturedEvents . fileRangeSyncFinish )
}
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_RANGE_SYNC_FINISH ) ) ;
assertThat ( capturedEvents . fileTruncateFinish )
if ( expected . contains ( EnabledEventCallback . ON_TABLE_FILE_CREATION_STARTED ) ) {
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_TRUNCATE_FINISH ) ) ;
assertTrue (
assertThat ( capturedEvents . fileCloseFinish )
"onTableFileCreationStarted was not called" , capturedEvents . tableFileCreationStarted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_FILE_CLOSE_FINISH ) ) ;
} else {
assertThat ( capturedEvents . shouldBeNotifiedOnFileIO )
assertFalse ( "onTableFileCreationStarted was called" , capturedEvents . tableFileCreationStarted ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . SHOULD_BE_NOTIFIED_ON_FILE_IO ) ) ;
}
assertThat ( capturedEvents . errorRecoveryBegin )
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_ERROR_RECOVERY_BEGIN ) ) ;
if ( expected . contains ( EnabledEventCallback . ON_MEMTABLE_SEALED ) ) {
assertThat ( capturedEvents . errorRecoveryCompleted )
assertTrue ( "onMemTableSealed was not called" , capturedEvents . memTableSealed ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_ERROR_RECOVERY_COMPLETED ) ) ;
} else {
assertThat ( capturedEvents . errorRecoveryCompleted )
assertFalse ( "onMemTableSealed was called" , capturedEvents . memTableSealed ) ;
. isEqualTo ( expected . contains ( EnabledEventCallback . ON_ERROR_RECOVERY_COMPLETED ) ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_COLUMN_FAMILY_HANDLE_DELETION_STARTED ) ) {
assertTrue ( "onColumnFamilyHandleDeletionStarted was not called" ,
capturedEvents . columnFamilyHandleDeletionStarted ) ;
} else {
assertFalse ( "onColumnFamilyHandleDeletionStarted was called" ,
capturedEvents . columnFamilyHandleDeletionStarted ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_EXTERNAL_FILE_INGESTED ) ) {
assertTrue ( "onExternalFileIngested was not called" , capturedEvents . externalFileIngested ) ;
} else {
assertFalse ( "onExternalFileIngested was called" , capturedEvents . externalFileIngested ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_BACKGROUND_ERROR ) ) {
assertTrue ( "onBackgroundError was not called" , capturedEvents . backgroundError ) ;
} else {
assertFalse ( "onBackgroundError was called" , capturedEvents . backgroundError ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_STALL_CONDITIONS_CHANGED ) ) {
assertTrue ( "onStallConditionsChanged was not called" , capturedEvents . stallConditionsChanged ) ;
} else {
assertFalse ( "onStallConditionsChanged was called" , capturedEvents . stallConditionsChanged ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_READ_FINISH ) ) {
assertTrue ( "onFileReadFinish was not called" , capturedEvents . fileReadFinish ) ;
} else {
assertFalse ( "onFileReadFinish was called" , capturedEvents . fileReadFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_WRITE_FINISH ) ) {
assertTrue ( "onFileWriteFinish was not called" , capturedEvents . fileWriteFinish ) ;
} else {
assertFalse ( "onFileWriteFinish was called" , capturedEvents . fileWriteFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_FLUSH_FINISH ) ) {
assertTrue ( "onFileFlushFinish was not called" , capturedEvents . fileFlushFinish ) ;
} else {
assertFalse ( "onFileFlushFinish was called" , capturedEvents . fileFlushFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_SYNC_FINISH ) ) {
assertTrue ( "onFileSyncFinish was not called" , capturedEvents . fileSyncFinish ) ;
} else {
assertFalse ( "onFileSyncFinish was called" , capturedEvents . fileSyncFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_RANGE_SYNC_FINISH ) ) {
assertTrue ( "onFileRangeSyncFinish was not called" , capturedEvents . fileRangeSyncFinish ) ;
} else {
assertFalse ( "onFileRangeSyncFinish was called" , capturedEvents . fileRangeSyncFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_TRUNCATE_FINISH ) ) {
assertTrue ( "onFileTruncateFinish was not called" , capturedEvents . fileTruncateFinish ) ;
} else {
assertFalse ( "onFileTruncateFinish was called" , capturedEvents . fileTruncateFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_FILE_CLOSE_FINISH ) ) {
assertTrue ( "onFileCloseFinish was not called" , capturedEvents . fileCloseFinish ) ;
} else {
assertFalse ( "onFileCloseFinish was called" , capturedEvents . fileCloseFinish ) ;
}
if ( expected . contains ( EnabledEventCallback . SHOULD_BE_NOTIFIED_ON_FILE_IO ) ) {
assertTrue (
"shouldBeNotifiedOnFileIO was not called" , capturedEvents . shouldBeNotifiedOnFileIO ) ;
} else {
assertFalse ( "shouldBeNotifiedOnFileIO was called" , capturedEvents . shouldBeNotifiedOnFileIO ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_ERROR_RECOVERY_BEGIN ) ) {
assertTrue ( "onErrorRecoveryBegin was not called" , capturedEvents . errorRecoveryBegin ) ;
} else {
assertFalse ( "onErrorRecoveryBegin was called" , capturedEvents . errorRecoveryBegin ) ;
}
if ( expected . contains ( EnabledEventCallback . ON_ERROR_RECOVERY_COMPLETED ) ) {
assertTrue ( "onErrorRecoveryCompleted was not called" , capturedEvents . errorRecoveryCompleted ) ;
} else {
assertFalse ( "onErrorRecoveryCompleted was called" , capturedEvents . errorRecoveryCompleted ) ;
}
}
}
/ * *
/ * *
@ -635,9 +563,43 @@ public class EventListenerTest {
volatile boolean errorRecoveryCompleted ;
volatile boolean errorRecoveryCompleted ;
}
}
private static class CapturingObjectAssert < T > extends ObjectAssert < T > {
private final List < AssertionError > assertionErrors ;
public CapturingObjectAssert ( T t , List < AssertionError > assertionErrors ) {
super ( t ) ;
this . assertionErrors = assertionErrors ;
}
@Override
public ObjectAssert < T > isEqualTo ( Object other ) {
try {
return super . isEqualTo ( other ) ;
} catch ( AssertionError error ) {
assertionErrors . add ( error ) ;
throw error ;
}
}
@Override
public ObjectAssert < T > isNotNull ( ) {
try {
return super . isNotNull ( ) ;
} catch ( AssertionError error ) {
assertionErrors . add ( error ) ;
throw error ;
}
}
}
private static class CapturingTestableEventListener extends TestableEventListener {
private static class CapturingTestableEventListener extends TestableEventListener {
final ListenerEvents capturedListenerEvents = new ListenerEvents ( ) ;
final ListenerEvents capturedListenerEvents = new ListenerEvents ( ) ;
final List < AssertionError > capturedAssertionErrors = new ArrayList < > ( ) ;
protected < T > AbstractObjectAssert < ? , T > assertThat ( T actual ) {
return new CapturingObjectAssert < T > ( actual , capturedAssertionErrors ) ;
}
public CapturingTestableEventListener ( ) { }
public CapturingTestableEventListener ( ) { }
public CapturingTestableEventListener ( final EnabledEventCallback . . . enabledEventCallbacks ) {
public CapturingTestableEventListener ( final EnabledEventCallback . . . enabledEventCallbacks ) {