You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/08/18 15:14:09 UTC
[airavata] branch develop updated: AIRAVATA-3302 Fix boundary
issues when offset is at the end of or past the last page
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/develop by this push:
new de930b7 AIRAVATA-3302 Fix boundary issues when offset is at the end of or past the last page
new 5b69f2b Merge branch 'airavata-3302' into develop
de930b7 is described below
commit de930b7ea1cc8dadae491bcfd65383773b15c40b
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Aug 18 11:13:16 2021 -0400
AIRAVATA-3302 Fix boundary issues when offset is at the end of or past the last page
---
.../repositories/expcatalog/ExperimentSummaryRepository.java | 7 ++++++-
.../expcatalog/ExperimentSummaryRepositoryTest.java | 10 ++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepository.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepository.java
index ee887fd..bcbc09a 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepository.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepository.java
@@ -215,10 +215,15 @@ public class ExperimentSummaryRepository extends ExpCatAbstractRepository<Experi
int count = scalarInt(query, queryParameters);
if (accumulator + count > queryOffset ) {
return new BatchOffset(batchNum, queryOffset - accumulator);
+ } else if (accumulator + count == queryOffset) {
+ // The initial batch is the next batch since this batch ends at the queryOffset
+ return new BatchOffset(batchNum + 1, 0);
}
accumulator += count;
}
- return new BatchOffset(0, 0);
+ // We didn't find a batch with the offset in it, so just return a batch
+ // num past the last one
+ return new BatchOffset(Double.valueOf(totalBatches).intValue(), 0);
}
public ExperimentStatistics getAccessibleExperimentStatistics(List<String> accessibleExperimentIds, Map<String,String> filters, int limit, int offset) throws RegistryException {
diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java
index bbc9ad4..ea068dd 100644
--- a/modules/registry/registry-core/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java
+++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java
@@ -199,6 +199,16 @@ public class ExperimentSummaryRepositoryTest extends TestBase{
DBConstants.Experiment.CREATION_TIME, ResultOrderType.ASC);
assertEquals("should only return 1 experiment since limit=2 but partial last page", 1, experimentSummaryModelList.size());
assertEquals(experimentIdThree, experimentSummaryModelList.get(0).getExperimentId());
+ // Test with offset at the end (should return empty list)
+ experimentSummaryModelList = experimentSummaryRepository.searchAllAccessibleExperiments(
+ allExperimentIds, filters, 3, 3,
+ DBConstants.Experiment.CREATION_TIME, ResultOrderType.ASC);
+ assertEquals("should return 0 since we're just past the last page (page size of 3)", 0, experimentSummaryModelList.size());
+ // Test with offset past the end (should return empty list)
+ experimentSummaryModelList = experimentSummaryRepository.searchAllAccessibleExperiments(
+ allExperimentIds, filters, 3, 10,
+ DBConstants.Experiment.CREATION_TIME, ResultOrderType.ASC);
+ assertEquals("should return 0 since we're well past the last page (page size of 3)", 0, experimentSummaryModelList.size());
filters = new HashMap<>();
filters.put(DBConstants.Experiment.GATEWAY_ID, gatewayId);