]> source.dussan.org Git - sonarqube.git/blob
1587ab5f044ab0b7acf19b3d2feb622537e27be2
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2016 SonarSource SA
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.computation.monitoring;
21
22 import org.junit.Test;
23 import org.sonar.server.computation.queue.CeQueueImpl;
24
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;
28
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;
36
37   private ComputeEngineQueueMonitor underTest = new ComputeEngineQueueMonitor(new DumbCEQueueStatus(), mock(CeQueueImpl.class));
38
39   @Test
40   public void name_is_ComputeEngine() {
41     assertThat(underTest.name()).isEqualTo("ComputeEngine");
42   }
43
44   @Test
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));
53   }
54
55   @Test
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);
63   }
64
65   /**
66    * Dumb implementation of CEQueueStatus which returns constant values for get methods and throws UnsupportedOperationException
67    * for other methods.
68    */
69   private static class DumbCEQueueStatus implements CEQueueStatus {
70
71     @Override
72     public long addReceived() {
73       return methodNotImplemented();
74     }
75
76     private long methodNotImplemented() {
77       throw new UnsupportedOperationException("Not Implemented");
78     }
79
80     @Override
81     public long getReceivedCount() {
82       return RECEIVED_COUNT;
83     }
84
85     @Override
86     public long initPendingCount(long initialPendingCount) {
87       return methodNotImplemented();
88     }
89
90     @Override
91     public long getPendingCount() {
92       return PENDING_COUNT;
93     }
94
95     @Override
96     public long addInProgress() {
97       return methodNotImplemented();
98     }
99
100     @Override
101     public long getInProgressCount() {
102       return IN_PROGRESS_COUNT;
103     }
104
105     @Override
106     public long addError(long processingTime) {
107       return methodNotImplemented();
108     }
109
110     @Override
111     public long getErrorCount() {
112       return ERROR_COUNT;
113     }
114
115     @Override
116     public long addSuccess(long processingTime) {
117       return methodNotImplemented();
118     }
119
120     @Override
121     public long getSuccessCount() {
122       return SUCCESS_COUNT;
123     }
124
125     @Override
126     public long getProcessingTime() {
127       return PROCESSING_TIME;
128     }
129   }
130 }