import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.log4j.Logger;
private final CEQueueStatus queueStatus;
private final ComputeEngineStatus computeEngineStatus;
- // state
- private AtomicBoolean peekPaused = new AtomicBoolean(false);
-
public InternalCeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, CEQueueStatus queueStatus,
DefaultOrganizationProvider defaultOrganizationProvider, ComputeEngineStatus computeEngineStatus) {
super(dbClient, uuidFactory, defaultOrganizationProvider);
public Optional<CeTask> peek(String workerUuid) {
requireNonNull(workerUuid, "workerUuid can't be null");
- if (peekPaused.get() || computeEngineStatus.getStatus() != ComputeEngineStatus.Status.STARTED) {
+ if (computeEngineStatus.getStatus() != ComputeEngineStatus.Status.STARTED) {
return Optional.empty();
}
try (DbSession dbSession = dbClient.openSession(false)) {
}
}
- @Override
- public void pausePeek() {
- this.peekPaused.set(true);
- }
-
- @Override
- public void resumePeek() {
- this.peekPaused.set(false);
- }
-
- @Override
- public boolean isPeekPaused() {
- return peekPaused.get();
- }
-
/**
* A {@link PrintWriter} subclass which enforces that line returns are {@code \n} whichever the platform.
*/
assertThat(ceQueueDto.getWorkerUuid()).isEqualTo(WORKER_UUID_1);
}
- @Test
- public void peek_nothing_if_paused() throws Exception {
- submit(CeTaskTypes.REPORT, "PROJECT_1");
- underTest.pausePeek();
-
- Optional<CeTask> peek = underTest.peek(WORKER_UUID_1);
- assertThat(peek.isPresent()).isFalse();
- }
-
@Test
public void peek_nothing_if_application_status_stopping() throws Exception {
submit(CeTaskTypes.REPORT, "PROJECT_1");
assertThat(underTest.isSubmitPaused()).isFalse();
}
- @Test
- public void pause_and_resume_peeks() throws Exception {
- assertThat(underTest.isPeekPaused()).isFalse();
- underTest.pausePeek();
- assertThat(underTest.isPeekPaused()).isTrue();
- underTest.resumePeek();
- assertThat(underTest.isPeekPaused()).isFalse();
- }
-
private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto) {
if (componentDto == null) {
assertThat(task.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid());