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 617c6871e5..58081a05af 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 @@ -125,7 +125,10 @@ private void initMasterKey() { } try { - latch.await(5, 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 211ea017c3..92a186c1dc 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 @@ -131,8 +131,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); @@ -165,8 +165,8 @@ public void decrypt_NullMasterKey_GetMasterKey_Exception() { @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);