3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.monitoring;
22 import org.junit.Test;
23 import org.sonar.server.computation.configuration.CeConfiguration;
24 import org.sonar.server.computation.queue.CeQueueImpl;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.assertj.core.api.Assertions.entry;
28 import static org.mockito.Mockito.mock;
30 public class ComputeEngineQueueMonitorTest {
31 private static final long RECEIVED_COUNT = 30;
32 private static final long PENDING_COUNT = 2;
33 private static final long IN_PROGRESS_COUNT = 5;
34 private static final long ERROR_COUNT = 10;
35 private static final long SUCCESS_COUNT = 13;
36 private static final long PROCESSING_TIME = 987;
37 private static final int WORKER_COUNT = 56;
39 private ComputeEngineQueueMonitor underTest = new ComputeEngineQueueMonitor(new DumbCEQueueStatus(), mock(CeQueueImpl.class), new DumbCeConfiguration());
42 public void name_is_ComputeEngine() {
43 assertThat(underTest.name()).isEqualTo("ComputeEngine");
47 public void attributes_has_entry_for_each_get_method() {
48 assertThat(underTest.attributes()).containsOnly(
49 entry("Received", RECEIVED_COUNT),
50 entry("Pending", PENDING_COUNT),
51 entry("In progress", IN_PROGRESS_COUNT),
52 entry("Successfully processed", SUCCESS_COUNT),
53 entry("Processed with error", ERROR_COUNT),
54 entry("Processing time", PROCESSING_TIME),
55 entry("Worker count", WORKER_COUNT));
59 public void get_methods_delegate_to_the_CEQueueStatus_instance() {
60 assertThat(underTest.getReceivedCount()).isEqualTo(RECEIVED_COUNT);
61 assertThat(underTest.getPendingCount()).isEqualTo(PENDING_COUNT);
62 assertThat(underTest.getInProgressCount()).isEqualTo(IN_PROGRESS_COUNT);
63 assertThat(underTest.getErrorCount()).isEqualTo(ERROR_COUNT);
64 assertThat(underTest.getSuccessCount()).isEqualTo(SUCCESS_COUNT);
65 assertThat(underTest.getProcessingTime()).isEqualTo(PROCESSING_TIME);
69 public void getWorkerCount_delegates_to_the_CEConfiguration_instance() {
70 assertThat(underTest.getWorkerCount()).isEqualTo(WORKER_COUNT);
74 * Dumb implementation of CEQueueStatus which returns constant values for get methods and throws UnsupportedOperationException
77 private static class DumbCEQueueStatus implements CEQueueStatus {
80 public long addReceived() {
81 return methodNotImplemented();
85 public long addReceived(long numberOfReceived) {
86 return methodNotImplemented();
90 public long getReceivedCount() {
91 return RECEIVED_COUNT;
95 public long initPendingCount(long initialPendingCount) {
96 return methodNotImplemented();
100 public long getPendingCount() {
101 return PENDING_COUNT;
105 public long addInProgress() {
106 return methodNotImplemented();
110 public long getInProgressCount() {
111 return IN_PROGRESS_COUNT;
115 public long addError(long processingTime) {
116 return methodNotImplemented();
120 public long getErrorCount() {
125 public long addSuccess(long processingTime) {
126 return methodNotImplemented();
130 public long getSuccessCount() {
131 return SUCCESS_COUNT;
135 public long getProcessingTime() {
136 return PROCESSING_TIME;
139 private long methodNotImplemented() {
140 throw new UnsupportedOperationException("Not Implemented");
144 private static class DumbCeConfiguration implements CeConfiguration {
146 public int getWorkerCount() {
151 public long getQueuePollingDelay() {
152 throw new UnsupportedOperationException("getQueuePollingDelay is not implemented");