33import static java .nio .charset .StandardCharsets .UTF_8 ;
44import static org .assertj .core .api .Assertions .assertThat ;
55
6- import java .io .*;
6+ import java .io .File ;
7+ import java .io .IOException ;
8+ import java .io .RandomAccessFile ;
79import java .util .ArrayList ;
810import java .util .List ;
11+ import org .hamcrest .CustomTypeSafeMatcher ;
912import org .hamcrest .Description ;
10- import org .hamcrest .TypeSafeMatcher ;
1113import org .junit .ClassRule ;
1214import org .junit .Rule ;
1315import org .junit .Test ;
@@ -50,15 +52,17 @@ public void multiGetKeyException() throws RocksDBException, IOException {
5052 try (Options options = new Options ().setCreateIfMissing (true ).setParanoidChecks (true );
5153 RocksDB db = RocksDB .openReadOnly (options , dbFolder .getRoot ().getAbsolutePath ())) {
5254 exception .expect (RocksDBException .class );
53- exception .expect (new TypeSafeMatcher <RocksDBException >() {
55+ exception .expect (new CustomTypeSafeMatcher <RocksDBException >(
56+ "Status.Code equal to Corruption" ) {
5457 @ Override
5558 protected boolean matchesSafely (RocksDBException e ) {
5659 return e .getStatus ().getCode () == Status .Code .Corruption ;
5760 }
5861
5962 @ Override
60- public void describeTo (Description description ) {
61- description .appendText ("Status.Code is not equal to Corruption" );
63+ protected void describeMismatchSafely (RocksDBException e , Description mismatchDescription ) {
64+ mismatchDescription .appendText (
65+ "was " + e .getStatus ().getCodeString () + " " + e .getMessage ());
6266 }
6367 });
6468
@@ -72,7 +76,9 @@ private void createCorruptedDatabase() throws RocksDBException, IOException {
7276 try (Options options = new Options ().setCreateIfMissing (true ).setParanoidChecks (true );
7377 RocksDB db = RocksDB .open (options , dbFolder .getRoot ().getAbsolutePath ())) {
7478 db .put (KEY , VALUE );
75- db .flush (new FlushOptions ().setWaitForFlush (true ));
79+ try (FlushOptions flushOptions = new FlushOptions ().setWaitForFlush (true )) {
80+ db .flush (flushOptions );
81+ }
7682 }
7783
7884 File [] files = dbFolder .getRoot ().listFiles ((dir , name ) -> name .endsWith ("sst" ));
0 commit comments