diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java index 6bf2adfa55..ced2d70fc5 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java @@ -181,7 +181,10 @@ private void initMasterKey() { })); try { - latch.await(1, SECONDS); + boolean completed = latch.await(3, SECONDS); + if (!completed) { + throw new MLException("Fetching master key timed out."); + } } catch (InterruptedException e) { throw new IllegalStateException(e); } diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java index ba3b3a9167..3f1c8c3948 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/encryptor/EncryptorImplTest.java @@ -462,8 +462,8 @@ public void decrypt() { @Test public void encrypt_NullMasterKey_NullMasterKey_MasterKeyNotExistInIndex() { - exceptionRule.expect(ResourceNotFoundException.class); - exceptionRule.expectMessage(MASTER_KEY_NOT_READY_ERROR); + exceptionRule.expect(MLException.class); + exceptionRule.expectMessage("Fetching master key timed out."); doAnswer(invocation -> { ActionListener listener = invocation.getArgument(1); @@ -517,8 +517,8 @@ public void decrypt_NoResponseToInitConfigIndex() { @Test public void decrypt_MLConfigIndexNotFound() { - exceptionRule.expect(ResourceNotFoundException.class); - exceptionRule.expectMessage(MASTER_KEY_NOT_READY_ERROR); + exceptionRule.expect(MLException.class); + exceptionRule.expectMessage("Fetching master key timed out."); Metadata metadata = new Metadata.Builder().indices(ImmutableMap.of()).build(); when(clusterState.metadata()).thenReturn(metadata);