Skip to content

Commit

Permalink
Fixes two flaky unit tests that have failed recently (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#3150)

Fixes two unit tests that have failed and are probably flaky. The ParseTreeEvaluatorListenerTest appears to be using negative values sometimes, which seems to be unsupported. The OTelLogsSourceTest test failed as well, but it appears this code may not always be executed because it was mixing Hamcrest and Mockito.

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable authored Aug 14, 2023
1 parent 0f70d52 commit 60f69b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void testSimpleRelationalOperatorExpressionWithInValidLiteralType() {
@Test
void testSimpleRelationalOperatorExpressionWithJsonPointerTypeValidValue() {
final String testKey = "testKey";
final int testValue = random.nextInt(1000);
final int testValue = random.nextInt(1000) + 2;
final Map<String, Integer> data = Map.of(testKey, testValue);
final Event testEvent = createTestEvent(data);
final String greaterThanStatement = String.format(" /%s > %d", testKey, testValue - 1);
Expand All @@ -207,7 +207,7 @@ void testSimpleRelationalOperatorExpressionWithJsonPointerTypeValidValue() {
}

@Test
void testSimpleRelationalOperatorExpressionWithJsonPointerTypeInValidValue() {
void testSimpleRelationalOperatorExpressionWithJsonPointerTypeInValidValueWithPositiveInteger() {
final String testKey = "testKey";
final boolean testValue = true;
final Map<String, Boolean> data = Map.of(testKey, testValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

package org.opensearch.dataprepper.plugins.source.otellogs;

import com.linecorp.armeria.common.HttpHeaderNames;
import com.linecorp.armeria.common.grpc.GrpcStatusFunction;
import org.opensearch.dataprepper.plugins.codec.CompressionOption;
import org.opensearch.dataprepper.plugins.health.HealthGrpcService;
import org.opensearch.dataprepper.plugins.source.otellogs.certificate.CertificateProviderFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
Expand All @@ -18,11 +13,13 @@
import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.common.AggregatedHttpResponse;
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.HttpHeaderNames;
import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.common.RequestHeaders;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.grpc.GrpcStatusFunction;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.server.grpc.GrpcService;
Expand Down Expand Up @@ -69,6 +66,9 @@
import org.opensearch.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer;
import org.opensearch.dataprepper.plugins.certificate.CertificateProvider;
import org.opensearch.dataprepper.plugins.certificate.model.Certificate;
import org.opensearch.dataprepper.plugins.codec.CompressionOption;
import org.opensearch.dataprepper.plugins.health.HealthGrpcService;
import org.opensearch.dataprepper.plugins.source.otellogs.certificate.CertificateProviderFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -89,25 +89,22 @@
import java.util.stream.Stream;
import java.util.zip.GZIPOutputStream;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.DEFAULT_PORT;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.DEFAULT_REQUEST_TIMEOUT_MS;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.SSL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
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.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
Expand All @@ -117,6 +114,9 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.DEFAULT_PORT;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.DEFAULT_REQUEST_TIMEOUT_MS;
import static org.opensearch.dataprepper.plugins.source.otellogs.OTelLogsSourceConfig.SSL;

@ExtendWith(MockitoExtension.class)
class OTelLogsSourceTest {
Expand Down Expand Up @@ -800,8 +800,9 @@ private void assertSecureResponseWithStatusCode(final AggregatedHttpResponse res
.stream()
.map(Map.Entry::getKey)
.map(AsciiString::toString)
.map(String::toLowerCase)
.collect(Collectors.toList());
assertThat("Response Header Keys", headerKeys, not(contains("server")));
assertThat("Response Header Keys", headerKeys, not(hasItem("server")));
}

private byte[] createGZipCompressedPayload(final String payload) throws IOException {
Expand Down

0 comments on commit 60f69b3

Please sign in to comment.