|
22 | 22 |
|
23 | 23 | import static org.elasticsearch.test.NodeRoles.nonRemoteClusterClientNode;
|
24 | 24 | import static org.elasticsearch.test.NodeRoles.remoteClusterClientNode;
|
| 25 | +import static org.elasticsearch.transport.RemoteClusterSettings.ProxyConnectionStrategySettings.PROXY_ADDRESS; |
25 | 26 | import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_CLUSTER_CREDENTIALS;
|
26 | 27 | import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE;
|
| 28 | +import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_CONNECTION_MODE; |
27 | 29 | import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING;
|
28 | 30 | import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_NODE_ATTRIBUTE;
|
29 | 31 | import static org.elasticsearch.transport.RemoteClusterSettings.SniffConnectionStrategySettings.REMOTE_CLUSTERS_PROXY;
|
@@ -95,4 +97,51 @@ public void testProxyDefault() {
|
95 | 97 | final String alias = randomAlphaOfLength(8);
|
96 | 98 | assertThat(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace(alias).get(Settings.EMPTY), equalTo(""));
|
97 | 99 | }
|
| 100 | + |
| 101 | + public void testSkipUnavailableAlwaysTrueIfCPSEnabled() { |
| 102 | + final var alias = randomAlphaOfLength(8); |
| 103 | + final var skipUnavailableSetting = REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace(alias); |
| 104 | + final var modeSetting = REMOTE_CONNECTION_MODE.getConcreteSettingForNamespace(alias); |
| 105 | + final var proxyAddressSetting = PROXY_ADDRESS.getConcreteSettingForNamespace(alias); |
| 106 | + final var cpsEnabledSettings = Settings.builder().put("serverless.cross_project.enabled", true).build(); |
| 107 | + final var proxyEnabledSettings = Settings.builder() |
| 108 | + .put(modeSetting.getKey(), RemoteConnectionStrategy.ConnectionStrategy.PROXY.toString()) |
| 109 | + .put(proxyAddressSetting.getKey(), "localhost:9400") |
| 110 | + .build(); |
| 111 | + |
| 112 | + // Ensure the validator still throws in non-CPS environment if a connection mode is not set. |
| 113 | + var exception = expectThrows( |
| 114 | + IllegalArgumentException.class, |
| 115 | + () -> skipUnavailableSetting.get(Settings.builder().put(skipUnavailableSetting.getKey(), true).build()) |
| 116 | + ); |
| 117 | + assertThat( |
| 118 | + exception.getMessage(), |
| 119 | + equalTo("Cannot configure setting [" + skipUnavailableSetting.getKey() + "] if remote cluster is not enabled.") |
| 120 | + ); |
| 121 | + |
| 122 | + // Ensure we can still get the set value in non-CPS environment. |
| 123 | + final var randomSkipUnavailableSettingValue = randomBoolean(); |
| 124 | + assertThat( |
| 125 | + skipUnavailableSetting.get( |
| 126 | + Settings.builder().put(proxyEnabledSettings).put(skipUnavailableSetting.getKey(), randomSkipUnavailableSettingValue).build() |
| 127 | + ), |
| 128 | + equalTo(randomSkipUnavailableSettingValue) |
| 129 | + ); |
| 130 | + |
| 131 | + // Check the validator rejects the skip_unavailable setting if present when CPS is enabled. |
| 132 | + exception = expectThrows( |
| 133 | + IllegalArgumentException.class, |
| 134 | + () -> skipUnavailableSetting.get( |
| 135 | + Settings.builder() |
| 136 | + .put(cpsEnabledSettings) |
| 137 | + .put(proxyEnabledSettings) |
| 138 | + .put(skipUnavailableSetting.getKey(), randomBoolean()) |
| 139 | + .build() |
| 140 | + ) |
| 141 | + ); |
| 142 | + assertThat(exception.getMessage(), equalTo("setting [" + skipUnavailableSetting.getKey() + "] is unavailable when CPS is enabled")); |
| 143 | + |
| 144 | + // Should not throw if the setting is not present, returning the expected default value of true. |
| 145 | + assertTrue(skipUnavailableSetting.get(Settings.builder().put(cpsEnabledSettings).put(proxyEnabledSettings).build())); |
| 146 | + } |
98 | 147 | }
|
0 commit comments