Skip to content

Commit 6185bf8

Browse files
committed
Fix tests and use postgres instead of H2
1 parent 9d2543e commit 6185bf8

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/router/RoutingRulesManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.nio.channels.FileChannel;
2626
import java.nio.channels.FileLock;
2727
import java.nio.file.Files;
28-
import java.nio.file.Paths;
28+
import java.nio.file.Path;
2929
import java.nio.file.StandardOpenOption;
3030
import java.util.List;
3131

@@ -47,7 +47,7 @@ public List<RoutingRule> getRoutingRules()
4747
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
4848
ImmutableList.Builder<RoutingRule> routingRulesBuilder = ImmutableList.builder();
4949
try {
50-
String content = Files.readString(Paths.get(rulesConfigPath), UTF_8);
50+
String content = Files.readString(Path.of(rulesConfigPath), UTF_8);
5151
YAMLParser parser = new YAMLFactory().createParser(content);
5252
while (parser.nextToken() != null) {
5353
RoutingRule routingRule = yamlReader.readValue(parser, RoutingRule.class);
@@ -65,7 +65,7 @@ public synchronized List<RoutingRule> updateRoutingRule(RoutingRule routingRule)
6565
{
6666
ImmutableList.Builder<RoutingRule> updatedRoutingRulesBuilder = ImmutableList.builder();
6767
List<RoutingRule> currentRoutingRulesList = getRoutingRules();
68-
try (FileChannel fileChannel = FileChannel.open(Paths.get(rulesConfigPath), StandardOpenOption.WRITE, StandardOpenOption.READ);
68+
try (FileChannel fileChannel = FileChannel.open(Path.of(rulesConfigPath), StandardOpenOption.WRITE, StandardOpenOption.READ);
6969
FileLock lock = fileChannel.lock()) {
7070
ObjectMapper yamlWriter = new ObjectMapper(new YAMLFactory());
7171
StringBuilder yamlContent = new StringBuilder();
@@ -79,7 +79,7 @@ public synchronized List<RoutingRule> updateRoutingRule(RoutingRule routingRule)
7979
updatedRoutingRulesBuilder.add(rule);
8080
}
8181
}
82-
Files.writeString(Paths.get(rulesConfigPath), yamlContent.toString(), UTF_8);
82+
Files.writeString(Path.of(rulesConfigPath), yamlContent.toString(), UTF_8);
8383
lock.release();
8484
}
8585
catch (IOException e) {

gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingAPI.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import org.junit.jupiter.api.BeforeAll;
2929
import org.junit.jupiter.api.Test;
3030
import org.junit.jupiter.api.TestInstance;
31+
import org.testcontainers.containers.PostgreSQLContainer;
3132
import org.testcontainers.containers.TrinoContainer;
3233

34+
import java.io.File;
3335
import java.util.List;
3436

3537
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,6 +42,7 @@ final class TestRoutingAPI
4042
{
4143
private final OkHttpClient httpClient = new OkHttpClient();
4244
private TrinoContainer trino;
45+
private final PostgreSQLContainer postgresql = new PostgreSQLContainer("postgres:16");
4346
int routerPort = 21001 + (int) (Math.random() * 1000);
4447
int backendPort;
4548

@@ -53,11 +56,13 @@ void setup()
5356

5457
backendPort = trino.getMappedPort(8080);
5558

59+
postgresql.start();
60+
5661
// seed database
57-
HaGatewayTestUtils.TestConfig testConfig =
58-
HaGatewayTestUtils.buildGatewayConfigAndSeedDb(routerPort, "test-config-with-routing-rules-api.yml");
62+
File testConfigFile =
63+
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-with-routing-rules-api.yml");
5964
// Start Gateway
60-
String[] args = {testConfig.configFilePath()};
65+
String[] args = {testConfigFile.getAbsolutePath()};
6166
HaGatewayLauncher.main(args);
6267
// Now populate the backend
6368
HaGatewayTestUtils.setUpBackend(

gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingRulesManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void testGetRoutingRules()
4848
"airflow",
4949
"if query from airflow, route to etl group",
5050
null,
51-
List.of("result.put(\"routingGroup\", \"etl\")"),
51+
List.of("result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl\")"),
5252
"request.getHeader(\"X-Trino-Source\") == \"airflow\" && (request.getHeader(\"X-Trino-Client-Tags\") == null || request.getHeader(\"X-Trino-Client-Tags\").isEmpty())"));
5353
}
5454

gateway-ha/src/test/resources/test-config-with-routing-rules-api.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ serverConfig:
33
http-server.http.port: REQUEST_ROUTER_PORT
44

55
dataStore:
6-
jdbcUrl: jdbc:h2:DB_FILE_PATH
7-
user: sa
8-
password: sa
9-
driver: org.h2.Driver
10-
11-
modules:
12-
- io.trino.gateway.ha.module.HaGatewayProviderModule
13-
- io.trino.gateway.ha.module.ClusterStateListenerModule
14-
- io.trino.gateway.ha.module.ClusterStatsMonitorModule
15-
16-
managedApps:
17-
- io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor
6+
jdbcUrl: POSTGRESQL_JDBC_URL
7+
user: POSTGRESQL_USER
8+
password: POSTGRESQL_PASSWORD
9+
driver: org.postgresql.Driver
1810

1911
clusterStatsConfiguration:
2012
monitorType: INFO_API

0 commit comments

Comments
 (0)