|
29 | 29 | import java.io.IOException; |
30 | 30 |
|
31 | 31 | import com.google.common.collect.Lists; |
32 | | -import org.apache.http.HttpStatus; |
| 32 | +import org.awaitility.Awaitility; |
33 | 33 | import org.junit.Assert; |
34 | 34 | import org.junit.Test; |
35 | 35 |
|
36 | 36 | import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; |
37 | 37 | import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; |
38 | 38 | import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; |
| 39 | +import org.opensearch.action.admin.indices.create.CreateIndexRequest; |
39 | 40 | import org.opensearch.cluster.health.ClusterHealthStatus; |
40 | 41 | import org.opensearch.common.settings.Settings; |
41 | 42 | import org.opensearch.common.unit.TimeValue; |
|
50 | 51 | import org.opensearch.security.test.helper.rest.RestHelper; |
51 | 52 | import org.opensearch.transport.Netty4Plugin; |
52 | 53 |
|
| 54 | +import static org.hamcrest.Matchers.equalTo; |
| 55 | +import static org.junit.Assert.assertThrows; |
| 56 | + |
53 | 57 | public class SlowIntegrationTests extends SingleClusterTest { |
54 | 58 |
|
55 | 59 | @Test |
@@ -223,27 +227,34 @@ public void testDelayInSecurityIndexInitialization() throws Exception { |
223 | 227 | .put(ConfigConstants.SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX, true) |
224 | 228 | .put("cluster.routing.allocation.exclude._ip", "127.0.0.1") |
225 | 229 | .build(); |
226 | | - try { |
| 230 | + assertThrows(IOException.class, () -> { |
227 | 231 | setup(Settings.EMPTY, null, settings, false); |
228 | | - Assert.fail("Expected IOException here due to red cluster state"); |
229 | | - } catch (IOException e) { |
230 | | - // Index request has a default timeout of 1 minute, adding buffer between nodes initialization and cluster health check |
231 | | - Thread.sleep(1000 * 80); |
232 | | - // Ideally, we would want to remove this cluster setting, but default settings cannot be removed. So overriding with a reserved |
233 | | - // IP address |
234 | 232 | clusterHelper.nodeClient() |
235 | 233 | .admin() |
236 | | - .cluster() |
237 | | - .updateSettings( |
238 | | - new ClusterUpdateSettingsRequest().transientSettings( |
239 | | - Settings.builder().put("cluster.routing.allocation.exclude._ip", "192.0.2.0").build() |
240 | | - ) |
241 | | - ); |
242 | | - this.clusterInfo = clusterHelper.waitForCluster(ClusterHealthStatus.GREEN, TimeValue.timeValueSeconds(10), 3); |
243 | | - } |
| 234 | + .indices() |
| 235 | + .create(new CreateIndexRequest("test-index").timeout(TimeValue.timeValueSeconds(10))) |
| 236 | + .actionGet(); |
| 237 | + clusterHelper.waitForCluster(ClusterHealthStatus.GREEN, TimeValue.timeValueSeconds(5), ClusterConfiguration.DEFAULT.getNodes()); |
| 238 | + }); |
| 239 | + // Ideally, we would want to remove this cluster setting, but default settings cannot be removed. So overriding with a reserved |
| 240 | + // IP address |
| 241 | + clusterHelper.nodeClient() |
| 242 | + .admin() |
| 243 | + .cluster() |
| 244 | + .updateSettings( |
| 245 | + new ClusterUpdateSettingsRequest().transientSettings( |
| 246 | + Settings.builder().put("cluster.routing.allocation.exclude._ip", "192.0.2.0").build() |
| 247 | + ) |
| 248 | + ); |
| 249 | + this.clusterInfo = clusterHelper.waitForCluster(ClusterHealthStatus.GREEN, TimeValue.timeValueSeconds(10), 3); |
244 | 250 | RestHelper rh = nonSslRestHelper(); |
245 | | - Thread.sleep(10000); |
246 | | - Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("", encodeBasicHeader("admin", "admin")).getStatusCode()); |
| 251 | + Awaitility.await() |
| 252 | + .alias("Wait until Security is initialized") |
| 253 | + .until( |
| 254 | + () -> rh.executeGetRequest("/_plugins/_security/health", encodeBasicHeader("admin", "admin")) |
| 255 | + .getTextFromJsonBody("/status"), |
| 256 | + equalTo("UP") |
| 257 | + ); |
247 | 258 | } |
248 | 259 |
|
249 | 260 | } |
0 commit comments