Skip to content

Commit

Permalink
Fixed exception when datasource is updated with existing configuration (
Browse files Browse the repository at this point in the history
#2006)

Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
  • Loading branch information
vamsi-amazon authored Aug 22, 2023
1 parent 8f650e8 commit b3fd4c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public void updateDataSourceMetadata(DataSourceMetadata dataSourceMetadata) {
throw new RuntimeException(e);
}

if (updateResponse.getResult().equals(DocWriteResponse.Result.UPDATED)) {
if (updateResponse.getResult().equals(DocWriteResponse.Result.UPDATED)
|| updateResponse.getResult().equals(DocWriteResponse.Result.NOOP)) {
LOG.debug("DatasourceMetadata : {} successfully updated", dataSourceMetadata.getName());
} else {
throw new RuntimeException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,24 @@ public void testUpdateDataSourceMetadata() {
Mockito.verify(client.threadPool().getThreadContext(), Mockito.times(1)).stashContext();
}

@Test
public void testUpdateDataSourceMetadataWithNOOP() {
Mockito.when(encryptor.encrypt("secret_key")).thenReturn("secret_key");
Mockito.when(encryptor.encrypt("access_key")).thenReturn("access_key");
Mockito.when(client.update(ArgumentMatchers.any())).thenReturn(updateResponseActionFuture);
Mockito.when(updateResponseActionFuture.actionGet()).thenReturn(updateResponse);
Mockito.when(updateResponse.getResult()).thenReturn(DocWriteResponse.Result.NOOP);
DataSourceMetadata dataSourceMetadata = getDataSourceMetadata();

this.openSearchDataSourceMetadataStorage.updateDataSourceMetadata(dataSourceMetadata);

Mockito.verify(encryptor, Mockito.times(1)).encrypt("secret_key");
Mockito.verify(encryptor, Mockito.times(1)).encrypt("access_key");
Mockito.verify(client.admin().indices(), Mockito.times(0)).create(ArgumentMatchers.any());
Mockito.verify(client, Mockito.times(1)).update(ArgumentMatchers.any());
Mockito.verify(client.threadPool().getThreadContext(), Mockito.times(1)).stashContext();
}

@Test
public void testUpdateDataSourceMetadataWithNotFoundResult() {
Mockito.when(encryptor.encrypt("secret_key")).thenReturn("secret_key");
Expand Down

0 comments on commit b3fd4c4

Please sign in to comment.