Skip to content

Commit

Permalink
tune methods name in text chunking proceesor unit tests
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 15, 2024
1 parent 98dd886 commit d245a04
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ private List<Map<String, Object>> createSourceDataListNestedMap() {
return List.of(documents, documents);
}

private Map<String, Object> createFixedTokenLengthParametersWithMaxChunk(int maxChunkNum) {
private Map<String, Object> createFixedTokenLengthParametersWithMaxChunkLimit(int maxChunkLimit) {
Map<String, Object> parameters = new HashMap<>();
parameters.put(FixedTokenLengthChunker.TOKEN_LIMIT_FIELD, 10);
parameters.put(MAX_CHUNK_LIMIT_FIELD, maxChunkNum);
parameters.put(MAX_CHUNK_LIMIT_FIELD, maxChunkLimit);
return parameters;
}

Expand Down Expand Up @@ -150,10 +150,10 @@ private TextChunkingProcessor createFixedTokenLengthInstance(Map<String, Object>
}

@SneakyThrows
private TextChunkingProcessor createFixedTokenLengthInstanceWithMaxChunkNum(Map<String, Object> fieldMap, int maxChunkNum) {
private TextChunkingProcessor createFixedTokenLengthInstanceWithMaxChunkLimit(Map<String, Object> fieldMap, int maxChunkLimit) {
Map<String, Object> config = new HashMap<>();
Map<String, Object> algorithmMap = new HashMap<>();
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunk(maxChunkNum));
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunkLimit(maxChunkLimit));
config.put(FIELD_MAP_FIELD, fieldMap);
config.put(ALGORITHM_FIELD, algorithmMap);
Map<String, Processor.Factory> registry = new HashMap<>();
Expand Down Expand Up @@ -189,13 +189,13 @@ public void testCreate_whenAlgorithmFieldMissing_thenFail() {
}

@SneakyThrows
public void testCreate_whenMaxChunkNumInvalidValue_thenFail() {
public void testCreate_whenMaxChunkLimitInvalidValue_thenFail() {
Map<String, Processor.Factory> registry = new HashMap<>();
Map<String, Object> config = new HashMap<>();
Map<String, Object> fieldMap = new HashMap<>();
Map<String, Object> algorithmMap = new HashMap<>();
fieldMap.put(INPUT_FIELD, OUTPUT_FIELD);
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunk(-2));
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunkLimit(-2));
config.put(FIELD_MAP_FIELD, fieldMap);
config.put(ALGORITHM_FIELD, algorithmMap);
IllegalArgumentException illegalArgumentException = assertThrows(
Expand All @@ -207,13 +207,13 @@ public void testCreate_whenMaxChunkNumInvalidValue_thenFail() {
}

@SneakyThrows
public void testCreate_whenMaxChunkNumDisabledValue_thenSucceed() {
public void testCreate_whenMaxChunkLimitDisabledValue_thenSucceed() {
Map<String, Processor.Factory> registry = new HashMap<>();
Map<String, Object> config = new HashMap<>();
Map<String, Object> fieldMap = new HashMap<>();
Map<String, Object> algorithmMap = new HashMap<>();
fieldMap.put(INPUT_FIELD, OUTPUT_FIELD);
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunk(-1));
algorithmMap.put(FixedTokenLengthChunker.ALGORITHM_NAME, createFixedTokenLengthParametersWithMaxChunkLimit(-1));
config.put(FIELD_MAP_FIELD, fieldMap);
config.put(ALGORITHM_FIELD, algorithmMap);
textChunkingProcessorFactory.create(registry, PROCESSOR_TAG, DESCRIPTION, config);
Expand Down Expand Up @@ -369,8 +369,8 @@ private IngestDocument createIngestDocumentWithSourceData(Object sourceData) {
}

@SneakyThrows
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNum_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkNum(createStringFieldMap(), 5);
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkLimit_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkLimit(createStringFieldMap(), 5);
IngestDocument ingestDocument = createIngestDocumentWithSourceData(createSourceDataString());
IngestDocument document = processor.execute(ingestDocument);
assert document.getSourceAndMetadata().containsKey(OUTPUT_FIELD);
Expand All @@ -384,8 +384,8 @@ public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNum_
}

@SneakyThrows
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNumTwice_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkNum(createStringFieldMap(), 5);
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkLimitTwice_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkLimit(createStringFieldMap(), 5);
for (int i = 0; i < 2; i++) {
IngestDocument ingestDocument = createIngestDocumentWithSourceData(createSourceDataString());
IngestDocument document = processor.execute(ingestDocument);
Expand All @@ -401,8 +401,8 @@ public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNumT
}

@SneakyThrows
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNumDisabled_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkNum(createStringFieldMap(), -1);
public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkLimitDisabled_thenSucceed() {
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkLimit(createStringFieldMap(), -1);
IngestDocument ingestDocument = createIngestDocumentWithSourceData(createSourceDataString());
IngestDocument document = processor.execute(ingestDocument);
assert document.getSourceAndMetadata().containsKey(OUTPUT_FIELD);
Expand All @@ -418,7 +418,7 @@ public void testExecute_withFixedTokenLength_andSourceDataStringWithMaxChunkNumD
@SneakyThrows
public void testExecute_withFixedTokenLength_andSourceDataStringExceedMaxChunkLimit_thenFail() {
int maxChunkLimit = 1;
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkNum(createStringFieldMap(), maxChunkLimit);
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkLimit(createStringFieldMap(), maxChunkLimit);
IngestDocument ingestDocument = createIngestDocumentWithSourceData(createSourceDataString());
IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, () -> processor.execute(ingestDocument));
assert (illegalStateException.getMessage()
Expand All @@ -433,9 +433,9 @@ public void testExecute_withFixedTokenLength_andSourceDataStringExceedMaxChunkLi
}

@SneakyThrows
public void testExecute_withFixedTokenLength_andSourceDataListWithMaxChunkLimitExceed_thenFail() {
public void testExecute_withFixedTokenLength_andSourceDataListExceedMaxChunkLimit_thenFail() {
int maxChunkLimit = 5;
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkNum(createStringFieldMap(), maxChunkLimit);
TextChunkingProcessor processor = createFixedTokenLengthInstanceWithMaxChunkLimit(createStringFieldMap(), maxChunkLimit);
IngestDocument ingestDocument = createIngestDocumentWithSourceData(createSourceDataListStrings());
IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, () -> processor.execute(ingestDocument));
assert (illegalStateException.getMessage()
Expand Down

0 comments on commit d245a04

Please sign in to comment.