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

[BUG] Fixed some failing unit tests on Windows #968

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -64,8 +64,8 @@ public void testWriteMetrics() throws TimeoutException {
Assert.assertTrue(
MetricsTestUtil.isBetween(
MetricsTestUtil.getMeasurementFromList(writeTimeMeasurements, Statistic.TOTAL_TIME).getValue(),
0.5,
0.6));
0.4,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would 0.45 and 0.65 work here? Similar to what you did in testWriteAllMetrics?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should still work yes. I can tighten it to that.

0.7));
}

@Test
Expand All @@ -91,8 +91,8 @@ public void testWriteAllMetrics() throws Exception {
Assert.assertTrue(
MetricsTestUtil.isBetween(
MetricsTestUtil.getMeasurementFromList(writeTimeMeasurements, Statistic.TOTAL_TIME).getValue(),
0.1,
0.2));
0.05,
0.25));
}

@Test
Expand Down Expand Up @@ -129,8 +129,8 @@ public void testReadMetrics() throws Exception {
Assert.assertEquals(1.0, MetricsTestUtil.getMeasurementFromList(readTimeMeasurements, Statistic.COUNT).getValue(), 0);
Assert.assertTrue(MetricsTestUtil.isBetween(
MetricsTestUtil.getMeasurementFromList(readTimeMeasurements, Statistic.TOTAL_TIME).getValue(),
0.1,
0.2));
0.05,
0.25));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PipelinesDataFlowModelTest {
void setup() {
objectMapper = new ObjectMapper(YAMLFactory.builder()
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
.enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
Expand Down Expand Up @@ -64,7 +65,7 @@ public final void testSerializingPluginModel_noExceptions() throws JsonGeneratio
public final void testSerialization_empty_plugin_to_YAML() throws JsonGenerationException, JsonMappingException, IOException {
final PluginModel pluginModel = new PluginModel("customPlugin", new HashMap<>());

final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS));

final String serialized = mapper.writeValueAsString(pluginModel);

Expand All @@ -78,7 +79,7 @@ public final void testSerialization_empty_plugin_to_YAML() throws JsonGeneration
public final void testUsingCustomSerializerWithPluginSettings_noExceptions() throws JsonGenerationException, JsonMappingException, IOException {
final PluginModel pluginModel = new PluginModel("customPlugin", validPluginSettings());

final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS));

final String serialized = mapper.writeValueAsString(pluginModel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testAttributesMutation_throwsAnException() {
@Test
public void testBuild_withoutTimeReceived() {

final Instant before = Instant.now();
final Instant before = Instant.now().minusSeconds(1);

EventMetadata result = DefaultEventMetadata.builder()
.withEventType(testEventType)
Expand All @@ -93,7 +93,7 @@ public void testBuild_withoutTimeReceived() {
final Instant timeReceived = result.getTimeReceived();
assertThat(timeReceived, notNullValue());
assertThat(timeReceived, is(greaterThan(before)));
assertThat(timeReceived, is(lessThan(Instant.now())));
assertThat(timeReceived, is(lessThan(Instant.now().plusSeconds(1))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you are adding second incase the times are the same. You be able to use lessThanOrEqualTo instead.

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void testBuild_withAttributes() {
@Test
public void testBuild_withAllMetadataFields() {

final Instant now = Instant.now();
final Instant now = Instant.now().minusSeconds(1);
final Map<String, Object> testAttributes = new HashMap<>();
testAttributes.put(UUID.randomUUID().toString(), UUID.randomUUID());
testAttributes.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.File;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -65,10 +67,12 @@ public void testGivenNullArgumentThenThrowException() {
public void testGivenLogstashConfigPathThenPipelineConfigCreated() {
final DataPrepperArgs args = new DataPrepperArgs(LOGSTASH_PIPELINE_FILE_PATH, DP_CONFIG_YAML_FILE_PATH);

final String configFileEnding = String.format("src%stest%sresources%slogstash-filter.yaml", File.separator, File.separator, File.separator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably write this as:

Paths.get("src", "test, "resources", "logstash-filter.yaml");


assertThat(args, is(notNullValue()));
assertThat(
args.getPipelineConfigFileLocation(),
endsWith("src/test/resources/logstash-filter.yaml"));
endsWith(configFileEnding));
assertThat(args.getDataPrepperConfigFileLocation(), is(DP_CONFIG_YAML_FILE_PATH));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public String convertLogstashConfigurationToPipeline(String logstashConfiguratio
ObjectMapper mapper = new ObjectMapper(YAMLFactory.builder()
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
.enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)
.enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS)
.disable(YAMLGenerator.Feature.SPLIT_LINES)
.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
.build());
Expand Down