-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix null exception in text docs data set (#1403)
Signed-off-by: Yaliang Wu <[email protected]>
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
53 changes: 53 additions & 0 deletions
53
common/src/test/java/org/opensearch/ml/common/dataset/TextDocsInputDataSetTest.java
This file contains 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,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataset; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TextDocsInputDataSetTest { | ||
|
||
@Rule | ||
public ExpectedException exceptionRule = ExpectedException.none(); | ||
|
||
@Test | ||
public void writeTo_Success() throws IOException { | ||
TextDocsInputDataSet inputDataSet = TextDocsInputDataSet.builder().docs(Arrays.asList("doc1", "doc2")).build(); | ||
BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); | ||
inputDataSet.writeTo(bytesStreamOutput); | ||
|
||
StreamInput streamInput = bytesStreamOutput.bytes().streamInput(); | ||
MLInputDataType inputDataType = streamInput.readEnum(MLInputDataType.class); | ||
assertEquals(MLInputDataType.TEXT_DOCS, inputDataType); | ||
TextDocsInputDataSet inputDataSet1 = new TextDocsInputDataSet((streamInput)); | ||
assertEquals(2, inputDataSet1.getDocs().size()); | ||
assertEquals("doc1", inputDataSet1.getDocs().get(0)); | ||
assertEquals("doc2", inputDataSet1.getDocs().get(1)); | ||
} | ||
|
||
@Test | ||
public void writeTo_Success_NullValue() throws IOException { | ||
TextDocsInputDataSet inputDataSet = TextDocsInputDataSet.builder().docs(Arrays.asList("doc1", null)).build(); | ||
BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); | ||
inputDataSet.writeTo(bytesStreamOutput); | ||
|
||
StreamInput streamInput = bytesStreamOutput.bytes().streamInput(); | ||
MLInputDataType inputDataType = streamInput.readEnum(MLInputDataType.class); | ||
assertEquals(MLInputDataType.TEXT_DOCS, inputDataType); | ||
TextDocsInputDataSet inputDataSet1 = new TextDocsInputDataSet((streamInput)); | ||
assertEquals(2, inputDataSet1.getDocs().size()); | ||
assertEquals("doc1", inputDataSet1.getDocs().get(0)); | ||
assertEquals(null, inputDataSet1.getDocs().get(1)); | ||
} | ||
} |