Skip to content

Commit 1d17af9

Browse files
committed
Update unit tests
1 parent 42f1a30 commit 1d17af9

File tree

2 files changed

+331
-190
lines changed

2 files changed

+331
-190
lines changed

lib/src/main/java/com/scalar/admin/kubernetes/Pauser.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import java.util.stream.Collectors;
1515
import javax.annotation.Nullable;
1616
import javax.annotation.concurrent.NotThreadSafe;
17-
import org.slf4j.Logger;
18-
import org.slf4j.LoggerFactory;
1917

2018
/**
2119
* This class implements a pause operation for Scalar product pods in a Kubernetes cluster. The
@@ -37,7 +35,6 @@ public class Pauser {
3735

3836
@VisibleForTesting static final int MAX_UNPAUSE_RETRY_COUNT = 3;
3937

40-
private final Logger logger = LoggerFactory.getLogger(Pauser.class);
4138
private final TargetSelector targetSelector;
4239
private Instant startTime;
4340
private Instant endTime;
@@ -74,8 +71,7 @@ public Pauser(String namespace, String helmReleaseName) throws PauserException {
7471
* @return The start and end time of the pause operation.
7572
*/
7673
public PausedDuration pause(int pauseDuration, @Nullable Long maxPauseWaitTime)
77-
throws PauserException, UnpauseFailedException, PauseFailedException,
78-
StatusCheckFailedException {
74+
throws PauserException {
7975
if (pauseDuration < 1) {
8076
throw new IllegalArgumentException(
8177
"pauseDuration is required to be greater than 0 millisecond.");
@@ -150,13 +146,15 @@ public PausedDuration pause(int pauseDuration, @Nullable Long maxPauseWaitTime)
150146

151147
// Check if pods and deployment information are the same between before pause and after pause.
152148
boolean compareTargetSuccessful;
149+
StatusCheckFailedException statusCheckFailedException;
153150
try {
154151
compareTargetSuccessful = compareTargetStatus(targetBeforePause, targetAfterPause);
155152
} catch (Exception e) {
153+
statusCheckFailedException = new StatusCheckFailedException(statusCheckErrorMessage, e);
156154
if (unpauseFailedException == null) {
157-
throw new StatusCheckFailedException(statusCheckErrorMessage, e);
155+
throw statusCheckFailedException;
158156
} else {
159-
throw new UnpauseFailedException(unpauseErrorMessage, e);
157+
throw new UnpauseFailedException(unpauseErrorMessage, statusCheckFailedException);
160158
}
161159
}
162160

@@ -181,12 +179,15 @@ public PausedDuration pause(int pauseDuration, @Nullable Long maxPauseWaitTime)
181179
String errorMessage = errorMessageBuilder.toString();
182180

183181
// Return the final result based on each process.
184-
if (unpauseFailedException != null) { // Unpause issue is the most critical.
182+
if (unpauseFailedException
183+
!= null) { // Unpause issue is the most critical because it might cause system down.
185184
throw new UnpauseFailedException(errorMessage, unpauseFailedException);
186185
} else if (pauseFailedException
187-
!= null) { // Pause issue might be caused by configuration error.
186+
!= null) { // Pause Failed is second priority because pause issue might be caused by
187+
// configuration error.
188188
throw new PauseFailedException(errorMessage, pauseFailedException);
189-
} else if (!compareTargetSuccessful) { // Status check issue might be caused by temporary issue.
189+
} else if (!compareTargetSuccessful) { // Status check failed is third priority because this
190+
// issue might be caused by temporary issue, for example, pod restarts.
190191
throw new PauseFailedException(errorMessage);
191192
} else { // All operations succeeded.
192193
return new PausedDuration(startTime, endTime);
@@ -221,6 +222,7 @@ RequestCoordinator getRequestCoordinator(TargetSnapshot target) {
221222
.collect(Collectors.toList()));
222223
}
223224

225+
@VisibleForTesting
224226
void pauseInternal(
225227
RequestCoordinator requestCoordinator, int pauseDuration, @Nullable Long maxPauseWaitTime) {
226228

@@ -230,6 +232,7 @@ void pauseInternal(
230232
endTime = Instant.now();
231233
}
232234

235+
@VisibleForTesting
233236
boolean compareTargetStatus(TargetSnapshot before, TargetSnapshot after) {
234237
return before.getStatus().equals(after.getStatus());
235238
}

0 commit comments

Comments
 (0)