|
18 | 18 | import com.linkedin.openhouse.tables.client.model.GetDatabaseResponseBody;
|
19 | 19 | import com.linkedin.openhouse.tables.client.model.GetTableResponseBody;
|
20 | 20 | import com.linkedin.openhouse.tables.client.model.Policies;
|
| 21 | +import com.linkedin.openhouse.tables.client.model.Replication; |
| 22 | +import com.linkedin.openhouse.tables.client.model.ReplicationConfig; |
21 | 23 | import com.linkedin.openhouse.tables.client.model.Retention;
|
22 | 24 | import com.linkedin.openhouse.tables.client.model.RetentionColumnPattern;
|
23 | 25 | import com.linkedin.openhouse.tables.client.model.TimePartitionSpec;
|
@@ -415,6 +417,33 @@ void testNonPartitionedTableWithPatternGetRetentionConfig() {
|
415 | 417 | Mockito.verify(apiMock, Mockito.times(1)).getTableV1(testDbName, testTableNamePartitioned);
|
416 | 418 | }
|
417 | 419 |
|
| 420 | + @Test |
| 421 | + void testPrimaryTableWithReplicationConfig() { |
| 422 | + GetTableResponseBody primaryTableWithReplicationConfigResponseBodyMock = |
| 423 | + createPrimaryTableWithReplicationPolicyResponseBodyMock( |
| 424 | + testDbName, testTableName, "schedule", "interval", "cluster"); |
| 425 | + Mono<GetTableResponseBody> responseMock = (Mono<GetTableResponseBody>) Mockito.mock(Mono.class); |
| 426 | + Mockito.when(responseMock.block(any(Duration.class))) |
| 427 | + .thenReturn(primaryTableWithReplicationConfigResponseBodyMock); |
| 428 | + Mockito.when(apiMock.getTableV1(testDbName, testTableName)).thenReturn(responseMock); |
| 429 | + Optional<List<com.linkedin.openhouse.jobs.util.ReplicationConfig>> result = |
| 430 | + client.getTableReplication( |
| 431 | + TableMetadata.builder().dbName(testDbName).tableName(testTableName).build()); |
| 432 | + Assertions.assertTrue( |
| 433 | + result.isPresent(), "Retention config must be present for a test partitioned table"); |
| 434 | + List<com.linkedin.openhouse.jobs.util.ReplicationConfig> replicationConfigs = new ArrayList<>(); |
| 435 | + com.linkedin.openhouse.jobs.util.ReplicationConfig replicationConfig = |
| 436 | + com.linkedin.openhouse.jobs.util.ReplicationConfig.builder() |
| 437 | + .schedule("schedule") |
| 438 | + .cluster("cluster") |
| 439 | + .tableOwner("") |
| 440 | + .build(); |
| 441 | + replicationConfigs.add(replicationConfig); |
| 442 | + Assertions.assertEquals(replicationConfigs, result.orElse(null)); |
| 443 | + Mockito.verify(responseMock, Mockito.times(1)).block(any(Duration.class)); |
| 444 | + Mockito.verify(apiMock, Mockito.times(1)).getTableV1(testDbName, testTableName); |
| 445 | + } |
| 446 | + |
418 | 447 | @Test
|
419 | 448 | void getDatabases() {
|
420 | 449 | GetAllDatabasesResponseBody allDatabasesResponseBodyMock =
|
@@ -535,6 +564,24 @@ private GetTableResponseBody createNonPartitionedTableWithPatternResponseBodyMoc
|
535 | 564 | return setUpResponseBodyMock(dbName, tableName, null, policies);
|
536 | 565 | }
|
537 | 566 |
|
| 567 | + private GetTableResponseBody createPrimaryTableWithReplicationPolicyResponseBodyMock( |
| 568 | + String dbName, String tableName, String schedule, String interval, String cluster) { |
| 569 | + Policies policies = Mockito.mock(Policies.class); |
| 570 | + Replication replication = Mockito.mock(Replication.class); |
| 571 | + List<ReplicationConfig> replicationConfigs = new ArrayList<>(); |
| 572 | + ReplicationConfig replicationConfig = Mockito.mock(ReplicationConfig.class); |
| 573 | + replicationConfigs.add(replicationConfig); |
| 574 | + replication.setConfig(replicationConfigs); |
| 575 | + |
| 576 | + policies.setReplication(replication); |
| 577 | + Mockito.when(replication.getConfig()).thenReturn(replicationConfigs); |
| 578 | + Mockito.when(policies.getReplication()).thenReturn(replication); |
| 579 | + Mockito.when(replicationConfig.getCronSchedule()).thenReturn(schedule); |
| 580 | + Mockito.when(replicationConfig.getDestination()).thenReturn(cluster); |
| 581 | + Mockito.when(replicationConfig.getInterval()).thenReturn(interval); |
| 582 | + return setUpResponseBodyMock(dbName, tableName, null, policies); |
| 583 | + } |
| 584 | + |
538 | 585 | private GetTableResponseBody createPartitionedTableNullPoliciesResponseBodyMock(
|
539 | 586 | String dbName, String tableName, String partitionColummName) {
|
540 | 587 | TimePartitionSpec partitionSpec = Mockito.mock(TimePartitionSpec.class);
|
|
0 commit comments