Skip to content

Commit

Permalink
Fix double trailing slash in getClusterVersion
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Sep 24, 2024
1 parent 6c32e29 commit 494958c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected OpenSearchClient(RestClient client, FailedRequestsLogger failedRequest
}

public Version getClusterVersion() {
return client.getAsync("/", null)
return client.getAsync("", null)
.flatMap(resp -> {
try {
return Mono.just(versionFromResponse(resp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;

import org.opensearch.migrations.Version;
import org.opensearch.migrations.bulkload.common.DocumentReindexer.BulkDocSection;
import org.opensearch.migrations.bulkload.common.http.HttpResponse;
import org.opensearch.migrations.bulkload.http.BulkRequestGenerator;
Expand All @@ -33,6 +34,7 @@
import static org.opensearch.migrations.bulkload.http.BulkRequestGenerator.itemEntryFailure;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -124,6 +126,30 @@ void testCreateIndex_errorOnCreation_notRetriedOnBadRequest() {
assertThat(exception.getMessage(), containsString("illegal_argument_exception"));
}

@Test
void testGetClusterVersion() {
var restClient = mock(RestClient.class);
var failedRequestLogger = mock(FailedRequestsLogger.class);
var openSearchClient = new OpenSearchClient(restClient, failedRequestLogger);

var versionJson = "{\"version\": {\"number\": \"7.10.2\"}}";
var successResponse = new HttpResponse(200, "OK", Map.of(), versionJson);

ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);

when(restClient.getAsync(pathCaptor.capture(), any()))
.thenReturn(Mono.just(successResponse));

Version version = openSearchClient.getClusterVersion();

assertThat(version, equalTo(Version.fromString("ES 7.10.2")));

String capturedPath = pathCaptor.getValue();
assertThat(capturedPath, equalTo(""));

verify(restClient, times(1)).getAsync(anyString(), any());
}

@Test
void testBulkRequest_succeedAfterRetries() {
var docId1 = "tt1979320";
Expand Down

0 comments on commit 494958c

Please sign in to comment.