|
7 | 7 | package org.elasticsearch.license;
|
8 | 8 |
|
9 | 9 | import org.elasticsearch.ElasticsearchException;
|
| 10 | +import org.elasticsearch.ResourceNotFoundException; |
10 | 11 | import org.elasticsearch.action.ActionListener;
|
11 | 12 | import org.elasticsearch.client.Client;
|
12 | 13 | import org.elasticsearch.common.settings.Settings;
|
@@ -349,6 +350,41 @@ public void testBuildErrorMessageForInactiveLicense() {
|
349 | 350 | equalTo("the license on cluster [expired-cluster] is not active"));
|
350 | 351 | }
|
351 | 352 |
|
| 353 | + public void testCheckRemoteClusterLicencesNoLicenseMetadata() { |
| 354 | + final ThreadPool threadPool = createMockThreadPool(); |
| 355 | + final Client client = createMockClient(threadPool); |
| 356 | + doAnswer(invocationMock -> { |
| 357 | + @SuppressWarnings("unchecked") ActionListener<XPackInfoResponse> listener = |
| 358 | + (ActionListener<XPackInfoResponse>) invocationMock.getArguments()[2]; |
| 359 | + listener.onResponse(new XPackInfoResponse(null, null, null)); |
| 360 | + return null; |
| 361 | + }).when(client).execute(same(XPackInfoAction.INSTANCE), any(), any()); |
| 362 | + |
| 363 | + final RemoteClusterLicenseChecker licenseChecker = |
| 364 | + new RemoteClusterLicenseChecker(client, XPackLicenseState::isPlatinumOrTrialOperationMode); |
| 365 | + final AtomicReference<Exception> exception = new AtomicReference<>(); |
| 366 | + |
| 367 | + licenseChecker.checkRemoteClusterLicenses( |
| 368 | + Collections.singletonList("remote"), |
| 369 | + doubleInvocationProtectingListener(new ActionListener<RemoteClusterLicenseChecker.LicenseCheck>() { |
| 370 | + |
| 371 | + @Override |
| 372 | + public void onResponse(final RemoteClusterLicenseChecker.LicenseCheck response) { |
| 373 | + fail(); |
| 374 | + } |
| 375 | + |
| 376 | + @Override |
| 377 | + public void onFailure(final Exception e) { |
| 378 | + exception.set(e); |
| 379 | + } |
| 380 | + |
| 381 | + })); |
| 382 | + |
| 383 | + assertNotNull(exception.get()); |
| 384 | + assertThat(exception.get(), instanceOf(ResourceNotFoundException.class)); |
| 385 | + assertThat(exception.get().getMessage(), equalTo("license info is missing for cluster [remote]")); |
| 386 | + } |
| 387 | + |
352 | 388 | private ActionListener<RemoteClusterLicenseChecker.LicenseCheck> doubleInvocationProtectingListener(
|
353 | 389 | final ActionListener<RemoteClusterLicenseChecker.LicenseCheck> listener) {
|
354 | 390 | final AtomicBoolean listenerInvoked = new AtomicBoolean();
|
|
0 commit comments