1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* SonarQube
* Copyright (C) 2009-2025 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.application;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import org.junit.Test;
import org.sonar.application.config.AppSettings;
import org.sonar.application.config.AppSettingsLoader;
import org.sonar.application.config.TestAppSettings;
import org.sonar.process.MessageException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.data.MapEntry.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
import static org.sonar.process.ProcessProperties.Property.PATH_LOGS;
import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
import static org.sonar.process.ProcessProperties.Property.PATH_WEB;
public class AppReloaderImplTest {
private final AppSettingsLoader settingsLoader = mock(AppSettingsLoader.class);
private final FileSystem fs = mock(FileSystem.class);
private final AppState state = mock(AppState.class);
private final AppLogging logging = mock(AppLogging.class);
private final AppReloaderImpl underTest = new AppReloaderImpl(settingsLoader, fs, state, logging);
@Test
public void reload_configuration_then_reset_all() throws IOException {
AppSettings settings = new TestAppSettings(ImmutableMap.of("foo", "bar"));
AppSettings newSettings = new TestAppSettings(ImmutableMap.of("foo", "newBar", "newProp", "newVal"));
when(settingsLoader.load()).thenReturn(newSettings);
underTest.reload(settings);
assertThat(settings.getProps().rawProperties())
.contains(entry("foo", "newBar"))
.contains(entry("newProp", "newVal"));
verify(logging).configure();
verify(state).reset();
verify(fs).reset();
}
@Test
public void throw_ISE_if_cluster_is_enabled() throws IOException {
AppSettings settings = new TestAppSettings(ImmutableMap.of(CLUSTER_ENABLED.getKey(), "true"));
assertThatThrownBy(() -> {
underTest.reload(settings);
verifyNoInteractions(logging);
verifyNoInteractions(state);
verifyNoInteractions(fs);
})
.isInstanceOf(IllegalStateException.class)
.hasMessage("Restart is not possible with cluster mode");
}
@Test
public void throw_MessageException_if_path_properties_are_changed() throws IOException {
verifyFailureIfPropertyValueChanged(PATH_DATA.getKey());
verifyFailureIfPropertyValueChanged(PATH_LOGS.getKey());
verifyFailureIfPropertyValueChanged(PATH_TEMP.getKey());
verifyFailureIfPropertyValueChanged(PATH_WEB.getKey());
}
@Test
public void throw_MessageException_if_cluster_mode_changed() throws IOException {
verifyFailureIfPropertyValueChanged(CLUSTER_ENABLED.getKey());
}
private void verifyFailureIfPropertyValueChanged(String propertyKey) throws IOException {
AppSettings settings = new TestAppSettings(ImmutableMap.of(propertyKey, "val1"));
AppSettings newSettings = new TestAppSettings(ImmutableMap.of(propertyKey, "val2"));
when(settingsLoader.load()).thenReturn(newSettings);
assertThatThrownBy(() -> {
underTest.reload(settings);
verifyNoInteractions(logging);
verifyNoInteractions(state);
verifyNoInteractions(fs);
})
.isInstanceOf(MessageException.class)
.hasMessage("Property [" + propertyKey + "] cannot be changed on restart: [val1] => [val2]");
}
}
|