Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE#11910] resolve mapper class paging parameter problem #11915

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Page<ConfigHistoryInfo> findConfigHistory(String dataId, String group, St
MapperResult sqlFetchRows = historyConfigInfoMapper.pageFindConfigHistoryFetchRows(context);

PaginationHelper<ConfigHistoryInfo> helper = createPaginationHelper();
return helper.fetchPage(sqlCountRows, sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(), pageNo,
return helper.fetchPageLimit(sqlCountRows, new Object[]{dataId, group, tenantTmp}, sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(), pageNo,
publicize-y marked this conversation as resolved.
Show resolved Hide resolved
pageSize, HISTORY_LIST_ROW_MAPPER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public Page<ConfigHistoryInfo> findConfigHistory(String dataId, String group, St

Page<ConfigHistoryInfo> page;
try {
page = helper.fetchPage(sqlCountRows, sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(), pageNo,
page = helper.fetchPageLimit(sqlCountRows, new Object[]{dataId, group, tenant},
sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(), pageNo,
pageSize, HISTORY_LIST_ROW_MAPPER);
} catch (DataAccessException e) {
LogUtil.FATAL_LOG.error("[list-config-history] error, dataId:{}, group:{}", new Object[] {dataId, group},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testFindConfigInfoAggrByPage() {
String dataId = "dataId111";
String group = "group";
String tenant = "tenant";

publicize-y marked this conversation as resolved.
Show resolved Hide resolved
//mock query count.
Mockito.when(databaseOperate.queryOne(anyString(), eq(new Object[] {dataId, group, tenant}), eq(Integer.class)))
.thenReturn(101);
Expand All @@ -210,11 +210,11 @@ public void testFindConfigInfoAggrByPage() {
configInfoAggrs.add(new ConfigInfoAggr());
configInfoAggrs.add(new ConfigInfoAggr());
configInfoAggrs.add(new ConfigInfoAggr());

Mockito.when(databaseOperate.queryMany(anyString(), eq(new Object[] {dataId, group, tenant}),
eq(CONFIG_INFO_AGGR_ROW_MAPPER))).thenReturn(configInfoAggrs);
int pageNo = 1;
int pageSize = 120;
int startRow = (pageNo - 1) * pageSize;
Mockito.when(databaseOperate.queryMany(anyString(), eq(new Object[] {dataId, group, tenant, startRow, pageSize}),
eq(CONFIG_INFO_AGGR_ROW_MAPPER))).thenReturn(configInfoAggrs);
Page<ConfigInfoAggr> configInfoAggrByPage = embededConfigInfoAggrPersistService.findConfigInfoAggrByPage(dataId,
group, tenant, pageNo, pageSize);
Assert.assertEquals(101, configInfoAggrByPage.getTotalCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public void testFindConfigInfo4Page() {
String dataId = "dataId4567222";
String group = "group3456789";
String tenant = "tenant4567890";

//mock total count
when(databaseOperate.queryOne(anyString(), eq(new Object[] {tenant, dataId, group}),
eq(Integer.class))).thenReturn(new Integer(9));
Expand All @@ -653,10 +653,14 @@ public void testFindConfigInfo4Page() {
result.add(createMockConfigInfo(0));
result.add(createMockConfigInfo(1));
result.add(createMockConfigInfo(2));
when(databaseOperate.queryMany(anyString(), eq(new Object[] {tenant, dataId, group}),

int pageNo = 1;
int pageSize = 3;
int startRow = (pageNo - 1) * pageSize;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {tenant, dataId, group, startRow, pageSize}),
eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);
Map<String, Object> configAdvanceInfo = new HashMap<>();
Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfo4Page(1, 3, dataId, group,
Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfo4Page(pageNo, pageSize, dataId, group,
tenant, configAdvanceInfo);
Assert.assertEquals(result.size(), configInfo4Page.getPageItems().size());
Assert.assertEquals(9, configInfo4Page.getTotalCount());
Expand All @@ -670,7 +674,6 @@ public void testFindConfigInfo4PageWithTags() {
String tenant = "tenant4567890";
Map<String, Object> configAdvanceInfo = new HashMap<>();
configAdvanceInfo.put("config_tags", "tags1,tags3");

//mock total count
when(databaseOperate.queryOne(anyString(), eq(new Object[] {tenant, dataId, group, "tags1", "tags3"}),
eq(Integer.class))).thenReturn(new Integer(9));
Expand All @@ -679,10 +682,14 @@ public void testFindConfigInfo4PageWithTags() {
result.add(createMockConfigInfo(0));
result.add(createMockConfigInfo(1));
result.add(createMockConfigInfo(2));
when(databaseOperate.queryMany(anyString(), eq(new Object[] {tenant, dataId, group, "tags1", "tags3"}),

int pageNo = 1;
int pageSize = 3;
int startRow = (pageNo - 1) * pageSize;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {tenant, dataId, group, "tags1", "tags3", startRow, pageSize}),
eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);

Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfo4Page(1, 3, dataId, group,
Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfo4Page(pageNo, pageSize, dataId, group,
tenant, configAdvanceInfo);
Assert.assertEquals(result.size(), configInfo4Page.getPageItems().size());
Assert.assertEquals(9, configInfo4Page.getTotalCount());
Expand Down Expand Up @@ -745,11 +752,15 @@ public void testFindConfigInfoLike4Page() {
result.add(createMockConfigInfo(0));
result.add(createMockConfigInfo(1));
result.add(createMockConfigInfo(2));

int pageNo = 1;
int pageSize = 3;
int startRow = (pageNo - 1) * pageSize;
when(databaseOperate.queryMany(anyString(),
eq(new Object[] {tenant, dataId.replaceAll("\\*", "%"), group.replaceAll("\\*", "%"), appName,
content}), eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);
content, startRow, pageSize}), eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);

Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfoLike4Page(1, 3, dataId, group,
Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group,
tenant, configAdvanceInfo);
Assert.assertEquals(result.size(), configInfo4Page.getPageItems().size());
Assert.assertEquals(9, configInfo4Page.getTotalCount());
Expand Down Expand Up @@ -779,7 +790,7 @@ public void testFindConfigInfoLike4PageWithTags() {
result.add(createMockConfigInfo(2));
when(databaseOperate.queryMany(anyString(),
eq(new Object[] {tenant, dataId.replaceAll("\\*", "%"), group.replaceAll("\\*", "%"), appName, content,
"tags", "tag2"}), eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);
"tags", "tag2", 0, 3}), eq(CONFIG_INFO_ROW_MAPPER))).thenReturn(result);

Page<ConfigInfo> configInfo4Page = embeddedConfigInfoPersistService.findConfigInfoLike4Page(1, 3, dataId, group,
tenant, configAdvanceInfo);
Expand Down Expand Up @@ -980,10 +991,10 @@ public void testGetTenantIdList() {
g3.put("TENANT_ID", tenantStrings.get(2));
List<Map<String, Object>> params = new ArrayList<>();
params.addAll(Arrays.asList(g1, g2, g3));

when(databaseOperate.queryMany(anyString(), eq(new Object[] {}), eq(MAP_ROW_MAPPER))).thenReturn(params);
int page = 10;
int pageSize = 100;
int startRow = (page - 1) * pageSize;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {startRow, pageSize}), eq(MAP_ROW_MAPPER))).thenReturn(params);
//execute return mock obj
List<String> returnTenants = embeddedConfigInfoPersistService.getTenantIdList(page, pageSize);
//expect check
Expand All @@ -1004,9 +1015,10 @@ public void testGetGroupIdList() {
g3.put("GROUP_ID", groupStrings.get(2));
List<Map<String, Object>> params = new ArrayList<>();
params.addAll(Arrays.asList(g1, g2, g3));
when(databaseOperate.queryMany(anyString(), eq(new Object[] {}), eq(MAP_ROW_MAPPER))).thenReturn(params);
int page = 10;
int pageSize = 100;
int startRow = (page - 1) * pageSize;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {startRow, pageSize}), eq(MAP_ROW_MAPPER))).thenReturn(params);
//execute return mock obj
List<String> returnGroups = embeddedConfigInfoPersistService.getGroupIdList(page, pageSize);

Expand All @@ -1022,9 +1034,9 @@ public void testFindAllConfigInfoFragment() {
mockConfigs.add(createMockConfigInfoWrapper(1));
mockConfigs.add(createMockConfigInfoWrapper(2));
long lastId = 10111L;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {lastId}),
eq(CONFIG_INFO_WRAPPER_ROW_MAPPER))).thenReturn(mockConfigs);
int pageSize = 100;
when(databaseOperate.queryMany(anyString(), eq(new Object[] {lastId, 0, pageSize}),
eq(CONFIG_INFO_WRAPPER_ROW_MAPPER))).thenReturn(mockConfigs);
//execute return mock obj
Page<ConfigInfoWrapper> returnConfigPage = embeddedConfigInfoPersistService.findAllConfigInfoFragment(lastId,
pageSize, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,13 @@ public void testFindAllConfigInfoTagForDumpAll() {
mockTagList.get(0).setLastModified(System.currentTimeMillis());
mockTagList.get(1).setLastModified(System.currentTimeMillis());
mockTagList.get(2).setLastModified(System.currentTimeMillis());
int pageNo = 3;
int pageSize = 100;
int startRow = (pageNo - 1) * pageSize;
//mock query list
Mockito.when(
databaseOperate.queryMany(anyString(), eq(new Object[] {}), eq(CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER)))
databaseOperate.queryMany(anyString(), eq(new Object[] {startRow, pageSize}), eq(CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER)))
.thenReturn(mockTagList);
int pageNo = 3;
int pageSize = 100;
//execute & verify
Page<ConfigInfoTagWrapper> returnTagPage = embeddedConfigInfoTagPersistService.findAllConfigInfoTagForDumpAll(
pageNo, pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void testFindConfigHistory() {
String dataId = "dataId34567";
String group = "group34567";
String tenant = "tenant34567";

//mock count
Mockito.when(databaseOperate.queryOne(anyString(), eq(new Object[] {dataId, group, tenant}), eq(Integer.class)))
.thenReturn(300);
Expand All @@ -179,10 +179,12 @@ public void testFindConfigHistory() {
mockList.add(createMockConfigHistoryInfo(0));
mockList.add(createMockConfigHistoryInfo(1));
mockList.add(createMockConfigHistoryInfo(2));
Mockito.when(databaseOperate.queryMany(anyString(), eq(new Object[] {dataId, group, tenant}),
eq(HISTORY_LIST_ROW_MAPPER))).thenReturn(mockList);

int pageSize = 100;
int pageNo = 2;
int startRow = (pageNo - 1) * pageSize;
Mockito.when(databaseOperate.queryMany(anyString(), eq(new Object[] {dataId, group, tenant, startRow, pageSize}),
eq(HISTORY_LIST_ROW_MAPPER))).thenReturn(mockList);
//execute & verify
Page<ConfigHistoryInfo> historyReturn = embeddedHistoryConfigInfoPersistService.findConfigHistory(dataId, group,
tenant, pageNo, pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void testFindConfigInfoAggrByPage() {
String dataId = "dataId111";
String group = "group";
String tenant = "tenant";

//mock query count.
when(jdbcTemplate.queryForObject(anyString(), eq(new Object[] {dataId, group, tenant}),
eq(Integer.class))).thenReturn(101);
Expand All @@ -251,11 +251,13 @@ public void testFindConfigInfoAggrByPage() {
configInfoAggrs.add(new ConfigInfoAggr());
configInfoAggrs.add(new ConfigInfoAggr());
configInfoAggrs.add(new ConfigInfoAggr());

when(jdbcTemplate.query(anyString(), eq(new Object[] {dataId, group, tenant}),
eq(CONFIG_INFO_AGGR_ROW_MAPPER))).thenReturn(configInfoAggrs);

int pageNo = 1;
int pageSize = 120;
int startRow = (pageNo - 1) * pageSize;
when(jdbcTemplate.query(anyString(), eq(new Object[] {dataId, group, tenant, startRow, pageSize}),
eq(CONFIG_INFO_AGGR_ROW_MAPPER))).thenReturn(configInfoAggrs);

Page<ConfigInfoAggr> configInfoAggrByPage = externalConfigInfoAggrPersistService.findConfigInfoAggrByPage(
dataId, group, tenant, pageNo, pageSize);
Assert.assertEquals(101, configInfoAggrByPage.getTotalCount());
Expand Down
Loading
Loading