-
Notifications
You must be signed in to change notification settings - Fork 325
Support isolation.level config for Kafka consumer #5894
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
Merged
dlvenable
merged 1 commit into
opensearch-project:main
from
lhooss:feat/support-isolation-level
Aug 1, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/opensearch/dataprepper/plugins/kafka/configuration/IsolationLevel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.opensearch.dataprepper.plugins.kafka.configuration; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public enum IsolationLevel { | ||
| READ_UNCOMMITTED("read_uncommitted"), | ||
| READ_COMMITTED("read_committed"); | ||
|
|
||
| private static final Map<String, IsolationLevel> OPTIONS_MAP = Arrays.stream(IsolationLevel.values()) | ||
| .collect(Collectors.toMap( | ||
| value -> value.type, | ||
| value -> value | ||
| )); | ||
|
|
||
| private final String type; | ||
|
|
||
| IsolationLevel(final String type) { | ||
| this.type = type; | ||
| } | ||
|
|
||
| @JsonCreator | ||
| public static IsolationLevel fromTypeValue(final String type) { | ||
| return OPTIONS_MAP.get(type.toLowerCase()); | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
...ava/org/opensearch/dataprepper/plugins/kafka/configuration/KafkaIsolationLevelConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.opensearch.dataprepper.plugins.kafka.configuration; | ||
|
|
||
| public interface KafkaIsolationLevelConfig { | ||
| IsolationLevel getIsolationLevel(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../test/java/org/opensearch/dataprepper/plugins/kafka/configuration/IsolationLevelTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.opensearch.dataprepper.plugins.kafka.configuration; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
| import org.junit.jupiter.params.provider.ArgumentsSource; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
|
|
||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.hamcrest.CoreMatchers.equalTo; | ||
| import static org.hamcrest.CoreMatchers.instanceOf; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.not; | ||
| import static org.hamcrest.CoreMatchers.notNullValue; | ||
| import static org.hamcrest.Matchers.emptyString; | ||
| import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
|
|
||
| public class IsolationLevelTest { | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(IsolationLevel.class) | ||
| void fromTypeValue_should_return_expected_enum(final IsolationLevel value) { | ||
| assertThat(IsolationLevel.fromTypeValue(value.getType()), is(value)); | ||
| assertThat(value, instanceOf(IsolationLevel.class)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ArgumentsSource(IsolationLevelToKnownName.class) | ||
| void fromTypeValue_returns_expected_value(final IsolationLevel isolationLevel, final String knownString) { | ||
| assertThat(IsolationLevel.fromTypeValue(knownString), equalTo(isolationLevel)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(IsolationLevel.class) | ||
| void getType_returns_non_empty_string_for_all_types(final IsolationLevel isolationLevel) { | ||
| assertThat(isolationLevel.getType(), notNullValue()); | ||
| assertThat(isolationLevel.getType(), not(emptyString())); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ArgumentsSource(IsolationLevelToKnownName.class) | ||
| void getType_returns_expected_string(final IsolationLevel isolationLevel, final String expectedString) { | ||
| assertThat(isolationLevel.getType(), equalTo(expectedString)); | ||
| } | ||
|
|
||
| @Test | ||
| void fromTypeValue_returns_null_for_unknown_string() { | ||
| assertThat(IsolationLevel.fromTypeValue("unknown"), nullValue()); | ||
| assertThat(IsolationLevel.fromTypeValue("READ_COMMITED_WRONG_CASE"), nullValue()); | ||
| } | ||
|
|
||
| static class IsolationLevelToKnownName implements ArgumentsProvider { | ||
| @Override | ||
| public Stream<? extends Arguments> provideArguments(final ExtensionContext context) { | ||
| return Stream.of( | ||
| arguments(IsolationLevel.READ_UNCOMMITTED, "read_uncommitted"), | ||
| arguments(IsolationLevel.READ_COMMITTED, "read_committed") | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.