Skip to content

Commit

Permalink
Add missing alias test
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Dec 21, 2023
1 parent 960e1aa commit 29f2a73
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;

public class RemoteClusterServiceTests extends ESTestCase {

Expand Down Expand Up @@ -1496,7 +1495,7 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionWithCorrectProfi
}
}

public void testUpdateRemoteClusterCredentialsRebuildsConnectionDespiteFailures() throws IOException, InterruptedException {
public void testUpdateRemoteClusterCredentialsRebuildsMultipleConnectionsDespiteFailures() throws IOException, InterruptedException {
final List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
try (
MockTransportService c1 = startTransport(
Expand Down Expand Up @@ -1541,6 +1540,10 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionDespiteFailures(

final String goodCluster = randomAlphaOfLength(10);
final String badCluster = randomValueOtherThan(goodCluster, () -> randomAlphaOfLength(10));
final String missingCluster = randomValueOtherThanMany(
alias -> alias.equals(goodCluster) || alias.equals(badCluster),
() -> randomAlphaOfLength(10)
);
try (RemoteClusterService service = new RemoteClusterService(Settings.EMPTY, transportService)) {
service.initializeRemoteClusters();

Expand All @@ -1552,23 +1555,18 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionDespiteFailures(
final Settings cluster2Settings = buildRemoteClusterSettings(badCluster, c2DiscoNode.getAddress().toString());
final PlainActionFuture<RemoteClusterService.RemoteClusterConnectionStatus> future = new PlainActionFuture<>();
service.updateRemoteCluster(badCluster, cluster2Settings, future);
Exception ex = null;
try {
future.actionGet(10, TimeUnit.SECONDS);
} catch (Exception e) {
// we're expecting a connection failure
ex = e;
}
assertThat(ex, notNullValue());
final var ex = expectThrows(Exception.class, () -> future.actionGet(10, TimeUnit.SECONDS));
assertThat(ex.getMessage(), containsString("bad cluster"));

assertConnectionHasProfile(service.getRemoteClusterConnection(goodCluster), "default");
assertConnectionHasProfile(service.getRemoteClusterConnection(badCluster), "default");
expectThrows(NoSuchRemoteClusterException.class, () -> service.getRemoteClusterConnection(missingCluster));

{
final MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("cluster.remote." + goodCluster + ".credentials", randomAlphaOfLength(10));
secureSettings.setString("cluster.remote." + badCluster + ".credentials", randomAlphaOfLength(10));
secureSettings.setString("cluster.remote." + goodCluster + ".credentials", randomAlphaOfLength(10));
secureSettings.setString("cluster.remote." + missingCluster + ".credentials", randomAlphaOfLength(10));
final PlainActionFuture<Void> listener = new PlainActionFuture<>();
service.updateRemoteClusterCredentials(
Settings.builder().put(cluster1Settings).put(cluster2Settings).setSecureSettings(secureSettings).build(),
Expand All @@ -1585,6 +1583,7 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionDespiteFailures(
service.getRemoteClusterConnection(badCluster),
RemoteClusterPortSettings.REMOTE_CLUSTER_PROFILE
);
expectThrows(NoSuchRemoteClusterException.class, () -> service.getRemoteClusterConnection(missingCluster));

{
final PlainActionFuture<Void> listener = new PlainActionFuture<>();
Expand All @@ -1598,6 +1597,7 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionDespiteFailures(

assertConnectionHasProfile(service.getRemoteClusterConnection(goodCluster), "default");
assertConnectionHasProfile(service.getRemoteClusterConnection(badCluster), "default");
expectThrows(NoSuchRemoteClusterException.class, () -> service.getRemoteClusterConnection(missingCluster));
}
}
}
Expand Down

0 comments on commit 29f2a73

Please sign in to comment.