mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
improve RunStateImage API and tests
This commit is contained in:
parent
ef7f35bcf4
commit
c35998ff25
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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
|
||||
* 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.
|
||||
* This is signaled <EM>by the motor</EM> after {@link Runnable#run}, but before entering the main processing
|
||||
* loop.
|
||||
*/
|
||||
Starting("s⏫"),
|
||||
Starting("⏫"),
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
@ -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
|
||||
* {@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.
|
||||
@ -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
|
||||
* {@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.
|
||||
*/
|
||||
Errored("E⚠");
|
||||
Errored("⚠");
|
||||
|
||||
private final String runcode;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -63,7 +63,7 @@ public class RunStateImage {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -27,13 +27,17 @@ public class RunStateImageTest {
|
||||
public void testMaxStateImage() {
|
||||
int[] counts = new int[RunState.values().length];
|
||||
counts[RunState.Running.ordinal()]=3;
|
||||
counts[RunState.Starting.ordinal()]=2;
|
||||
RunStateImage image = new RunStateImage(counts, false);
|
||||
assertThat(image.is(RunState.Running)).isTrue();
|
||||
assertThat(image.is(RunState.Starting)).isTrue();
|
||||
assertThat(image.isTimeout()).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();
|
||||
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()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user