Skip to content

Commit

Permalink
ArraysIntersectProcessor should validate if source fields are present (
Browse files Browse the repository at this point in the history
  • Loading branch information
matvey-mtn authored Apr 3, 2022
1 parent 10904b7 commit abefc87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public ArraysIntersectProcessor(String sourceFieldA, String sourceFieldB, String

@Override
public ProcessResult process(Doc doc) {
if (!doc.hasField(sourceFieldA) || !doc.hasField(sourceFieldB)) {
return ProcessResult.failure("One or both input fields are missing");
}

Iterable<Object> arrayA = doc.getField(sourceFieldA);
Iterable<Object> arrayB = doc.getField(sourceFieldB);

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

import com.google.common.collect.ImmutableMap;
import io.logz.sawmill.Doc;
import io.logz.sawmill.ProcessResult;
import io.logz.sawmill.Processor;
import org.junit.Test;

Expand Down Expand Up @@ -53,16 +54,17 @@ public void testEmptyIntersectionAddsEmptyList() throws InterruptedException {
}

@Test
public void testMissingSourceFieldsFailsProcessing() {
public void testMissingSourceFieldsFailsProcessing() throws InterruptedException {
String badFieldName = "some-other-field";
Processor processor = createProcessor(ArraysIntersectProcessor.class, LIST_INTERSECT_CONFIG);
List<Integer> array = Arrays.asList(1, 2, 3);
Doc doc = createDoc(badFieldName, array, SOURCE_FIELD_B, array);

assertThatThrownBy(() -> processor.process(doc))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(SOURCE_FIELD_A);
assertThat(doc.hasField(TARGET_FIELD)).isEqualTo(false);

ProcessResult processResult = processor.process(doc);
assertThat(processResult.isSucceeded()).isFalse();
assertThat(processResult.getError()).isPresent();
assertThat(processResult.getError().get().getMessage()).contains("One or both input fields are missing");
}

@Test
Expand Down

0 comments on commit abefc87

Please sign in to comment.