*/
package org.sonar.ce.queue;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.ce.queue.CeQueue;
import org.sonar.ce.queue.CeTask;
*/
package org.sonar.ce.queue;
-import com.google.common.base.Optional;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
requireNonNull(workerUuid, "workerUuid can't be null");
if (peekPaused.get()) {
- return Optional.absent();
+ return Optional.empty();
}
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<CeQueueDto> dto = dbClient.ceQueueDao().peek(dbSession, workerUuid, MAX_EXECUTION_COUNT);
task = loadTask(dbSession, dto.get());
queueStatus.addInProgress();
}
- return Optional.fromNullable(task);
+ return Optional.ofNullable(task);
}
}
*/
package org.sonar.ce.taskprocessor;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.ce.queue.CeTask;
import org.sonar.ce.taskprocessor.CeTaskProcessor;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.sonar.ce.queue.CeTask;
import org.sonar.ce.taskprocessor.CeTaskProcessor;
@Override
public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) {
- return Optional.fromNullable(taskProcessorByCeTaskType.get(ceTask.getType()));
+ return Optional.ofNullable(taskProcessorByCeTaskType.get(ceTask.getType()));
}
private static Map<String, CeTaskProcessor> indexTaskProcessors(CeTaskProcessor[] taskProcessors) {
*/
package org.sonar.ce.taskprocessor;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
} catch (Exception e) {
LOG.error("Failed to pop the queue of analysis reports", e);
}
- return Optional.absent();
+ return Optional.empty();
}
private void executeTask(CeTask task) {
*/
package org.sonar.ce.queue;
-import com.google.common.base.Optional;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
+import java.util.Optional;
import java.util.Random;
import javax.annotation.Nullable;
-import org.assertj.guava.api.Assertions;
+import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
Optional<CeActivityDto> activityDto = dbTester.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid());
- Assertions.assertThat(activityDto).isPresent();
+ assertThat(activityDto).isPresent();
assertThat(activityDto.get().getErrorMessage()).isEqualTo(error.getMessage());
assertThat(activityDto.get().getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error));
@Test
public void fail_to_cancel_if_in_progress() throws Exception {
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(startsWith("Task is in progress and can't be canceled"));
+ expectedException.expectMessage(Matchers.startsWith("Task is in progress and can't be canceled"));
CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
underTest.peek(WORKER_UUID_2);
}
private void verifyCanceled(CeQueueDto original) {
- Assertions.assertThat(dbTester.getDbClient().ceQueueDao().selectByUuid(dbTester.getSession(), original.getUuid())).isAbsent();
+ assertThat(dbTester.getDbClient().ceQueueDao().selectByUuid(dbTester.getSession(), original.getUuid())).isEmpty();
CeActivityDto dto = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), original.getUuid()).get();
assertThat(dto.getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
assertThat(dto.getExecutionCount()).isEqualTo(original.getExecutionCount());
import com.google.common.collect.ImmutableSet;
import java.util.Set;
-import org.assertj.guava.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
-
public class CeTaskProcessorRepositoryImplTest {
private static final String SOME_CE_TASK_TYPE = "some type";
private static final String SOME_COMPONENT_KEY = "key";
public void getForTask_returns_absent_if_repository_is_empty() {
CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] {});
- Assertions.assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isAbsent();
+ assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isEmpty();
}
@Test
createCeTaskProcessor(SOME_CE_TASK_TYPE + "_2", SOME_CE_TASK_TYPE + "_3"),
});
- Assertions.assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isAbsent();
+ assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isEmpty();
}
@Test
*/
package org.sonar.ce.taskprocessor;
-import com.google.common.base.Optional;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import org.junit.rules.ExternalResource;
import org.sonar.ce.queue.CeTask;
public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) {
CeTaskProcessor taskProcessor = index.get(ceTask.getType());
checkState(taskProcessor != null, "CeTaskProcessor was not set in rule for task %s", ceTask);
- return taskProcessor instanceof NoCeTaskProcessor ? Optional.<CeTaskProcessor>absent() : Optional.of(taskProcessor);
+ return taskProcessor instanceof NoCeTaskProcessor ? Optional.empty() : Optional.of(taskProcessor);
}
private enum NoCeTaskProcessor implements CeTaskProcessor {
*/
package org.sonar.ce.taskprocessor;
-import com.google.common.base.Optional;
import java.util.List;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
@Test
public void no_pending_tasks_in_queue() throws Exception {
- when(queue.peek(UNKNOWN_WORKER_UUID)).thenReturn(Optional.<CeTask>absent());
+ when(queue.peek(UNKNOWN_WORKER_UUID)).thenReturn(Optional.empty());
assertThat(underTest.call()).isFalse();
*/
package org.sonar.db.ce;
-import com.google.common.base.Optional;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
}
public Optional<CeActivityDto> selectByUuid(DbSession dbSession, String uuid) {
- return Optional.fromNullable(mapper(dbSession).selectByUuid(uuid));
+ return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid));
}
public void insert(DbSession dbSession, CeActivityDto dto) {
*/
package org.sonar.db.ce;
-import com.google.common.base.Optional;
import java.util.List;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.utils.System2;
}
public Optional<CeQueueDto> selectByUuid(DbSession session, String uuid) {
- return Optional.fromNullable(mapper(session).selectByUuid(uuid));
+ return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
public List<CeQueueDto> selectPendingByMinimumExecutionCount(DbSession dbSession, int minExecutionCount) {
public Optional<CeQueueDto> peek(DbSession session, String workerUuid, int maxExecutionCount) {
List<EligibleTaskDto> eligibles = mapper(session).selectEligibleForPeek(maxExecutionCount, ONE_RESULT_PAGINATION);
if (eligibles.isEmpty()) {
- return Optional.absent();
+ return Optional.empty();
}
EligibleTaskDto eligible = eligibles.get(0);
new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, eligible.getExecutionCount() + 1, now, now),
new UpdateIf.OldProperties(PENDING, eligible.getExecutionCount()));
if (touchedRows != 1) {
- return Optional.absent();
+ return Optional.empty();
}
CeQueueDto result = mapper(session).selectByUuid(eligible.getUuid());
package org.sonar.db.ce;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.junit.Rule;
import org.junit.Test;
CeActivityDto inserted = insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS);
Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
- assertThat(saved.isPresent()).isTrue();
+ assertThat(saved).isPresent();
CeActivityDto dto = saved.get();
assertThat(dto.getUuid()).isEqualTo("TASK_1");
assertThat(dto.getComponentUuid()).isEqualTo("PROJECT_1");
underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3"));
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isFalse();
- assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").isPresent()).isTrue();
+ assertThat(underTest.selectByUuid(db.getSession(), "TASK_2")).isPresent();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").isPresent()).isFalse();
}
// must not fail
underTest.deleteByUuids(db.getSession(), singleton("TASK_2"));
- assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isTrue();
+ assertThat(underTest.selectByUuid(db.getSession(), "TASK_1")).isPresent();
}
@Test
package org.sonar.db.ce;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Random;
import java.util.stream.Stream;
import javax.annotation.Nullable;
insert(TASK_UUID_1, COMPONENT_UUID_1, PENDING);
underTest.deleteByUuid(db.getSession(), "UNKNOWN");
- assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1).isPresent()).isTrue();
+ assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1)).isPresent();
underTest.deleteByUuid(db.getSession(), TASK_UUID_1);
assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1).isPresent()).isFalse();
// peek first one
Optional<CeQueueDto> peek = underTest.peek(db.getSession(), WORKER_UUID_1, MAX_EXECUTION_COUNT);
- assertThat(peek.isPresent()).isTrue();
+ assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(TASK_UUID_1);
assertThat(peek.get().getStatus()).isEqualTo(IN_PROGRESS);
assertThat(peek.get().getWorkerUuid()).isEqualTo(WORKER_UUID_1);
// peek second one
peek = underTest.peek(db.getSession(), WORKER_UUID_2, MAX_EXECUTION_COUNT);
- assertThat(peek.isPresent()).isTrue();
+ assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(TASK_UUID_2);
assertThat(peek.get().getStatus()).isEqualTo(IN_PROGRESS);
assertThat(peek.get().getWorkerUuid()).isEqualTo(WORKER_UUID_2);
insert(TASK_UUID_2, COMPONENT_UUID_1, PENDING);
Optional<CeQueueDto> peek = underTest.peek(db.getSession(), WORKER_UUID_1, MAX_EXECUTION_COUNT);
- assertThat(peek.isPresent()).isTrue();
+ assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(TASK_UUID_1);
assertThat(peek.get().getWorkerUuid()).isEqualTo(WORKER_UUID_1);
assertThat(peek.get().getExecutionCount()).isEqualTo(1);
package org.sonar.ce.queue;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
if (dto.getComponentUuid() == null) {
return new CeQueueDtoToCeTask(defaultOrganizationProvider.get().getUuid()).apply(dto);
}
- Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, dto.getComponentUuid());
+ com.google.common.base.Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, dto.getComponentUuid());
if (componentDto.isPresent()) {
return new CeQueueDtoToCeTask(defaultOrganizationProvider.get().getUuid(), ImmutableMap.of(dto.getComponentUuid(), componentDto.get())).apply(dto);
}
return Optional.absent();
}
- Optional<CeQueueDto> queue = dbClient.ceQueueDao().selectByUuid(dbSession, textQuery);
+ java.util.Optional<CeQueueDto> queue = dbClient.ceQueueDao().selectByUuid(dbSession, textQuery);
if (queue.isPresent()) {
return Optional.of(formatter.formatQueue(dbSession, queue.get()));
}
- Optional<CeActivityDto> activity = dbClient.ceActivityDao().selectByUuid(dbSession, textQuery);
+ java.util.Optional<CeActivityDto> activity = dbClient.ceActivityDao().selectByUuid(dbSession, textQuery);
if (activity.isPresent()) {
return Optional.of(formatter.formatActivity(dbSession, activity.get()));
}
*/
package org.sonar.server.ce.ws;
-import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
if (queueDto.isPresent()) {
- Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
+ com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
checkPermission(component);
wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
} else {
CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
- Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
+ com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
checkPermission(component);
Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
maskErrorStacktrace(ceActivityDto, additionalFields);
}
}
- private Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
+ private com.google.common.base.Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
if (projectUuid == null) {
- return Optional.absent();
+ return com.google.common.base.Optional.absent();
}
return dbClient.componentDao().selectByUuid(dbSession, projectUuid);
}
- private void checkPermission(Optional<ComponentDto> component) {
+ private void checkPermission(com.google.common.base.Optional<ComponentDto> component) {
if (component.isPresent()) {
String orgUuid = component.get().getOrganizationUuid();
if (!userSession.hasPermission(OrganizationPermission.ADMINISTER, orgUuid) &&
*/
package org.sonar.ce.queue;
-import com.google.common.base.Optional;
import java.util.List;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;