improve RunStateImage API and tests

This commit is contained in:
Jonathan Shook 2023-02-05 20:30:33 -06:00
parent ef7f35bcf4
commit c35998ff25
3 changed files with 17 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,27 +35,27 @@ public enum RunState {
* Initial state after creation of a motor. This is the initial state upon instantiation of a motor, before * Initial state after creation of a motor. This is the initial state upon instantiation of a motor, before
* it is called on to do any active logic besides what occurs in the constructor. * it is called on to do any active logic besides what occurs in the constructor.
*/ */
Uninitialized("i"), Uninitialized(""),
/** /**
* A thread has been invoked, but is initializing and preparing for its main control loop. * A thread has been invoked, but is initializing and preparing for its main control loop.
* This is signaled <EM>by the motor</EM> after {@link Runnable#run}, but before entering the main processing * This is signaled <EM>by the motor</EM> after {@link Runnable#run}, but before entering the main processing
* loop. * loop.
*/ */
Starting("s"), Starting(""),
/** /**
* A thread is iterating within the main control loop. * A thread is iterating within the main control loop.
* This is signaled <EM>by the motor</EM> once initialization in the main loop is complete and immediately * This is signaled <EM>by the motor</EM> once initialization in the main loop is complete and immediately
* before it enters it's main processing loop. * before it enters it's main processing loop.
*/ */
Running("R\u23F5"), Running("\u23F5"),
/** /**
* <P>The thread has been requested to stop. This can be set by a managing thread which is not the * <P>The thread has been requested to stop. This can be set by a managing thread which is not the
* motor thread, or by the motor thread. In either case, the motor thread is required to observe changes to this and initiate shutdown.</P> * motor thread, or by the motor thread. In either case, the motor thread is required to observe changes to this and initiate shutdown.</P>
*/ */
Stopping("s"), Stopping(""),
/** /**
* The thread has stopped. This should only be set by the motor. This state will only be visible * The thread has stopped. This should only be set by the motor. This state will only be visible
@ -64,7 +64,7 @@ public enum RunState {
* <P>NOTE: When a motor is stopped or finished, its state will remain visible in state tracking until * <P>NOTE: When a motor is stopped or finished, its state will remain visible in state tracking until
* {@link Motor#getState()}.{@link MotorState#removeState()} is called.</P> * {@link Motor#getState()}.{@link MotorState#removeState()} is called.</P>
*/ */
Stopped("e\u23F9"), Stopped("\u23F9"),
/** /**
* <P>A thread has exhausted its supply of values on the input (AKA cycles), thus has completed its work. * <P>A thread has exhausted its supply of values on the input (AKA cycles), thus has completed its work.
@ -73,12 +73,12 @@ public enum RunState {
* <P>NOTE: When a motor is stopped or finished, its state will remain visible in state tracking until * <P>NOTE: When a motor is stopped or finished, its state will remain visible in state tracking until
* {@link Motor#getState()}.{@link MotorState#removeState()} is called.</P> * {@link Motor#getState()}.{@link MotorState#removeState()} is called.</P>
*/ */
Finished("F"), Finished(""),
/** /**
* If a motor has seen an exception, it goes into errored state before propagating the error. * If a motor has seen an exception, it goes into errored state before propagating the error.
*/ */
Errored("E"); Errored("");
private final String runcode; private final String runcode;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -63,7 +63,7 @@ public class RunStateImage {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (RunState runState : RunState.values()) { for (RunState runState : RunState.values()) {
sb.append(runState.getCode()).append(" ").append(counts[runState.ordinal()]).append(" "); sb.append(runState.getCode()).append(":").append(counts[runState.ordinal()]).append(" ");
} }
return sb.toString(); return sb.toString();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,13 +27,17 @@ public class RunStateImageTest {
public void testMaxStateImage() { public void testMaxStateImage() {
int[] counts = new int[RunState.values().length]; int[] counts = new int[RunState.values().length];
counts[RunState.Running.ordinal()]=3; counts[RunState.Running.ordinal()]=3;
counts[RunState.Starting.ordinal()]=2;
RunStateImage image = new RunStateImage(counts, false); RunStateImage image = new RunStateImage(counts, false);
assertThat(image.is(RunState.Running)).isTrue(); assertThat(image.is(RunState.Running)).isTrue();
assertThat(image.is(RunState.Starting)).isTrue();
assertThat(image.isTimeout()).isFalse(); assertThat(image.isTimeout()).isFalse();
assertThat(image.is(RunState.Errored)).isFalse(); assertThat(image.is(RunState.Errored)).isFalse();
assertThat(image.isOnly(RunState.Running)).isTrue(); assertThat(image.isNonOther(RunState.Starting, RunState.Running)).isTrue();
RunState maxState = image.getMaxState(); RunState maxState = image.getMaxState();
assertThat(maxState).isEqualTo(RunState.values()[2]); assertThat(maxState).isEqualTo(RunState.values()[RunState.Running.ordinal()]);
RunState minState = image.getMinState();
assertThat(minState).isEqualTo(RunState.values()[RunState.St.ordinal()]);
} }
} }