|
16 | 16 | * specific language governing permissions and limitations
|
17 | 17 | * under the License.
|
18 | 18 | */
|
19 |
| -package org.apache.polaris.commons; |
| 19 | +package org.apache.polaris.test.commons; |
20 | 20 |
|
21 | 21 | import io.quarkus.test.common.DevServicesContext;
|
22 | 22 | import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
|
@@ -60,41 +60,45 @@ public Map<String, String> start() {
|
60 | 60 |
|
61 | 61 | context.containerNetworkId().ifPresent(postgres::withNetworkMode);
|
62 | 62 | postgres.start();
|
63 |
| - Map<String, String> props = new HashMap<>(); |
64 |
| - props.put("polaris.persistence.type", "relational-jdbc"); |
65 | 63 |
|
66 |
| - if (!databases.isEmpty()) { |
67 |
| - for (String database : databases) { |
68 |
| - // polaris.relation.jdbc.datasource.realm=realm_ds |
69 |
| - props.put(String.format("polaris.relation.jdbc.datasource.%s", database), database + "_ds"); |
70 |
| - props.put(String.format("quarkus.datasource.%s.db-kind", database + "_ds"), "pgsql"); |
71 |
| - props.put(String.format("quarkus.datasource.%s.active", database + "_ds"), "true"); |
72 |
| - props.put( |
73 |
| - String.format("quarkus.datasource.%s.jdbc.url", database + "_ds"), |
74 |
| - postgres.getJdbcUrl().replace("realm1", database)); |
75 |
| - props.put( |
76 |
| - String.format("quarkus.datasource.%s.username", database + "_ds"), |
77 |
| - postgres.getUsername()); |
78 |
| - props.put( |
79 |
| - String.format("quarkus.datasource.%s.password", database + "_ds"), |
80 |
| - postgres.getPassword()); |
81 |
| - } |
| 64 | + if (databases.isEmpty()) { |
| 65 | + Map<String, String> props = generateDataSourceProps(List.of("realm1")); |
| 66 | + // make realm1_ds as the default ds |
| 67 | + props.put("polaris.relation.jdbc.datasource.default-datasource", "realm1_ds"); |
| 68 | + return props; |
82 | 69 | } else {
|
83 |
| - return Map.of( |
84 |
| - "polaris.persistence.type", |
85 |
| - "relational-jdbc", |
86 |
| - "quarkus.datasource.db-kind", |
87 |
| - "pgsql", |
88 |
| - "quarkus.datasource.jdbc.url", |
89 |
| - postgres.getJdbcUrl(), |
90 |
| - "quarkus.datasource.username", |
91 |
| - postgres.getUsername(), |
92 |
| - "quarkus.datasource.password", |
93 |
| - postgres.getPassword(), |
94 |
| - "quarkus.datasource.jdbc.initial-size", |
95 |
| - "10"); |
| 70 | + Map<String, String> allProps = new HashMap<>(); |
| 71 | + allProps.putAll(generateDataSourceMappingProps(databases)); |
| 72 | + allProps.putAll(generateDataSourceProps(databases)); |
| 73 | + return allProps; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private Map<String, String> generateDataSourceProps(List<String> dataSources) { |
| 78 | + Map<String, String> props = new HashMap<>(); |
| 79 | + props.put("polaris.persistence.type", "relational-jdbc"); |
| 80 | + for (String database : dataSources) { |
| 81 | + props.put(String.format("quarkus.datasource.%s.db-kind", database + "_ds"), "pgsql"); |
| 82 | + props.put(String.format("quarkus.datasource.%s.active", database + "_ds"), "true"); |
| 83 | + props.put( |
| 84 | + String.format("quarkus.datasource.%s.jdbc.url", database + "_ds"), |
| 85 | + postgres.getJdbcUrl().replace("realm1", database)); |
| 86 | + props.put( |
| 87 | + String.format("quarkus.datasource.%s.username", database + "_ds"), |
| 88 | + postgres.getUsername()); |
| 89 | + props.put( |
| 90 | + String.format("quarkus.datasource.%s.password", database + "_ds"), |
| 91 | + postgres.getPassword()); |
96 | 92 | }
|
| 93 | + return props; |
| 94 | + } |
97 | 95 |
|
| 96 | + private Map<String, String> generateDataSourceMappingProps(List<String> realms) { |
| 97 | + Map<String, String> props = new HashMap<>(); |
| 98 | + // polaris.relation.jdbc.datasource.realm=realm_ds |
| 99 | + for (String database : realms) { |
| 100 | + props.put(String.format("polaris.relation.jdbc.datasource.realm.%s", database), database + "_ds"); |
| 101 | + } |
98 | 102 | return props;
|
99 | 103 | }
|
100 | 104 |
|
|
0 commit comments