-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always enforce a ttl on snapshot expiration jobs even if unconfigured (…
…#281) ## Summary <!--- HINT: Replace #nnn with corresponding Issue number, if you are fixing an existing issue --> [Issue](https://github.com/linkedin/openhouse/issues/#nnn)] Briefly discuss the summary of the changes made in this pull request in 2-3 lines. Currently it is possible to define tables with an version count, and the snapshot expiration job will respect the version count instead of enforcing a TTL. With this change the snapshot expiration job will **always** enforce a TTL, defaulted currently to 3 days. This cannot be overridden by users unless they explicitly define a TTL that is greater than 3 days (but is currently the maximum is 3 days due to the history configuration validator) https://github.com/linkedin/openhouse/blob/7f66a730ec7d611335917e29bfed01050090c397/services/tables/src/main/java/com/linkedin/openhouse/tables/api/validator/impl/HistoryPolicySpecValidator.java#L57 Also fix some bugs where `TableSnapshotExpirationTask` is not sending properties correctly from the JobScheduler ## Changes - [ ] Client-facing API Changes - [ ] Internal API Changes - [ ] Bug Fixes - [ ] New Features - [ ] Performance Improvements - [ ] Code Style - [ ] Refactoring - [ ] Documentation - [ ] Tests For all the boxes checked, please include additional details of the changes made in this pull request. ## Testing Done <!--- Check any relevant boxes with "x" --> - [ ] Manually Tested on local docker setup. Please include commands ran, and their output. - [ ] Added new tests for the changes made. - [x] Updated existing tests to reflect the changes made. - [ ] No tests added or updated. Please explain why. If unsure, please feel free to ask for help. - [ ] Some other form of testing like staging or soak time in production. Please explain. Tested E2E with acceptance tests from local For all the boxes checked, include a detailed description of the testing done for the changes made in this pull request. # Additional Information - [ ] Breaking Changes - [ ] Deprecations - [ ] Large PR broken into smaller PRs, and PR plan linked in the description. For all the boxes checked, include additional details of the changes made in this pull request.
- Loading branch information
Showing
6 changed files
with
141 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...src/test/java/com/linkedin/openhouse/jobs/scheduler/tasks/SnapshotExpirationTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.linkedin.openhouse.jobs.scheduler.tasks; | ||
|
||
import com.linkedin.openhouse.jobs.client.JobsClient; | ||
import com.linkedin.openhouse.jobs.client.TablesClient; | ||
import com.linkedin.openhouse.jobs.util.HistoryConfig; | ||
import com.linkedin.openhouse.jobs.util.TableMetadata; | ||
import com.linkedin.openhouse.tables.client.model.History; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class SnapshotExpirationTaskTest { | ||
private TablesClient tablesClient; | ||
private JobsClient jobsClient; | ||
private TableMetadata tableMetadata; | ||
|
||
@BeforeEach | ||
void setup() { | ||
tablesClient = Mockito.mock(TablesClient.class); | ||
jobsClient = Mockito.mock(JobsClient.class); | ||
tableMetadata = Mockito.mock(TableMetadata.class); | ||
Mockito.when(tableMetadata.fqtn()).thenReturn("db.table"); | ||
} | ||
|
||
@Test | ||
void testSnapshotExpirationForTableWithoutConfig() { | ||
TableSnapshotsExpirationTask tableRetentionTask = | ||
new TableSnapshotsExpirationTask(jobsClient, tablesClient, tableMetadata); | ||
|
||
List<String> expectedArgs = | ||
Stream.of("--tableName", tableMetadata.fqtn()).collect(Collectors.toList()); | ||
Assertions.assertEquals(expectedArgs, tableRetentionTask.getArgs()); | ||
} | ||
|
||
@Test | ||
void testSnapshotExpirationJobWithOnlyMaxAgeConfig() { | ||
TableSnapshotsExpirationTask tableRetentionTask = | ||
new TableSnapshotsExpirationTask(jobsClient, tablesClient, tableMetadata); | ||
|
||
HistoryConfig historyConfigMock = Mockito.mock(HistoryConfig.class); | ||
int maxAge = 1; | ||
History.GranularityEnum granularity = History.GranularityEnum.DAY; | ||
|
||
Mockito.when(tableMetadata.getHistoryConfig()).thenReturn(historyConfigMock); | ||
Mockito.when(historyConfigMock.getMaxAge()).thenReturn(maxAge); | ||
Mockito.when(historyConfigMock.getGranularity()).thenReturn(granularity); | ||
List<String> expectedArgs = | ||
Stream.of( | ||
"--tableName", | ||
tableMetadata.fqtn(), | ||
"--maxAge", | ||
String.valueOf(maxAge), | ||
"--granularity", | ||
granularity.getValue()) | ||
.collect(Collectors.toList()); | ||
Assertions.assertEquals(expectedArgs, tableRetentionTask.getArgs()); | ||
} | ||
|
||
@Test | ||
void testSnapshotExpirationJobWithOnlyVersionsConfig() { | ||
TableSnapshotsExpirationTask tableRetentionTask = | ||
new TableSnapshotsExpirationTask(jobsClient, tablesClient, tableMetadata); | ||
|
||
HistoryConfig historyConfigMock = Mockito.mock(HistoryConfig.class); | ||
int versions = 3; | ||
|
||
Mockito.when(tableMetadata.getHistoryConfig()).thenReturn(historyConfigMock); | ||
Mockito.when(historyConfigMock.getVersions()).thenReturn(versions); | ||
List<String> expectedArgs = | ||
Stream.of("--tableName", tableMetadata.fqtn(), "--versions", String.valueOf(versions)) | ||
.collect(Collectors.toList()); | ||
Assertions.assertEquals(expectedArgs, tableRetentionTask.getArgs()); | ||
} | ||
|
||
@Test | ||
void testSnapshotExpirationJobWithMaxAgeAndVersions() { | ||
TableSnapshotsExpirationTask tableRetentionTask = | ||
new TableSnapshotsExpirationTask(jobsClient, tablesClient, tableMetadata); | ||
|
||
HistoryConfig historyConfigMock = Mockito.mock(HistoryConfig.class); | ||
int maxAge = 3; | ||
History.GranularityEnum granularity = History.GranularityEnum.DAY; | ||
int versions = 3; | ||
|
||
Mockito.when(tableMetadata.getHistoryConfig()).thenReturn(historyConfigMock); | ||
Mockito.when(historyConfigMock.getMaxAge()).thenReturn(maxAge); | ||
Mockito.when(historyConfigMock.getGranularity()).thenReturn(granularity); | ||
Mockito.when(historyConfigMock.getVersions()).thenReturn(versions); | ||
|
||
List<String> expectedArgs = | ||
Stream.of( | ||
"--tableName", | ||
tableMetadata.fqtn(), | ||
"--maxAge", | ||
String.valueOf(maxAge), | ||
"--granularity", | ||
granularity.getValue(), | ||
"--versions", | ||
String.valueOf(versions)) | ||
.collect(Collectors.toList()); | ||
Assertions.assertEquals(expectedArgs, tableRetentionTask.getArgs()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters