Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: validate special data in opensearch sink #3685

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.opensearch.client.Request;
Expand Down Expand Up @@ -99,6 +100,9 @@
import static org.opensearch.dataprepper.plugins.sink.opensearch.OpenSearchIntegrationHelper.wipeAllTemplates;

public class OpenSearchSinkIT {
private static final int LUCENE_CHAR_LENGTH_LIMIT = 32_766;
private static final String TEST_STRING_WITH_SPECIAL_CHARS = "Hello! Data-Prepper? #Example123";
private static final String TEST_STRING_WITH_NON_LATIN_CHARS = "Привет,Γειά σας,こんにちは,你好";
private static final String PLUGIN_NAME = "opensearch";
private static final String PIPELINE_NAME = "integTestPipeline";
private static final String TEST_CUSTOM_INDEX_POLICY_FILE = "test-custom-index-policy-file.json";
Expand Down Expand Up @@ -969,6 +973,33 @@ public void testEventOutput() throws IOException, InterruptedException {
sink.shutdown();
}

@ParameterizedTest
@MethodSource("getAttributeTestSpecialAndExtremeValues")
public void testEventOutputWithSpecialAndExtremeValues(final Object testValue) throws IOException, InterruptedException {
final String testIndexAlias = "test-alias";
final String testField = "value";
final Map<String, Object> data = new HashMap<>();
data.put(testField, testValue);
final Event testEvent = JacksonEvent.builder()
.withData(data)
.withEventType("event")
.build();

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

final PluginSetting pluginSetting = generatePluginSetting(null, testIndexAlias, null);
final OpenSearchSink sink = createObjectUnderTest(pluginSetting, true);
sink.output(testRecords);

final List<Map<String, Object>> retSources = getSearchResponseDocSources(testIndexAlias);
final Map<String, Object> expectedContent = new HashMap<>();
expectedContent.put(testField, testValue);

assertThat(retSources.size(), equalTo(1));
assertThat(retSources.get(0), equalTo(expectedContent));
sink.shutdown();
}

@ParameterizedTest
@ValueSource(strings = {"info/ids/id", "id"})
public void testOpenSearchDocumentId(final String testDocumentIdField) throws IOException, InterruptedException {
Expand Down Expand Up @@ -1436,4 +1467,25 @@ private void createV1IndexTemplate(final String templateName, final String index
private static boolean isES6() {
return DeclaredOpenSearchVersion.OPENDISTRO_0_10.compareTo(OpenSearchIntegrationHelper.getVersion()) >= 0;
}

private static Stream<Object> getAttributeTestSpecialAndExtremeValues() {
return Stream.of(
null,
Arguments.of(Long.MAX_VALUE),
Arguments.of(Long.MIN_VALUE),
Arguments.of(Integer.MAX_VALUE),
Arguments.of(Integer.MIN_VALUE),
Arguments.of(RandomStringUtils.randomAlphabetic(LUCENE_CHAR_LENGTH_LIMIT)),
Arguments.of(TEST_STRING_WITH_SPECIAL_CHARS),
Arguments.of(TEST_STRING_WITH_NON_LATIN_CHARS),
Arguments.of(Double.MIN_VALUE),
Arguments.of(-Double.MIN_VALUE),
Arguments.of((double) Float.MAX_VALUE),
Arguments.of((double) Float.MIN_VALUE),
Arguments.of((double) -Float.MAX_VALUE),
Arguments.of((double) -Float.MIN_VALUE),
Arguments.of(Boolean.TRUE),
Arguments.of(Boolean.FALSE)
);
}
}
Loading