fix batch2 npe when no results returned (#5219)
* fix npe error * spotless * spotless
This commit is contained in:
parent
ab2a86b0d5
commit
b9155721a7
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 5219
|
||||||
|
title: "Reindex batch job threw an exception when no results matched the reindex request. This has been corrected."
|
|
@ -90,15 +90,15 @@ public class ResourceIdListStep<PT extends PartitionedJobParameters, IT extends
|
||||||
|
|
||||||
if (nextChunk.isEmpty()) {
|
if (nextChunk.isEmpty()) {
|
||||||
ourLog.info("No data returned");
|
ourLog.info("No data returned");
|
||||||
}
|
} else {
|
||||||
|
|
||||||
ourLog.debug("Found {} IDs from {} to {}", nextChunk.size(), start, nextChunk.getLastDate());
|
ourLog.debug("Found {} IDs from {} to {}", nextChunk.size(), start, nextChunk.getLastDate());
|
||||||
|
|
||||||
final Set<TypedPidJson> idBuffer = nextChunk.getTypedResourcePids().stream()
|
final Set<TypedPidJson> idBuffer = nextChunk.getTypedResourcePids().stream()
|
||||||
.map(TypedPidJson::new)
|
.map(TypedPidJson::new)
|
||||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
|
||||||
final UnmodifiableIterator<List<TypedPidJson>> partition = Iterators.partition(idBuffer.iterator(), maxBatchId);
|
final UnmodifiableIterator<List<TypedPidJson>> partition =
|
||||||
|
Iterators.partition(idBuffer.iterator(), maxBatchId);
|
||||||
|
|
||||||
while (partition.hasNext()) {
|
while (partition.hasNext()) {
|
||||||
final List<TypedPidJson> submissionIds = partition.next();
|
final List<TypedPidJson> submissionIds = partition.next();
|
||||||
|
@ -109,6 +109,7 @@ public class ResourceIdListStep<PT extends PartitionedJobParameters, IT extends
|
||||||
}
|
}
|
||||||
|
|
||||||
ourLog.info("Submitted {} chunks with {} resource IDs", chunkCount, totalIdsFound);
|
ourLog.info("Submitted {} chunks with {} resource IDs", chunkCount, totalIdsFound);
|
||||||
|
}
|
||||||
return RunOutcome.SUCCESS;
|
return RunOutcome.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,18 +56,17 @@ class ResourceIdListStepTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(ints = {1, 100, 500, 501, 2345, 10500})
|
@ValueSource(ints = {0, 1, 100, 500, 501, 2345, 10500})
|
||||||
void testResourceIdListBatchSizeLimit(int theListSize) {
|
void testResourceIdListBatchSizeLimit(int theListSize) {
|
||||||
List<TypedResourcePid> idList = generateIdList(theListSize);
|
List<TypedResourcePid> idList = generateIdList(theListSize);
|
||||||
when(myStepExecutionDetails.getData()).thenReturn(myData);
|
when(myStepExecutionDetails.getData()).thenReturn(myData);
|
||||||
when(myParameters.getBatchSize()).thenReturn(theListSize);
|
when(myParameters.getBatchSize()).thenReturn(theListSize);
|
||||||
when(myStepExecutionDetails.getParameters()).thenReturn(myParameters);
|
when(myStepExecutionDetails.getParameters()).thenReturn(myParameters);
|
||||||
HomogeneousResourcePidList homogeneousResourcePidList = mock(HomogeneousResourcePidList.class);
|
HomogeneousResourcePidList homogeneousResourcePidList = mock(HomogeneousResourcePidList.class);
|
||||||
|
if (theListSize > 0) {
|
||||||
when(homogeneousResourcePidList.getTypedResourcePids()).thenReturn(idList);
|
when(homogeneousResourcePidList.getTypedResourcePids()).thenReturn(idList);
|
||||||
when(homogeneousResourcePidList.getLastDate()).thenReturn(new Date());
|
when(homogeneousResourcePidList.getLastDate()).thenReturn(new Date());
|
||||||
when(myIdChunkProducer.fetchResourceIdsPage(any(), any(), any(), any(), any()))
|
when(homogeneousResourcePidList.isEmpty()).thenReturn(false);
|
||||||
.thenReturn(homogeneousResourcePidList);
|
|
||||||
|
|
||||||
// Ensure none of the work chunks exceed MAX_BATCH_OF_IDS in size:
|
// Ensure none of the work chunks exceed MAX_BATCH_OF_IDS in size:
|
||||||
doAnswer(i -> {
|
doAnswer(i -> {
|
||||||
ResourceIdListWorkChunkJson list = i.getArgument(0);
|
ResourceIdListWorkChunkJson list = i.getArgument(0);
|
||||||
|
@ -75,6 +74,12 @@ class ResourceIdListStepTest {
|
||||||
"Id batch size should never exceed " + ResourceIdListStep.MAX_BATCH_OF_IDS);
|
"Id batch size should never exceed " + ResourceIdListStep.MAX_BATCH_OF_IDS);
|
||||||
return null;
|
return null;
|
||||||
}).when(myDataSink).accept(any(ResourceIdListWorkChunkJson.class));
|
}).when(myDataSink).accept(any(ResourceIdListWorkChunkJson.class));
|
||||||
|
} else {
|
||||||
|
when(homogeneousResourcePidList.isEmpty()).thenReturn(true);
|
||||||
|
}
|
||||||
|
when(myIdChunkProducer.fetchResourceIdsPage(any(), any(), any(), any(), any()))
|
||||||
|
.thenReturn(homogeneousResourcePidList);
|
||||||
|
|
||||||
|
|
||||||
final RunOutcome run = myResourceIdListStep.run(myStepExecutionDetails, myDataSink);
|
final RunOutcome run = myResourceIdListStep.run(myStepExecutionDetails, myDataSink);
|
||||||
assertNotEquals(null, run);
|
assertNotEquals(null, run);
|
||||||
|
@ -93,8 +98,10 @@ class ResourceIdListStepTest {
|
||||||
// The very last chunk should be whatever is left over (if there is a remainder):
|
// The very last chunk should be whatever is left over (if there is a remainder):
|
||||||
int expectedLastBatchSize = theListSize % ResourceIdListStep.MAX_BATCH_OF_IDS;
|
int expectedLastBatchSize = theListSize % ResourceIdListStep.MAX_BATCH_OF_IDS;
|
||||||
expectedLastBatchSize = (expectedLastBatchSize == 0) ? ResourceIdListStep.MAX_BATCH_OF_IDS : expectedLastBatchSize;
|
expectedLastBatchSize = (expectedLastBatchSize == 0) ? ResourceIdListStep.MAX_BATCH_OF_IDS : expectedLastBatchSize;
|
||||||
|
if (!allDataChunks.isEmpty()) {
|
||||||
assertEquals(expectedLastBatchSize, allDataChunks.get(allDataChunks.size() - 1).size());
|
assertEquals(expectedLastBatchSize, allDataChunks.get(allDataChunks.size() - 1).size());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<TypedResourcePid> generateIdList(int theListSize) {
|
private List<TypedResourcePid> generateIdList(int theListSize) {
|
||||||
List<TypedResourcePid> idList = new ArrayList<>();
|
List<TypedResourcePid> idList = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue