Skip to content

Commit

Permalink
initLMDB to prevent NPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardladenthin committed Mar 27, 2024
1 parent 366578c commit 7999322
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ public void initLMDB_lmdbNotExisting_noExceptionThrown() throws IOException {
@Test
public void startStatisticsTimer_noExceptionThrown() throws IOException, InterruptedException {
final int runTimes = 3;

TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();
TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

CConsumerJava cConsumerJava = new CConsumerJava();
cConsumerJava.lmdbConfigurationReadOnly = new CLMDBConfigurationReadOnly();
cConsumerJava.lmdbConfigurationReadOnly.lmdbDirectory = lmdbFolderPath.getAbsolutePath();
cConsumerJava.printStatisticsEveryNSeconds = 1;
ConsumerJava consumerJava = new ConsumerJava(cConsumerJava, keyUtility, persistenceUtils);
Logger logger = mock(Logger.class);
consumerJava.setLogger(logger);
consumerJava.initLMDB();

// act
consumerJava.startStatisticsTimer();
Expand Down Expand Up @@ -130,10 +138,17 @@ public void interrupt_keysQueueNotEmpty_consumerNotRunningWaitedInternallyForThe
// Change await duration
ConsumerJava.AWAIT_DURATION_QUEUE_EMPTY = AwaitTimeTests.AWAIT_DURATION;

TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();
TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

CConsumerJava cConsumerJava = new CConsumerJava();
cConsumerJava.lmdbConfigurationReadOnly = new CLMDBConfigurationReadOnly();
cConsumerJava.lmdbConfigurationReadOnly.lmdbDirectory = lmdbFolderPath.getAbsolutePath();
ConsumerJava consumerJava = new ConsumerJava(cConsumerJava, keyUtility, persistenceUtils);
Logger logger = mock(Logger.class);
consumerJava.setLogger(logger);
consumerJava.initLMDB();

// add keys
consumerJava.consumeKeys(createExamplePublicKeyBytesfromPrivateKey73());
Expand Down Expand Up @@ -167,11 +182,19 @@ public void interrupt_keysQueueNotEmpty_consumerNotRunningWaitedInternallyForThe

@Test
public void interrupt_statisticsTimerStarted_executerServiceShutdown() throws IOException, InterruptedException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();
TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

CConsumerJava cConsumerJava = new CConsumerJava();
cConsumerJava.lmdbConfigurationReadOnly = new CLMDBConfigurationReadOnly();
cConsumerJava.lmdbConfigurationReadOnly.lmdbDirectory = lmdbFolderPath.getAbsolutePath();
cConsumerJava.printStatisticsEveryNSeconds = 1;
ConsumerJava consumerJava = new ConsumerJava(cConsumerJava, keyUtility, persistenceUtils);

Logger logger = mock(Logger.class);
consumerJava.setLogger(logger);
consumerJava.initLMDB();
// pre-assert
assertThat(consumerJava.scheduledExecutorService.isShutdown(), is(equalTo(Boolean.FALSE)));

Expand All @@ -194,7 +217,6 @@ public void interrupt_statisticsTimerStarted_executerServiceShutdown() throws IO
@Test
public void initLMDB_initialize_databaseOpened() throws IOException, InterruptedException, DecoderException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

Expand All @@ -218,7 +240,6 @@ public void initLMDB_initialize_databaseOpened() throws IOException, Interrupted
@Test
public void interrupt_consumerInitialized_databaseClosed() throws IOException, InterruptedException, DecoderException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

Expand All @@ -244,7 +265,6 @@ public void interrupt_consumerInitialized_databaseClosed() throws IOException, I
@UseDataProvider(value = CommonDataProvider.DATA_PROVIDER_COMPRESSED_AND_STATIC_AMOUNT, location = CommonDataProvider.class)
public void runProber_testAddressGiven_hitExpected(boolean compressed, boolean useStaticAmount) throws IOException, InterruptedException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(compressed);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, useStaticAmount, false);

Expand Down Expand Up @@ -304,7 +324,6 @@ public void runProber_testAddressGiven_hitExpected(boolean compressed, boolean u
@UseDataProvider(value = CommonDataProvider.DATA_PROVIDER_COMPRESSED_AND_STATIC_AMOUNT, location = CommonDataProvider.class)
public void runProber_unknownAddressGiven_missExpectedAndLogMessagesInDebugAndTrace(boolean compressed, boolean useStaticAmount) throws IOException, InterruptedException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(compressed);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, useStaticAmount, false);

Expand Down Expand Up @@ -367,7 +386,6 @@ public void runProber_unknownAddressGiven_missExpectedAndLogMessagesInDebugAndTr
@Test
public void consumeKeys_invalidSecretGiven_continueExpectedAndNoExceptionThrown() throws IOException, InterruptedException, DecoderException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

Expand All @@ -392,7 +410,6 @@ public void consumeKeys_invalidSecretGiven_continueExpectedAndNoExceptionThrown(
@UseDataProvider(value = CommonDataProvider.DATA_PROVIDER_COMPRESSED, location = CommonDataProvider.class)
public void consumeKeys_invalidPublicKeyHashUncompressedGiven_ThrowException(boolean compressed) throws IOException, InterruptedException, DecoderException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

Expand Down Expand Up @@ -447,7 +464,6 @@ public void consumeKeys_invalidPublicKeyHashUncompressedGiven_ThrowException(boo
@UseDataProvider(value = CommonDataProvider.DATA_PROVIDER_COMPRESSED, location = CommonDataProvider.class)
public void consumeKeys_testVanityPattern_patternMatches(boolean compressed) throws IOException, InterruptedException, DecoderException, MnemonicException.MnemonicLengthException {
TestAddressesLMDB testAddressesLMDB = new TestAddressesLMDB();

TestAddressesFiles testAddresses = new TestAddressesFiles(false);
File lmdbFolderPath = testAddressesLMDB.createTestLMDB(folder, testAddresses, true, true);

Expand Down

0 comments on commit 7999322

Please sign in to comment.