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

Revert enum deserializer changes #5113

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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 @@ -79,13 +79,11 @@ public static ByteCount parse(final String string) {
final String unitString = matcher.group("unit");

if(unitString == null) {
throw new ByteCountInvalidInputException("Byte counts must have a unit. Valid byte units include: " +
Arrays.stream(Unit.values()).map(unitValue -> unitValue.unitString).collect(Collectors.toList()));
throw new ByteCountInvalidInputException("Byte counts must have a unit.");
}

final Unit unit = Unit.fromString(unitString)
.orElseThrow(() -> new ByteCountInvalidInputException("Invalid byte unit: '" + unitString + "'. Valid byte units include: "
+ Arrays.stream(Unit.values()).map(unitValue -> unitValue.unitString).collect(Collectors.toList())));
.orElseThrow(() -> new ByteCountInvalidInputException("Invalid byte unit: '" + unitString + "'"));

final BigDecimal valueBigDecimal = new BigDecimal(valueString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.dataprepper.integration;

import org.junit.FixMethodOrder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.opensearch.dataprepper.model.event.Event;
Expand All @@ -29,7 +28,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@FixMethodOrder()
class PipelinesWithAcksIT {
private static final Logger LOG = LoggerFactory.getLogger(PipelinesWithAcksIT.class);
private static final String IN_MEMORY_IDENTIFIER = "PipelinesWithAcksIT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ private void buildPipelineFromConfiguration(
Buffer pipelineDefinedBuffer = null;
final PluginSetting bufferPluginSetting = pipelineConfiguration.getBufferPluginSetting();
try {
if (source != null) {
pipelineDefinedBuffer = pluginFactory.loadPlugin(Buffer.class, bufferPluginSetting, source.getDecoder());
}
pipelineDefinedBuffer = pluginFactory.loadPlugin(Buffer.class, bufferPluginSetting, source.getDecoder());
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelineModel.BUFFER_PLUGIN_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,16 @@ void parseConfiguration_with_invalid_root_source_pipeline_creates_empty_pipeline
final Map<String, Pipeline> connectedPipelines = pipelineTransformer.transformConfiguration();
assertThat(connectedPipelines.size(), equalTo(0));
verify(dataPrepperConfiguration).getPipelineExtensions();
assertThat(pluginErrorCollector.getPluginErrors().size(), equalTo(1));
assertThat(pluginErrorCollector.getPluginErrors().size(), equalTo(2));
final PluginError sourcePluginError = pluginErrorCollector.getPluginErrors().get(0);
assertThat(sourcePluginError.getPipelineName(), equalTo("test-pipeline-1"));
assertThat(sourcePluginError.getPluginName(), equalTo("file"));
assertThat(sourcePluginError.getException(), notNullValue());
// Buffer plugin gets error due to instantiated source is null
final PluginError bufferPluginError = pluginErrorCollector.getPluginErrors().get(1);
assertThat(bufferPluginError.getPipelineName(), equalTo("test-pipeline-1"));
assertThat(bufferPluginError.getPluginName(), equalTo("bounded_blocking"));
assertThat(bufferPluginError.getException(), notNullValue());
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ByteCount deserialize(final JsonParser parser, final DeserializationConte
try {
return ByteCount.parse(byteString);
} catch (final Exception ex) {
throw new IllegalArgumentException(ex.getMessage());
throw new IllegalArgumentException(ex);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.params.provider.ValueSource;
import org.opensearch.dataprepper.model.types.ByteCount;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -32,28 +31,9 @@ void setUp() {
}

@ParameterizedTest
@ValueSource(strings = {"1", "10"})
void convert_with_no_byte_unit_throws_expected_exception(final String invalidByteString) {
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> objectMapper.convertValue(invalidByteString, ByteCount.class));
assertThat(exception.getMessage(), containsString("Byte counts must have a unit. Valid byte units include: [b, kb, mb, gb]"));
}

@ParameterizedTest
@ValueSource(strings = {"10 2b", "bad"})
void convert_with_non_parseable_values_throws(final String invalidByteString) {
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> objectMapper.convertValue(invalidByteString, ByteCount.class));
assertThat(exception.getMessage(), containsString("Unable to parse bytes"));
}

@ParameterizedTest
@CsvSource({
"10f, f",
"1vb, vb",
"3g, g"
})
void convert_with_invalid_byte_units_throws(final String invalidByteString, final String invalidUnit) {
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> objectMapper.convertValue(invalidByteString, ByteCount.class));
assertThat(exception.getMessage(), containsString("Invalid byte unit: '" + invalidUnit + "'. Valid byte units include: [b, kb, mb, gb]"));
@ValueSource(strings = {"1", "1b 2b", "1vb", "bad"})
void convert_with_invalid_values_throws(final String invalidByteString) {
assertThrows(IllegalArgumentException.class, () -> objectMapper.convertValue(invalidByteString, ByteCount.class));
}

@ParameterizedTest
Expand Down
Loading
Loading