]> source.dussan.org Git - sonarqube.git/blob
8ba7e634d3eb250388a81589d0fedcec8a210c1b
[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.configuration.CeConfiguration;
24 import org.sonar.server.computation.queue.CeQueueImpl;
25
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;
29
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;
38
39   private ComputeEngineQueueMonitor underTest = new ComputeEngineQueueMonitor(new DumbCEQueueStatus(), mock(CeQueueImpl.class), new DumbCeConfiguration());
40
41   @Test
42   public void name_is_ComputeEngine() {
43     assertThat(underTest.name()).isEqualTo("ComputeEngine");
44   }
45
46   @Test
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));
56   }
57
58   @Test
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);
66   }
67
68   @Test
69   public void getWorkerCount_delegates_to_the_CEConfiguration_instance() {
70     assertThat(underTest.getWorkerCount()).isEqualTo(WORKER_COUNT);
71   }
72
73   /**
74    * Dumb implementation of CEQueueStatus which returns constant values for get methods and throws UnsupportedOperationException
75    * for other methods.
76    */
77   private static class DumbCEQueueStatus implements CEQueueStatus {
78
79     @Override
80     public long addReceived() {
81       return methodNotImplemented();
82     }
83
84     @Override
85     public long addReceived(long numberOfReceived) {
86       return methodNotImplemented();
87     }
88
89     @Override
90     public long getReceivedCount() {
91       return RECEIVED_COUNT;
92     }
93
94     @Override
95     public long initPendingCount(long initialPendingCount) {
96       return methodNotImplemented();
97     }
98
99     @Override
100     public long getPendingCount() {
101       return PENDING_COUNT;
102     }
103
104     @Override
105     public long addInProgress() {
106       return methodNotImplemented();
107     }
108
109     @Override
110     public long getInProgressCount() {
111       return IN_PROGRESS_COUNT;
112     }
113
114     @Override
115     public long addError(long processingTime) {
116       return methodNotImplemented();
117     }
118
119     @Override
120     public long getErrorCount() {
121       return ERROR_COUNT;
122     }
123
124     @Override
125     public long addSuccess(long processingTime) {
126       return methodNotImplemented();
127     }
128
129     @Override
130     public long getSuccessCount() {
131       return SUCCESS_COUNT;
132     }
133
134     @Override
135     public long getProcessingTime() {
136       return PROCESSING_TIME;
137     }
138
139     private long methodNotImplemented() {
140       throw new UnsupportedOperationException("Not Implemented");
141     }
142   }
143
144   private static class DumbCeConfiguration implements CeConfiguration {
145     @Override
146     public int getWorkerCount() {
147       return WORKER_COUNT;
148     }
149
150     @Override
151     public long getQueuePollingDelay() {
152       throw new UnsupportedOperationException("getQueuePollingDelay is not implemented");
153     }
154   }
155 }