This repository was archived by the owner on Jul 20, 2024. It is now read-only.
forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsTest.java
More file actions
181 lines (151 loc) · 6.29 KB
/
SettingsTest.java
File metadata and controls
181 lines (151 loc) · 6.29 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Copyright 2011 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.splunk;
import org.junit.Assert;
import org.junit.Test;
public class SettingsTest extends SDKTestCase {
@Test
public void testGettersThrowNoExceptions() {
Settings settings = service.getSettings();
settings.getSplunkDB();
settings.getSplunkHome();
settings.getEnableSplunkWebSSL();
settings.getHost();
settings.getHttpPort();
settings.getMgmtPort();
settings.getMinFreeSpace();
settings.getPass4SymmKey();
settings.getServerName();
settings.getSessionTimeout();
settings.getStartWebServer();
settings.getTrustedIP();
}
@Test
public void testHttpPortSetter() throws Exception {
Settings settings = service.getSettings();
int originalHttpPort = settings.getHttpPort();
if (!isPortInUse(originalHttpPort)) {
// Try to clean up from weird state where splunkweb isn't running
System.out.println(
"WARNING: splunkweb seems to be down. " +
"Trying to recover...");
uncheckedSplunkRestart();
waitForSplunkwebUp(originalHttpPort);
}
Assert.assertTrue(isPortInUse(originalHttpPort));
int newPort = originalHttpPort + 1;
while (isPortInUse(newPort)) {
newPort++;
}
changeHttpPort(newPort);
Assert.assertTrue(isPortInUse(newPort));
Assert.assertFalse(isPortInUse(originalHttpPort));
changeHttpPort(originalHttpPort);
Assert.assertTrue(isPortInUse(originalHttpPort));
Assert.assertFalse(isPortInUse(newPort));
}
private void changeHttpPort(int newHttpPort) {
Settings settings = service.getSettings();
settings.setHttpPort(newHttpPort);
settings.update();
// If you change the splunkweb port, a new splunkweb instance
// will be created on the new port. However the old splunkweb instance
// will remain until you do a full restart.
splunkRestart();
waitForSplunkwebUp(newHttpPort);
settings = service.getSettings();
Assert.assertEquals(newHttpPort, settings.getHttpPort());
}
private void waitForSplunkwebUp(final int httpPort) {
// Wait for splunkweb to come back up
assertEventuallyTrue(new EventuallyTrueBehavior() {
{
tries = 20;
pauseTime = 1000;
}
public boolean predicate() {
return isPortInUse(httpPort);
}
});
}
@Test
public void testMangementPort() throws Exception {
Settings settings = service.getSettings();
int managementPort = settings.getMgmtPort();
settings.setMgmtPort(29111);
settings.update();
settings.refresh();
Assert.assertEquals(29111, settings.getMgmtPort());
settings.setMgmtPort(managementPort);
settings.update();
splunkRestart();
}
@Test
public void testSymmKey() throws Exception {
Settings settings = service.getSettings();
String key = settings.getPass4SymmKey();
settings.setPasswordSymmKey(key + "_foo");
settings.update();
settings.refresh();
Assert.assertEquals(key + "_foo", settings.getPass4SymmKey());
settings.setPasswordSymmKey(key);
settings.update();
splunkRestart();
}
@Test
public void testOtherSetters() throws Exception {
Settings settings = service.getSettings();
// Save original settings
String originalTimeout = settings.getSessionTimeout();
boolean originalSSL = settings.getEnableSplunkWebSSL();
String originalHost = settings.getHost();
int originalMinSpace = settings.getMinFreeSpace();
//int originalMgmtPort = settings.getMgmtPort();
String originalServerName = settings.getServerName();
boolean originalStartWeb = settings.getStartWebServer();
// Update
settings.setEnableSplunkWebSSL(!originalSSL);
settings.setHost("sdk-host");
settings.setMinimumFreeSpace(originalMinSpace-100);
//settings.setMgmtHostPort(originalMgmtPort+1);
settings.setServerName("sdk-test-name");
settings.setSessionTimeout("2h");
//settings.setStartWebServer(!originalStartWeb);
settings.update();
clearRestartMessage();
Assert.assertEquals(!originalSSL, settings.getEnableSplunkWebSSL());
Assert.assertEquals("sdk-host", settings.getHost());
Assert.assertEquals(originalMinSpace - 100, settings.getMinFreeSpace());
Assert.assertEquals("sdk-test-name", settings.getServerName());
Assert.assertEquals("2h", settings.getSessionTimeout());
//Assert.assertEquals(settings.getStartWebServer(), !originalStartWeb);
// Restore
settings.setEnableSplunkWebSSL(originalSSL);
settings.setHost(originalHost);
settings.setMinimumFreeSpace(originalMinSpace);
settings.setServerName(originalServerName);
settings.setSessionTimeout(originalTimeout);
settings.setStartWebServer(originalStartWeb);
settings.update();
clearRestartMessage();
Assert.assertEquals(originalSSL, settings.getEnableSplunkWebSSL());
Assert.assertEquals(originalHost, settings.getHost());
Assert.assertEquals(originalMinSpace, settings.getMinFreeSpace());
Assert.assertEquals(originalServerName, settings.getServerName());
Assert.assertEquals(originalTimeout, settings.getSessionTimeout());
Assert.assertEquals(originalStartWeb, settings.getStartWebServer());
}
}