Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
Krishna Kondaka committed Jan 5, 2024
1 parent 25956ce commit c13ebcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -1120,26 +1121,34 @@ public void testOpenSearchRoutingField(final String testRoutingField) throws IOE
}

@ParameterizedTest
@ValueSource(strings = {"info/ids/rid", "rid"})
@ValueSource(strings = {"", "info/ids/rid", "rid"})
public void testOpenSearchRouting(final String testRouting) throws IOException, InterruptedException {
final String expectedRouting = UUID.randomUUID().toString();
final String testIndexAlias = "test_index";
final Event testEvent = JacksonEvent.builder()
.withData(Map.of("arbitrary_data", UUID.randomUUID().toString()))
.withEventType("event")
.build();
testEvent.put(testRouting, expectedRouting);
if (!testRouting.isEmpty()) {
testEvent.put(testRouting, expectedRouting);
}

final List<Record<Event>> testRecords = Collections.singletonList(new Record<>(testEvent));

final PluginSetting pluginSetting = generatePluginSetting(null, testIndexAlias, null);
pluginSetting.getSettings().put(IndexConfiguration.ROUTING_FIELD, testRouting);
if (!testRouting.isEmpty()) {
pluginSetting.getSettings().put(IndexConfiguration.ROUTING, "${"+testRouting+"}");
}
final OpenSearchSink sink = createObjectUnderTest(pluginSetting, true);
sink.output(testRecords);

final List<String> routingFields = getSearchResponseRoutingFields(testIndexAlias);
for (String routingField : routingFields) {
assertThat(routingField, equalTo(expectedRouting));
if (!testRouting.isEmpty()) {
assertThat(routingField, equalTo(expectedRouting));
} else {
assertTrue(Objects.isNull(routingField));
}
}
sink.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private SerializedJson getDocument(final Event event) {
try {
routingValue = event.formatString(routing, expressionEvaluator);
} catch (final ExpressionEvaluationException | EventKeyNotFoundException e) {
LOG.error("Unable to construct routing with format {}, the document_id will be generated by OpenSearch", routing, e);
LOG.error("Unable to construct routing with format {}, the routing will be generated by OpenSearch", routing, e);
}
}

Expand Down

0 comments on commit c13ebcf

Please sign in to comment.