Skip to content

Commit

Permalink
string format description for non or multiple algorithm
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Mar 12, 2024
1 parent 2760490 commit faae633
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ public String getType() {

@SuppressWarnings("unchecked")
private void validateAndParseAlgorithmMap(Map<String, Object> algorithmMap) {
if (algorithmMap.size() != 1) {
if (algorithmMap.isEmpty()) {
throw new IllegalArgumentException(
"Unable to create the processor as [" + ALGORITHM_FIELD + "] must contain and only contain 1 algorithm"
String.format("Unable to create %s processor as [%s] does not contain any algorithm", TYPE, ALGORITHM_FIELD)
);
} else if (algorithmMap.size() > 1) {
throw new IllegalArgumentException(
String.format("Unable to create %s processor as [%s] contains multiple algorithms", TYPE, ALGORITHM_FIELD)
);
}
Entry<String, Object> algorithmEntry = algorithmMap.entrySet().iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opensearch.neuralsearch.processor.factory.TextChunkingProcessorFactory;
import org.opensearch.plugins.AnalysisPlugin;
import org.opensearch.test.OpenSearchTestCase;
import static org.opensearch.neuralsearch.processor.TextChunkingProcessor.TYPE;
import static org.opensearch.neuralsearch.processor.TextChunkingProcessor.FIELD_MAP_FIELD;
import static org.opensearch.neuralsearch.processor.TextChunkingProcessor.ALGORITHM_FIELD;
import static org.opensearch.neuralsearch.processor.TextChunkingProcessor.MAX_CHUNK_LIMIT_FIELD;
Expand Down Expand Up @@ -201,7 +202,7 @@ public void testCreate_whenAlgorithmFieldNoAlgorithm_thenFail() {
() -> textChunkingProcessorFactory.create(registry, PROCESSOR_TAG, DESCRIPTION, config)
);
assertEquals(
"Unable to create the processor as [" + ALGORITHM_FIELD + "] must contain and only contain 1 algorithm",
String.format("Unable to create %s processor as [%s] does not contain any algorithm", TYPE, ALGORITHM_FIELD),
illegalArgumentException.getMessage()
);
}
Expand All @@ -221,7 +222,7 @@ public void testCreate_whenAlgorithmFieldMultipleAlgorithm_thenFail() {
() -> textChunkingProcessorFactory.create(registry, PROCESSOR_TAG, DESCRIPTION, config)
);
assertEquals(
"Unable to create the processor as [" + ALGORITHM_FIELD + "] must contain and only contain 1 algorithm",
String.format("Unable to create %s processor as [%s] contains multiple algorithms", TYPE, ALGORITHM_FIELD),
illegalArgumentException.getMessage()
);
}
Expand Down Expand Up @@ -271,7 +272,7 @@ public void testCreate_whenAlgorithmFieldInvalidAlgorithmContent_thenFail() {
public void testGetType() {
TextChunkingProcessor processor = createFixedTokenLengthInstance(createStringFieldMap());
String type = processor.getType();
assertEquals(TextChunkingProcessor.TYPE, type);
assertEquals(TYPE, type);
}

private String createSourceDataString() {
Expand Down

0 comments on commit faae633

Please sign in to comment.