Skip to content

Commit

Permalink
Ran 'make format'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter authored and dnnanuti committed Mar 9, 2024
1 parent b9e1363 commit b065601
Showing 1 changed file with 113 additions and 113 deletions.
226 changes: 113 additions & 113 deletions java/src/test/java/org/rocksdb/SequenceNumberAllocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,138 +59,138 @@ public void testSeqnoFlushAndClose() throws RocksDBException {
assertEquals("Sequence number changed between closing and reopening the database", 15,
db.getLatestSequenceNumber());
}
}
}
}

@Test
public void testSeqnoCloseWithoutFlush() throws RocksDBException {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 30);
assertEquals("Database values count mismatch", 30, count);
db.closeE();
}
@Test
public void testSeqnoCloseWithoutFlush() throws RocksDBException {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 30);
assertEquals("Database values count mismatch", 30, count);
db.closeE();
}

try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Sequence number changed between closing and reopening the database", 30,
db.getLatestSequenceNumber());
}
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Sequence number changed between closing and reopening the database", 30,
db.getLatestSequenceNumber());
}
}

@Test
public void testSeqnoThreadInterruptAfterFlush() throws RocksDBException {
ExecutorService executor = Executors.newFixedThreadPool(1);
AtomicLong sequenceNumberAfterFlush = new AtomicLong(0);
CountDownLatch waitingSignal = new CountDownLatch(1);
CountDownLatch dbOperationsSignal = new CountDownLatch(1);

Future<?> task = executor.submit(() -> {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final FlushOptions flushOptions = new FlushOptions();
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 10);
assertEquals("Database values count mismatch", 10, count);
db.flush(flushOptions);
sequenceNumberAfterFlush.set(db.getLatestSequenceNumber());
assertEquals("Incorrect sequence number after flush", 10, sequenceNumberAfterFlush.get());
dbOperationsSignal.countDown();
waitingSignal.await(60, TimeUnit.SECONDS);
} catch (RocksDBException e) {
fail("Encountered exception:" + e);
} catch (InterruptedException e) {
} finally {
dbOperationsSignal.countDown();
waitingSignal.countDown();
}
});

try {
dbOperationsSignal.await(5, TimeUnit.SECONDS);
task.cancel(true);
assertTrue("Failed to cancel task", task.isCancelled());
@Test
public void testSeqnoThreadInterruptAfterFlush() throws RocksDBException {
ExecutorService executor = Executors.newFixedThreadPool(1);
AtomicLong sequenceNumberAfterFlush = new AtomicLong(0);
CountDownLatch waitingSignal = new CountDownLatch(1);
CountDownLatch dbOperationsSignal = new CountDownLatch(1);

Future<?> task = executor.submit(() -> {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final FlushOptions flushOptions = new FlushOptions();
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 10);
assertEquals("Database values count mismatch", 10, count);
db.flush(flushOptions);
sequenceNumberAfterFlush.set(db.getLatestSequenceNumber());
assertEquals("Incorrect sequence number after flush", 10, sequenceNumberAfterFlush.get());
dbOperationsSignal.countDown();
waitingSignal.await(60, TimeUnit.SECONDS);
} catch (RocksDBException e) {
fail("Encountered exception:" + e);
} catch (InterruptedException e) {
} finally {
executor.shutdownNow();
assertTrue("Executor did not shutdown", executor.isShutdown());
dbOperationsSignal.countDown();
waitingSignal.countDown();
}
});

try {
dbOperationsSignal.await(5, TimeUnit.SECONDS);
task.cancel(true);
assertTrue("Failed to cancel task", task.isCancelled());
} catch (InterruptedException e) {
} finally {
executor.shutdownNow();
assertTrue("Executor did not shutdown", executor.isShutdown());
}

try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Lastest sequence number is not the one expected",
sequenceNumberAfterFlush.get(), db.getLatestSequenceNumber());
}
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Lastest sequence number is not the one expected", sequenceNumberAfterFlush.get(),
db.getLatestSequenceNumber());
}
}

@Test
public void testSeqnoDataWrittenAfterFlush() throws RocksDBException {
ExecutorService executor = Executors.newFixedThreadPool(1);
AtomicLong sequenceNumberAfterFlush = new AtomicLong(0);
CountDownLatch waitingSignal = new CountDownLatch(1);
CountDownLatch dbOperationsSignal = new CountDownLatch(1);

Future<?> task = executor.submit(() -> {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final FlushOptions flushOptions = new FlushOptions();
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 10);
assertEquals("Database values count mismatch", 10, count);
db.flush(flushOptions);
sequenceNumberAfterFlush.set(db.getLatestSequenceNumber());
assertEquals("Incorrect sequence number after flush", 10, sequenceNumberAfterFlush.get());
count = fillDatabase(db, writeOptions, 10, 20);
assertEquals("Database values count mismatch", 20, count);
assertEquals(
"Unexpected value for latest DB sequence number", 20, db.getLatestSequenceNumber());
dbOperationsSignal.countDown();
waitingSignal.await(60, TimeUnit.SECONDS);
} catch (RocksDBException e) {
fail("Encountered exception:" + e);
} catch (InterruptedException e) {
} finally {
dbOperationsSignal.countDown();
waitingSignal.countDown();
executor.shutdownNow();
assertTrue("Executor did not shutdown", executor.isShutdown());
}
});

try {
dbOperationsSignal.await(5, TimeUnit.SECONDS);
task.cancel(true);
assertTrue("Failed to cancel task", task.isCancelled());
@Test
public void testSeqnoDataWrittenAfterFlush() throws RocksDBException {
ExecutorService executor = Executors.newFixedThreadPool(1);
AtomicLong sequenceNumberAfterFlush = new AtomicLong(0);
CountDownLatch waitingSignal = new CountDownLatch(1);
CountDownLatch dbOperationsSignal = new CountDownLatch(1);

Future<?> task = executor.submit(() -> {
try (final Options options = new Options().setCreateIfMissing(true);
final WriteOptions writeOptions = new WriteOptions().setDisableWAL(disableWAL);
final FlushOptions flushOptions = new FlushOptions();
final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
int count = fillDatabase(db, writeOptions, 0, 10);
assertEquals("Database values count mismatch", 10, count);
db.flush(flushOptions);
sequenceNumberAfterFlush.set(db.getLatestSequenceNumber());
assertEquals("Incorrect sequence number after flush", 10, sequenceNumberAfterFlush.get());
count = fillDatabase(db, writeOptions, 10, 20);
assertEquals("Database values count mismatch", 20, count);
assertEquals(
"Unexpected value for latest DB sequence number", 20, db.getLatestSequenceNumber());
dbOperationsSignal.countDown();
waitingSignal.await(60, TimeUnit.SECONDS);
} catch (RocksDBException e) {
fail("Encountered exception:" + e);
} catch (InterruptedException e) {
} finally {
dbOperationsSignal.countDown();
waitingSignal.countDown();
executor.shutdownNow();
assertTrue("Executor did not shutdown", executor.isShutdown());
}

int expectedSequenceNumber = disableWAL ? 10 : 20;
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Lastest sequence number is not the one expected",
expectedSequenceNumber, db.getLatestSequenceNumber());
}
});

try {
dbOperationsSignal.await(5, TimeUnit.SECONDS);
task.cancel(true);
assertTrue("Failed to cancel task", task.isCancelled());
} catch (InterruptedException e) {
} finally {
executor.shutdownNow();
assertTrue("Executor did not shutdown", executor.isShutdown());
}

private int fillDatabase(RocksDB db, WriteOptions writeOptions, int start, int end)
throws RocksDBException {
assertEquals("Database does not have expected sequence number " + start, start,
int expectedSequenceNumber = disableWAL ? 10 : 20;
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
assertTrue("Database should not be empty", db.getLatestSequenceNumber() != 0);
assertEquals("Lastest sequence number is not the one expected", expectedSequenceNumber,
db.getLatestSequenceNumber());
int count;
for (count = start; count < end; ++count) {
byte[] key = ("key" + count).getBytes(StandardCharsets.UTF_8);
byte[] value = ("value" + count).getBytes(StandardCharsets.UTF_8);
db.put(writeOptions, key, value);
assertEquals("Sequence number is not updated", count + 1, db.getLatestSequenceNumber());
}
}
}

return count;
private int fillDatabase(RocksDB db, WriteOptions writeOptions, int start, int end)
throws RocksDBException {
assertEquals("Database does not have expected sequence number " + start, start,
db.getLatestSequenceNumber());
int count;
for (count = start; count < end; ++count) {
byte[] key = ("key" + count).getBytes(StandardCharsets.UTF_8);
byte[] value = ("value" + count).getBytes(StandardCharsets.UTF_8);
db.put(writeOptions, key, value);
assertEquals("Sequence number is not updated", count + 1, db.getLatestSequenceNumber());
}

return count;
}
}

0 comments on commit b065601

Please sign in to comment.