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

fix:API-paging #172

Merged
merged 33 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
77b421c
fix:API-paging
Nov 2, 2023
f5e476d
Adding tests
Nov 3, 2023
89a5d58
Update BeekeeperApiIntegrationTest.java
Nov 3, 2023
9e7f763
Update CHANGELOG.md
HamzaJugon Nov 7, 2023
1a59b02
Update CHANGELOG.md
HamzaJugon Nov 7, 2023
6db5465
Update CHANGELOG.md
HamzaJugon Nov 7, 2023
4966b56
[maven-release-plugin] prepare release beekeeper-parent-3.5.5
eg-oss-ci Nov 7, 2023
a47309e
[maven-release-plugin] prepare for next development iteration
eg-oss-ci Nov 7, 2023
16bb13d
Update pom.xml
HamzaJugon Nov 8, 2023
643d1ca
Update pom.xml
HamzaJugon Nov 8, 2023
db6a691
Update pom.xml
HamzaJugon Nov 8, 2023
03d3f4b
Update pom.xml
HamzaJugon Nov 8, 2023
2c29d08
Update pom.xml
HamzaJugon Nov 8, 2023
586a11f
Update pom.xml
HamzaJugon Nov 8, 2023
4a18f68
Update pom.xml
HamzaJugon Nov 8, 2023
249c99f
Update pom.xml
HamzaJugon Nov 8, 2023
ccead96
Update pom.xml
HamzaJugon Nov 8, 2023
d9e016a
Update pom.xml
HamzaJugon Nov 8, 2023
30c2040
Remove surplus comments
Nov 8, 2023
7a02cc5
Update CHANGELOG.md
HamzaJugon Nov 8, 2023
bad68e0
Update CHANGELOG.md
HamzaJugon Nov 9, 2023
4496f4d
Update beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/res…
andreeapad Nov 9, 2023
fcc6a73
Update beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/res…
HamzaJugon Nov 9, 2023
9d913fe
Update MetadataResponseConverter.java
HamzaJugon Nov 9, 2023
ebacb6d
Update PathResponseConverter.java
HamzaJugon Nov 9, 2023
8f94433
Update CHANGELOG.md
HamzaJugon Nov 9, 2023
e1de760
Update BeekeeperApiIntegrationTest.java
Nov 10, 2023
fdabfc5
Update BeekeeperApiIntegrationTest.java
Nov 10, 2023
9e3f1d3
Update BeekeeperApiIntegrationTest.java
Nov 10, 2023
fd4d461
Update BeekeeperApiIntegrationTest.java
Nov 10, 2023
c067716
Refactoring tests
Nov 10, 2023
6d5e33d
Update beekeeper-integration-tests/src/test/java/com/expediagroup/bee…
HamzaJugon Nov 10, 2023
d853eb7
Refactoring tests
Nov 10, 2023
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 @@ -37,13 +37,18 @@ public final class MetadataResponseConverter {
public static Page<HousekeepingMetadataResponse> convertToHousekeepingMetadataResponsePage(
Page<HousekeepingMetadata> housekeepingMetadataPage) {
List<HousekeepingMetadata> housekeepingMetadataList = housekeepingMetadataPage.getContent();
//Create a new ArrayList to store the HousekeepingMetadataResponse objects.
List<HousekeepingMetadataResponse> housekeepingMetadataResponseList = new ArrayList<>();
//Iterate over the list of HousekeepingMetadata objects and convert each one to a HousekeepingMetadataResponse object.
for (HousekeepingMetadata housekeepingMetadata : housekeepingMetadataList) {
HousekeepingMetadataResponse housekeepingMetadataResponse = convertToHousekeepingMetadataResponse(
housekeepingMetadata);
HousekeepingMetadataResponse housekeepingMetadataResponse = convertToHousekeepingMetadataResponse(housekeepingMetadata);
housekeepingMetadataResponseList.add(housekeepingMetadataResponse);
}
return new PageImpl<>(housekeepingMetadataResponseList);
//Create a new PageImpl<HousekeepingMetadataResponse> object using the HousekeepingMetadataResponse list, the Pageable
HamzaJugon marked this conversation as resolved.
Show resolved Hide resolved
// object from the HousekeepingMetadataPage object, and the total number of elements from the HousekeepingMetadataPage object.
PageImpl<HousekeepingMetadataResponse> housekeepingMetadataResponses = new PageImpl<>(
housekeepingMetadataResponseList, housekeepingMetadataPage.getPageable(), housekeepingMetadataPage.getTotalElements());
return housekeepingMetadataResponses;
}

private static HousekeepingMetadataResponse convertToHousekeepingMetadataResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ private static HousekeepingPathResponse convertToHousekeepingPathResponse(Housek
public static Page<HousekeepingPathResponse> convertToHousekeepingPathResponsePage(
Page<HousekeepingPath> housekeepingPathPage) {
List<HousekeepingPath> housekeepingPathList = housekeepingPathPage.getContent();
//Create a new ArrayList to store the HousekeepingPathResponse objects.
List<HousekeepingPathResponse> housekeepingPathResponseList = new ArrayList<>();
//Iterate over the list of HousekeepingPath objects and convert each one to a HousekeepingPathResponse object.
for (HousekeepingPath housekeepingPath : housekeepingPathList) {
HousekeepingPathResponse housekeepingPathResponse = convertToHousekeepingPathResponse(housekeepingPath);
housekeepingPathResponseList.add(housekeepingPathResponse);
}
return new PageImpl<>(housekeepingPathResponseList);
PageImpl<HousekeepingPathResponse> HousekeepingPathResponses = new PageImpl<>(
abhimanyugupta07 marked this conversation as resolved.
Show resolved Hide resolved
housekeepingPathResponseList, housekeepingPathPage.getPageable(), housekeepingPathPage.getTotalElements());
return HousekeepingPathResponses;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019-2021 Expedia, Inc.
* Copyright (C) 2019-2023 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,8 @@ public void testConvertToHouseKeepingMetadataResponsePage() {

assertThat(metadataResponsePageList.get(0)).isEqualTo(metadataResponse1);
assertThat(metadataResponsePageList.get(1)).isEqualTo(metadataResponse2);
assertThat(metadataResponsePage.getTotalElements()).isEqualTo(2L);
assertThat(metadataResponsePage.getTotalPages()).isEqualTo(1L);
HamzaJugon marked this conversation as resolved.
Show resolved Hide resolved
assertThat(metadataResponsePage.getPageable()).isEqualTo((new PageImpl<>(housekeepingMetadataList).getPageable()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (C) 2019-2023 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.expediagroup.beekeeper.api.response;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import static com.expediagroup.beekeeper.api.response.PathResponseConverter.convertToHousekeepingPathResponsePage;
import static com.expediagroup.beekeeper.api.util.DummyHousekeepingEntityGenerator.generateDummyHousekeepingPath;
import static com.expediagroup.beekeeper.api.util.DummyHousekeepingEntityGenerator.generateDummyHousekeepingPathResponse;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;

import com.expediagroup.beekeeper.core.model.HousekeepingPath;

public class PathResponseConverterTest {

@Test
public void testConvertToHousekeepingPathResponsePage() {
HousekeepingPath housekeepingPath1 = generateDummyHousekeepingPath("some_database1", "some_table1");
HousekeepingPath housekeepingPath2 = generateDummyHousekeepingPath("some_database2", "some_table2");
HousekeepingPathResponse housekeepingPathResponse1 = generateDummyHousekeepingPathResponse(housekeepingPath1);
HousekeepingPathResponse housekeepingPathResponse2 = generateDummyHousekeepingPathResponse(housekeepingPath2);

List<HousekeepingPath> housekeepingPathList = List.of(housekeepingPath1, housekeepingPath2);
Page<HousekeepingPathResponse> housekeepingPathResponsePage = convertToHousekeepingPathResponsePage(
new PageImpl<>(housekeepingPathList));

List<HousekeepingPathResponse> housekeepingPathResponsePageList = housekeepingPathResponsePage.getContent();

assertThat(housekeepingPathResponsePageList.get(0)).isEqualTo(housekeepingPathResponse1);
assertThat(housekeepingPathResponsePageList.get(1)).isEqualTo(housekeepingPathResponse2);
assertThat(housekeepingPathResponsePage.getTotalElements()).isEqualTo(2L);
assertThat(housekeepingPathResponsePage.getTotalPages()).isEqualTo(1L);
assertThat(housekeepingPathResponsePage.getPageable()).isEqualTo((new PageImpl<>(housekeepingPathList).getPageable()));
}
}
andreeapad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.ZoneId;

import com.expediagroup.beekeeper.api.response.HousekeepingMetadataResponse;
import com.expediagroup.beekeeper.api.response.HousekeepingPathResponse;
import com.expediagroup.beekeeper.core.model.HousekeepingMetadata;
import com.expediagroup.beekeeper.core.model.HousekeepingPath;
import com.expediagroup.beekeeper.core.model.PeriodDuration;
Expand Down Expand Up @@ -88,4 +89,19 @@ public static HousekeepingPath generateDummyHousekeepingPath(String databaseName
.build();
}

public static HousekeepingPathResponse generateDummyHousekeepingPathResponse(HousekeepingPath housekeepingPath) {
return HousekeepingPathResponse
.builder()
.path("s3://some/path/")
.databaseName(housekeepingPath.getDatabaseName())
.tableName(housekeepingPath.getTableName())
.housekeepingStatus(SCHEDULED)
.creationTimestamp(CREATION_TIMESTAMP)
.modifiedTimestamp(CREATION_TIMESTAMP)
.cleanupTimestamp(housekeepingPath.getCleanupTimestamp())
.cleanupDelay(CLEANUP_DELAY_STRING)
.cleanupAttempts(0)
.lifecycleType(EXPIRED.toString())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,107 @@ public void testGetPathsWhenThereIsFiltering() throws SQLException, InterruptedE
Page<HousekeepingPathResponse> responsePage = mapper
.readValue(body, new TypeReference<RestResponsePage<HousekeepingPathResponse>>() {});
List<HousekeepingPathResponse> result = responsePage.getContent();

assertThat(responsePage.getTotalElements()).isEqualTo(1L);
assertThatPathsEqualsResponse(testPath1, result.get(0));
assertThat(result.size()).isEqualTo(1);
}

@Test
public void testPathsPageable() throws SQLException, InterruptedException, IOException {
// Test the total elements on different pages by setting the page size to 1.
int pageSize = 1;

// Create three new HousekeepingPath objects
HousekeepingPath testPath1 = createHousekeepingPath("some_table",
HamzaJugon marked this conversation as resolved.
Show resolved Hide resolved
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=A", LifecycleEventType.EXPIRED,
Duration.parse("P3D").toString());
HousekeepingPath testPath2 = createHousekeepingPath("some_table",
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=B", LifecycleEventType.UNREFERENCED,
Duration.parse("P3D").toString());
HousekeepingPath testPath3 = createHousekeepingPath("some_table",
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=D", LifecycleEventType.UNREFERENCED,
Duration.parse("P3D").toString());

// Set the housekeepingStatus and cleanupTimestamp properties
testPath1.setHousekeepingStatus(HousekeepingStatus.FAILED);
testPath2.setHousekeepingStatus(HousekeepingStatus.FAILED);
testPath3.setHousekeepingStatus(HousekeepingStatus.FAILED);
testPath1.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));
testPath2.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));
testPath3.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));
HamzaJugon marked this conversation as resolved.
Show resolved Hide resolved

// Insert the three objects into the database
insertUnreferencedPath(testPath1);
insertUnreferencedPath(testPath2);
insertUnreferencedPath(testPath3);

// Call the getUnreferencedPaths() method with the relevant filters
String filters = "?housekeeping_status=FAILED&page=1&size=" + pageSize; // Concat the pageSize set initially
HttpResponse<String> response = testClient.getUnreferencedPaths("some_database", "some_table", filters);

// Assert that the response contains the entries in the database
assertThat(response.statusCode()).isEqualTo(OK.value());
String body = response.body();
Page<HousekeepingPathResponse> responsePage = mapper
.readValue(body, new TypeReference<RestResponsePage<HousekeepingPathResponse>>() {});
List<HousekeepingPathResponse> result = responsePage.getContent();

// Assert that each page contains exactly one element
assertThat(result.size()).isEqualTo(1);
HamzaJugon marked this conversation as resolved.
Show resolved Hide resolved
// Assert that there are a total of three elements
assertThat(responsePage.getTotalElements()).isEqualTo(3L);
// Assert that there are a total of three pages.
assertThat(responsePage.getTotalPages()).isEqualTo(3L);
}

@Test
public void testMetadataPageable() throws SQLException, InterruptedException, IOException {
// Test the total elements on different pages by setting the page size to 1.
int pageSize = 1;

// Create three new HousekeepingMetadata objects
HousekeepingMetadata testMetadata1 = createHousekeepingMetadata("some_table",
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=A",
"event_date=2020-01-01/event_hour=0/event_type=A", LifecycleEventType.EXPIRED, "P3D");
HousekeepingMetadata testMetadata2 = createHousekeepingMetadata("some_table",
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=B",
"event_date=2020-01-01/event_hour=0/event_type=B", LifecycleEventType.UNREFERENCED, "P3D");
HousekeepingMetadata testMetadata3 = createHousekeepingMetadata("some_table",
"s3://some/path/event_date=2020-01-01/event_hour=0/event_type=C",
"event_date=2020-01-01/event_hour=0/event_type=C", LifecycleEventType.UNREFERENCED, "P3D");

// Set the housekeepingStatus and cleanupTimestamp properties
testMetadata1.setHousekeepingStatus(HousekeepingStatus.FAILED);
testMetadata2.setHousekeepingStatus(HousekeepingStatus.FAILED);
testMetadata3.setHousekeepingStatus(HousekeepingStatus.FAILED);
testMetadata1.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));
testMetadata2.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));
testMetadata3.setCleanupTimestamp(LocalDateTime.parse("1999-05-05T10:41:20"));

// Insert the three objects into the database
insertExpiredMetadata(testMetadata1);
insertExpiredMetadata(testMetadata2);
insertExpiredMetadata(testMetadata3);

// Call the getUnreferencedPaths() method with the relevant filters
String filters = "?housekeeping_status=FAILED&page=1&size=" + pageSize; // Concat the pageSize set initially
HttpResponse<String> response = testClient.getMetadata("some_database", "some_table", filters);

// Assert that the response contains the entries in the database
assertThat(response.statusCode()).isEqualTo(OK.value());
String body = response.body();
Page<HousekeepingMetadataResponse> responsePage = mapper
.readValue(body, new TypeReference<RestResponsePage<HousekeepingMetadataResponse>>() {});
List<HousekeepingMetadataResponse> result = responsePage.getContent();

// Assert that each page contains exactly one element
assertThat(result.size()).isEqualTo(1);
// Assert that there are a total of three elements
assertThat(responsePage.getTotalElements()).isEqualTo(3L);
// Assert that there are a total of three pages.
assertThat(responsePage.getTotalPages()).isEqualTo(3L);
}

// This test is to manually test the API
@Disabled
@Test
Expand Down
Loading