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.queue.CeQueueImpl;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.entry;
27 import static org.mockito.Mockito.mock;
29 public class ComputeEngineQueueMonitorTest {
30 private static final long RECEIVED_COUNT = 30;
31 private static final long PENDING_COUNT = 2;
32 private static final long IN_PROGRESS_COUNT = 5;
33 private static final long ERROR_COUNT = 10;
34 private static final long SUCCESS_COUNT = 13;
35 private static final long PROCESSING_TIME = 987;
37 private ComputeEngineQueueMonitor underTest = new ComputeEngineQueueMonitor(new DumbCEQueueStatus(), mock(CeQueueImpl.class));
40 public void name_is_ComputeEngine() {
41 assertThat(underTest.name()).isEqualTo("ComputeEngine");
45 public void attributes_has_entry_for_each_get_method() {
46 assertThat(underTest.attributes()).containsOnly(
47 entry("Received", RECEIVED_COUNT),
48 entry("Pending", PENDING_COUNT),
49 entry("In progress", IN_PROGRESS_COUNT),
50 entry("Successfully processed", SUCCESS_COUNT),
51 entry("Processed with error", ERROR_COUNT),
52 entry("Processing time", PROCESSING_TIME));
56 public void get_methods_delegate_to_the_CEQueueStatus_instance() {
57 assertThat(underTest.getReceivedCount()).isEqualTo(RECEIVED_COUNT);
58 assertThat(underTest.getPendingCount()).isEqualTo(PENDING_COUNT);
59 assertThat(underTest.getInProgressCount()).isEqualTo(IN_PROGRESS_COUNT);
60 assertThat(underTest.getErrorCount()).isEqualTo(ERROR_COUNT);
61 assertThat(underTest.getSuccessCount()).isEqualTo(SUCCESS_COUNT);
62 assertThat(underTest.getProcessingTime()).isEqualTo(PROCESSING_TIME);
66 * Dumb implementation of CEQueueStatus which returns constant values for get methods and throws UnsupportedOperationException
69 private static class DumbCEQueueStatus implements CEQueueStatus {
72 public long addReceived() {
73 return methodNotImplemented();
76 private long methodNotImplemented() {
77 throw new UnsupportedOperationException("Not Implemented");
81 public long getReceivedCount() {
82 return RECEIVED_COUNT;
86 public long initPendingCount(long initialPendingCount) {
87 return methodNotImplemented();
91 public long getPendingCount() {
96 public long addInProgress() {
97 return methodNotImplemented();
101 public long getInProgressCount() {
102 return IN_PROGRESS_COUNT;
106 public long addError(long processingTime) {
107 return methodNotImplemented();
111 public long getErrorCount() {
116 public long addSuccess(long processingTime) {
117 return methodNotImplemented();
121 public long getSuccessCount() {
122 return SUCCESS_COUNT;
126 public long getProcessingTime() {
127 return PROCESSING_TIME;