Skip to content

Commit

Permalink
Improve and add tests, add missing shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardladenthin committed Mar 25, 2024
1 parent ae79fc9 commit 6dabecc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int getFreeThreads() {
@Override
public void releaseProducer() {
super.releaseProducer();
resultReaderThreadPoolExecutor.shutdown();
if (openCLContext != null) {
openCLContext.release();
openCLContext = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public void turnOff() {
final Logger logger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.setLevel(Level.OFF);
}
public void setLevel(Level newLevel) {
final Logger logger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.setLevel(newLevel);
}
}
20 changes: 20 additions & 0 deletions src/test/java/net/ladenthin/bitcoinaddressfinder/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// @formatter:on
package net.ladenthin.bitcoinaddressfinder;

import ch.qos.logback.classic.Level;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -49,6 +50,8 @@ public class MainTest {
private final Path config_LMDBToAddressFile_js = testRoundtripDirectory.resolve("config_LMDBToAddressFile.js");
private final Path config_Find_SecretsFile_js = testRoundtripDirectory.resolve("config_Find_SecretsFile.js");

private final Path config_Find_1OpenCLDevice_js = testRoundtripDirectory.resolve("config_Find_1OpenCLDevice.js");

private final Path config_OpenCLInfo_js = testOpenCLInfoDirectory.resolve("config_OpenCLInfo.js");

// <editor-fold defaultstate="collapsed" desc="testRoundtrip">
Expand All @@ -66,6 +69,23 @@ public void testRoundtrip_configurationsGiven_lmdbCreatedExportedAndRunFindSecre
}
// </editor-fold>


// <editor-fold defaultstate="collapsed" desc="testRoundtrip OpenCL producer">
@Test
@OpenCLTest
public void testRoundtripOpenCLProducer_configurationsGiven_lmdbCreatedAndRunFindOpenCLDevice() throws IOException, InterruptedException {
new OpenCLPlatformAssume().assumeOpenCLLibraryLoadableAndOneOpenCL2_0OrGreaterDeviceAvailable();
// arrange
Main mainAddressFilesToLMDB = Main.createFromConfigurationFile(config_AddressFilesToLMDB_js);
mainAddressFilesToLMDB.run();

new LogLevelChange().setLevel(Level.INFO);

Main mainFind_1OpenCLDevice = Main.createFromConfigurationFile(config_Find_1OpenCLDevice_js);
mainFind_1OpenCLDevice.run();
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="testRoundtrip">
@Test
@OpenCLTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void initProducer_configurationGiven_stateInitializedAndLogged() throws I
// <editor-fold defaultstate="collapsed" desc="releaseProducer">
@OpenCLTest
@Test
public void releaseProducer_configurationGiven_stateInitializedAndLogged() throws IOException, InterruptedException {
public void releaseProducer_configurationGiven_stateInitializedAndLoggedAndExecuterServiceShutdown() throws IOException, InterruptedException {
new OpenCLPlatformAssume().assumeOpenCLLibraryLoadableAndOneOpenCL2_0OrGreaterDeviceAvailable();
CProducerOpenCL cProducerOpenCL = new CProducerOpenCL();
MockConsumer mockConsumer = new MockConsumer();
Expand All @@ -71,6 +71,7 @@ public void releaseProducer_configurationGiven_stateInitializedAndLogged() throw
ProducerOpenCL producerOpenCL = new ProducerOpenCL(cProducerOpenCL, mockConsumer, keyUtility, mockSecretFactory);

AbstractProducerTest.verifyReleaseProducer(producerOpenCL);
assertThat(producerOpenCL.resultReaderThreadPoolExecutor.isShutdown(), is(equalTo(Boolean.TRUE)));
}
// </editor-fold>

Expand Down
33 changes: 33 additions & 0 deletions src/test/resources/testRoundtrip/config_Find_1OpenCLDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"command": "Find",
"finder" : {
"consumerJava" : {
"lmdbConfigurationReadOnly" : {
"lmdbDirectory" : "src/test/resources/testRoundtrip/lmdb",
"useProxyOptimal" : true,
"logStatsOnInit" : true,
"logStatsOnClose" : false
},
"threads" : 8,
"delayEmptyConsumer" : 50,
"printStatisticsEveryNSeconds" : 10,
"queueSize" : 4,
"runtimePublicKeyCalculationCheck" : false,
"enableVanity" : false,
"vanityPattern" : "1[Ee][Mm][Ii][Ll].*"
},
"producerOpenCL" : [
{
"privateKeyMaxNumBits" : 256,
"platformIndex" : 0,
"deviceType" : -1,
"deviceIndex" : 0,
"gridNumBits" : 18,
"maxResultReaderThreads" : 4,
"delayBlockedReader" : 50
}
],
"producerJava" : [
]
}
}

0 comments on commit 6dabecc

Please sign in to comment.