Skip to content

Commit

Permalink
Improve tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardladenthin committed Mar 27, 2024
1 parent 89731e9 commit 6200615
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public class ConsumerJava implements Consumer {
@VisibleForTesting
static Duration AWAIT_DURATION_QUEUE_EMPTY = Duration.ofMinutes(1);

/**
* The duration for a cyclic check to test the keys queue is empty.
*/
private static final Duration DURATION_CYCLIC_CHECK_KEYS_QUEUE_EMPTY = Duration.ofMillis(100L);

public static final String MISS_PREFIX = "miss: Could not find the address: ";
public static final String HIT_PREFIX = "hit: Found the address: ";
public static final String VANITY_HIT_PREFIX = "vanity pattern match: ";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @formatter:off
/**
* Copyright 2024 Bernard Ladenthin bernard.ladenthin@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// @formatter:on
package net.ladenthin.bitcoinaddressfinder;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)

/**
* It is an await time test. This tests changes timing durations. Especially for {@link java.util.concurrent.ExecutorService#awaitTermination}.
*/
public @interface AwaitTimeTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ public void startStatisticsTimer_invalidparameter_throwsException() throws IOExc
consumerJava.startStatisticsTimer();
}

/**
* Attention, this is an await time test. This tests changes {@link ConsumerJava#AWAIT_DURATION_QUEUE_EMPTY}.
*/
@AwaitTimeTest
@Test
public void interrupt_keysQueueNotEmpty_consumerNotRunningWaitedInternallyForTheDuration() throws IOException, InterruptedException, MnemonicException.MnemonicLengthException {
// Attention: Change the duration.
// Change await duration
ConsumerJava.AWAIT_DURATION_QUEUE_EMPTY = AwaitTimeTests.AWAIT_DURATION;

CConsumerJava cConsumerJava = new CConsumerJava();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ public void shutdownAndAwaitTermination_producersSetAndNotInitialized_shutdownCa
assertThat(finder.producerExecutorService.isTerminated(), is(equalTo(Boolean.TRUE)));
}

/**
* Attention, this is an await time test. This tests changes {@link Finder#AWAIT_DURATION_TERMINATE}.
*/
@AwaitTimeTest
@Test
public void shutdownAndAwaitTermination_producersSetAndInitialized_shutdownCalledAndAwaitTermination() throws IOException {
// Attention: Change the duration.
// Change await duration
Finder.AWAIT_DURATION_TERMINATE = AwaitTimeTests.AWAIT_DURATION;

// Attention: During the long duration, this test produce a lot of debug and warn output, prevent it by set the log details
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/net/ladenthin/bitcoinaddressfinder/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.ladenthin.bitcoinaddressfinder.cli.Main;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -69,7 +72,6 @@ public void testRoundtrip_configurationsGiven_lmdbCreatedExportedAndRunFindSecre
}
// </editor-fold>


// <editor-fold defaultstate="collapsed" desc="testRoundtrip OpenCL producer">
@Test
@OpenCLTest
Expand All @@ -82,6 +84,16 @@ public void testRoundtripOpenCLProducer_configurationsGiven_lmdbCreatedAndRunFin
new LogLevelChange().setLevel(Level.DEBUG);

Main mainFind_1OpenCLDevice = Main.createFromConfigurationFile(config_Find_1OpenCLDevice_js);


ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

// interrupt the act after 10 seconds
scheduledExecutorService.schedule(() -> {
mainFind_1OpenCLDevice.interrupt();
}, 10, TimeUnit.SECONDS);

// act
mainFind_1OpenCLDevice.run();
}
// </editor-fold>
Expand Down

0 comments on commit 6200615

Please sign in to comment.