|
4 | 4 | import static org.hypertrace.core.documentstore.model.config.AggregatePipelineMode.SORT_OPTIMIZED_IF_POSSIBLE; |
5 | 5 | import static org.hypertrace.core.documentstore.model.options.DataFreshness.NEAR_REALTIME_FRESHNESS; |
6 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
7 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
8 | 10 |
|
9 | 11 | import com.typesafe.config.Config; |
10 | 12 | import com.typesafe.config.ConfigFactory; |
11 | 13 | import java.time.Duration; |
12 | 14 | import java.util.List; |
13 | 15 | import java.util.Map; |
| 16 | +import org.hypertrace.core.documentstore.model.config.postgres.PostgresConnectionConfig; |
14 | 17 | import org.hypertrace.core.documentstore.model.options.DataFreshness; |
15 | 18 | import org.junit.jupiter.api.Test; |
16 | 19 | import org.junit.jupiter.params.ParameterizedTest; |
17 | 20 | import org.junit.jupiter.params.provider.EnumSource; |
18 | 21 |
|
19 | 22 | class TypesafeConfigDatastoreConfigExtractorTest { |
| 23 | + |
20 | 24 | private static final String TYPE_KEY = "database_type"; |
21 | 25 | private static final String HOST_KEY = "hostname"; |
22 | 26 | private static final String PORT_KEY = "port_number"; |
@@ -387,6 +391,21 @@ void testBuildPostgresWithCollectionConfigs() { |
387 | 391 | assertEquals(false, nonExistentConfig.isPresent()); |
388 | 392 | } |
389 | 393 |
|
| 394 | + @Test |
| 395 | + void testBuildPostgresWithCollectionConfigWithoutTimestampFields() { |
| 396 | + final ConnectionConfig config = |
| 397 | + TypesafeConfigDatastoreConfigExtractor.from( |
| 398 | + buildConfigMapWithCollectionConfigWithoutTimestampFields(), TYPE_KEY) |
| 399 | + .extract() |
| 400 | + .connectionConfig(); |
| 401 | + |
| 402 | + final PostgresConnectionConfig postgresConfig = (PostgresConnectionConfig) config; |
| 403 | + |
| 404 | + var collectionWithoutTs = postgresConfig.getCollectionConfig("collection_without_ts"); |
| 405 | + assertTrue(collectionWithoutTs.isPresent()); |
| 406 | + assertFalse(collectionWithoutTs.get().getTimestampFields().isPresent()); |
| 407 | + } |
| 408 | + |
390 | 409 | private Config buildConfigMap() { |
391 | 410 | return ConfigFactory.parseMap( |
392 | 411 | Map.ofEntries( |
@@ -516,4 +535,21 @@ private Config buildConfigMapWithCollectionConfigsForPostgres() { |
516 | 535 | "postgres.collectionConfigs.entities_domain.timestampFields.lastUpdated", |
517 | 536 | "update_ts"))); |
518 | 537 | } |
| 538 | + |
| 539 | + private Config buildConfigMapWithCollectionConfigWithoutTimestampFields() { |
| 540 | + return ConfigFactory.parseMap( |
| 541 | + Map.ofEntries( |
| 542 | + entry(TYPE_KEY, "postgres"), |
| 543 | + entry("postgres.host", host), |
| 544 | + entry("postgres.port", port), |
| 545 | + entry("postgres.database", database), |
| 546 | + entry("postgres.user", user), |
| 547 | + entry("postgres.password", password), |
| 548 | + entry("appName", appName), |
| 549 | + entry("maxPoolSize", maxConnections), |
| 550 | + entry("connectionAccessTimeout", accessTimeout), |
| 551 | + entry("connectionIdleTime", surrenderTimeout), |
| 552 | + // Collection config exists but has no timestampFields - uses a dummy key |
| 553 | + entry("postgres.collectionConfigs.collection_without_ts.someOtherConfig", "value"))); |
| 554 | + } |
519 | 555 | } |
0 commit comments