Skip to content

Commit

Permalink
Code review clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Meredith Baxter <[email protected]>
  • Loading branch information
mbaxter committed Oct 28, 2019
1 parent 6420cf6 commit b8d2334
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private enum State {
private final IbftEventQueue eventQueue;
private final IbftExecutors ibftExecutors;

private long blockAddedObserverId;
private AtomicReference<State> state = new AtomicReference<>(State.IDLE);

public IbftMiningCoordinator(
Expand All @@ -71,13 +72,13 @@ public IbftMiningCoordinator(
this.eventQueue = eventQueue;

this.blockchain = blockchain;
this.blockchain.observeBlockAdded(this);
}

@Override
public void start() {
if (state.compareAndSet(State.IDLE, State.RUNNING)) {
ibftExecutors.start();
blockAddedObserverId = blockchain.observeBlockAdded(this);
controller.start();
ibftExecutors.executeIbftProcessor(ibftProcessor);
}
Expand All @@ -86,6 +87,7 @@ public void start() {
@Override
public void stop() {
if (state.compareAndSet(State.RUNNING, State.STOPPED)) {
blockchain.removeObserver(blockAddedObserverId);
ibftProcessor.stop();
// Make sure the processor has stopped before shutting down the executors
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -84,7 +83,7 @@ public void stopsMining() {

ibftMiningCoordinator.start();
ibftMiningCoordinator.stop();
verify(ibftProcessor, times(1)).stop();
verify(ibftProcessor).stop();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void returnsCorrectMethodName() {
}

@Test
public void shouldReturnTrueWhenMiningCoordinatorExistsAndRunning() {
public void shouldReturnTrueWhenMining() {
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), true);
when(miningCoordinator.isMining()).thenReturn(true);
Expand All @@ -61,7 +61,7 @@ public void shouldReturnTrueWhenMiningCoordinatorExistsAndRunning() {
}

@Test
public void shouldReturnFalseWhenMiningCoordinatorExistsAndDisabled() {
public void shouldReturnFalseWhenNotMining() {
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), false);
when(miningCoordinator.isMining()).thenReturn(false);
Expand Down

0 comments on commit b8d2334

Please sign in to comment.