Skip to content

Commit 38bee26

Browse files
committed
Update changes
1 parent 43b40e8 commit 38bee26

File tree

4 files changed

+359
-33
lines changed

4 files changed

+359
-33
lines changed

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/ContainerQueryRunner.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import java.io.IOException;
3939
import java.sql.Connection;
40-
import java.sql.DriverManager;
4140
import java.sql.ResultSet;
4241
import java.sql.SQLException;
4342
import java.sql.Statement;
@@ -51,6 +50,7 @@
5150
import java.util.logging.Logger;
5251

5352
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
53+
import static java.sql.DriverManager.getConnection;
5454

5555
public class ContainerQueryRunner
5656
implements QueryRunner
@@ -62,32 +62,31 @@ public class ContainerQueryRunner
6262
private static final String CLUSTER_SHUTDOWN_TIMEOUT = System.getProperty("clusterShutDownTimeout", "10");
6363
private static final String BASE_DIR = System.getProperty("user.dir");
6464
private static final int DEFAULT_COORDINATOR_PORT = 8080;
65-
private static final int DEFAULT_FUNCTION_SERVER_PORT = 1122;
6665
private static final String TPCH_CATALOG = "tpch";
6766
private static final String TINY_SCHEMA = "tiny";
6867
private static final int DEFAULT_NUMBER_OF_WORKERS = 4;
6968
private static final Logger logger = Logger.getLogger(ContainerQueryRunner.class.getName());
7069
private final GenericContainer<?> coordinator;
7170
private final List<GenericContainer<?>> workers = new ArrayList<>();
7271
private final int coordinatorPort;
73-
private final int functionServerPort;
7472
private final String catalog;
7573
private final String schema;
76-
private Statement statement;
74+
private final int numberOfWorkers;
75+
private Connection connection;
7776

7877
public ContainerQueryRunner()
7978
throws InterruptedException, IOException
8079
{
81-
this(DEFAULT_COORDINATOR_PORT, DEFAULT_FUNCTION_SERVER_PORT, TPCH_CATALOG, TINY_SCHEMA, DEFAULT_NUMBER_OF_WORKERS);
80+
this(DEFAULT_COORDINATOR_PORT, TPCH_CATALOG, TINY_SCHEMA, DEFAULT_NUMBER_OF_WORKERS);
8281
}
8382

84-
public ContainerQueryRunner(int coordinatorPort, int functionServerPort, String catalog, String schema, int numberOfWorkers)
83+
public ContainerQueryRunner(int coordinatorPort, String catalog, String schema, int numberOfWorkers)
8584
throws InterruptedException, IOException
8685
{
8786
this.coordinatorPort = coordinatorPort;
88-
this.functionServerPort = functionServerPort;
8987
this.catalog = catalog;
9088
this.schema = schema;
89+
this.numberOfWorkers = numberOfWorkers;
9190

9291
// The container details can be added as properties in VM options for testing in IntelliJ.
9392
coordinator = createCoordinator();
@@ -109,9 +108,7 @@ public ContainerQueryRunner(int coordinatorPort, int functionServerPort, String
109108
"timeZoneId=UTC");
110109

111110
try {
112-
Connection connection = DriverManager.getConnection(url, "test", null);
113-
statement = connection.createStatement();
114-
statement.execute("set session remote_functions_enabled=true");
111+
connection = getConnection(url, "test", null);
115112
}
116113
catch (SQLException e) {
117114
throw new RuntimeException(e);
@@ -133,14 +130,11 @@ private GenericContainer<?> createCoordinator()
133130
ContainerQueryRunnerUtils.createCoordinatorLogProperties();
134131
ContainerQueryRunnerUtils.createCoordinatorNodeProperties();
135132
ContainerQueryRunnerUtils.createCoordinatorEntryPointScript();
136-
ContainerQueryRunnerUtils.createFunctionNamespaceRemoteProperties(functionServerPort);
137-
ContainerQueryRunnerUtils.createFunctionServerConfigProperties(functionServerPort);
138133

139134
return new GenericContainer<>(PRESTO_COORDINATOR_IMAGE)
140135
.withExposedPorts(coordinatorPort)
141136
.withNetwork(network).withNetworkAliases("presto-coordinator")
142137
.withFileSystemBind(BASE_DIR + "/testcontainers/coordinator/etc", "/opt/presto-server/etc", BindMode.READ_WRITE)
143-
.withFileSystemBind(BASE_DIR + "/testcontainers/coordinator/etc/function-server", "/opt/function-server/etc", BindMode.READ_ONLY)
144138
.withFileSystemBind(BASE_DIR + "/testcontainers/coordinator/entrypoint.sh", "/opt/entrypoint.sh", BindMode.READ_ONLY)
145139
.waitingFor(Wait.forLogMessage(".*======== SERVER STARTED ========.*", 1))
146140
.withStartupTimeout(Duration.ofSeconds(Long.parseLong(CONTAINER_TIMEOUT)));
@@ -149,7 +143,7 @@ private GenericContainer<?> createCoordinator()
149143
private GenericContainer<?> createNativeWorker(int port, String nodeId)
150144
throws IOException
151145
{
152-
ContainerQueryRunnerUtils.createNativeWorkerConfigProperties(coordinatorPort, functionServerPort, nodeId);
146+
ContainerQueryRunnerUtils.createNativeWorkerConfigProperties(coordinatorPort, nodeId);
153147
ContainerQueryRunnerUtils.createNativeWorkerTpchProperties(nodeId);
154148
ContainerQueryRunnerUtils.createNativeWorkerEntryPointScript(nodeId);
155149
ContainerQueryRunnerUtils.createNativeWorkerNodeProperties(nodeId);
@@ -302,12 +296,12 @@ public Session getDefaultSession()
302296
public MaterializedResult execute(Session session, String sql)
303297
{
304298
try {
299+
Statement statement = connection.createStatement();
305300
ResultSet resultSet = statement.executeQuery(sql);
306-
return ContainerQueryRunnerUtils
307-
.toMaterializedResult(resultSet);
301+
return ContainerQueryRunnerUtils.toMaterializedResult(resultSet);
308302
}
309303
catch (SQLException e) {
310-
throw new RuntimeException(e);
304+
throw new RuntimeException("Error executing query: " + sql, e);
311305
}
312306
}
313307
}

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/ContainerQueryRunnerUtils.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,19 @@ public static void createNativeWorkerTpchProperties(String nodeId)
7171
createPropertiesFile("testcontainers/" + nodeId + "/etc/catalog/tpch.properties", properties);
7272
}
7373

74-
public static void createNativeWorkerConfigProperties(int coordinatorPort, int functionServerPort, String nodeId)
74+
public static void createNativeWorkerConfigProperties(int coordinatorPort, String nodeId)
75+
throws IOException
76+
{
77+
Properties properties = new Properties();
78+
properties.setProperty("presto.version", "testversion");
79+
properties.setProperty("http-server.http.port", "7777");
80+
properties.setProperty("discovery.uri", "http://presto-coordinator:" + coordinatorPort);
81+
properties.setProperty("system-memory-gb", "2");
82+
properties.setProperty("native.sidecar", "false");
83+
createPropertiesFile("testcontainers/" + nodeId + "/etc/config.properties", properties);
84+
}
85+
86+
public static void createNativeWorkerConfigPropertiesWithFunctionServer(int coordinatorPort, int functionServerPort, String nodeId)
7587
throws IOException
7688
{
7789
Properties properties = new Properties();
@@ -106,7 +118,24 @@ public static void createCoordinatorConfigProperties(int port)
106118
createPropertiesFile("testcontainers/coordinator/etc/config.properties", properties);
107119
}
108120

109-
public static void createFunctionNamespaceRemoteProperties(int functionServerPort)
121+
public static void createFunctionNamespaceRemoteProperties()
122+
throws IOException
123+
{
124+
Properties properties = new Properties();
125+
properties.setProperty("function-namespace-manager.name", "rest");
126+
properties.setProperty("supported-function-languages", "Java");
127+
properties.setProperty("function-implementation-type", "REST");
128+
129+
String directoryPath = "testcontainers/function-namespace";
130+
File directory = new File(directoryPath);
131+
if (!directory.exists()) {
132+
directory.mkdirs();
133+
}
134+
135+
createPropertiesFile("testcontainers/coordinator/etc/function-namespace/remote.properties", properties);
136+
}
137+
138+
public static void createFunctionNamespaceRemotePropertiesWithFunctionServer(int functionServerPort)
110139
throws IOException
111140
{
112141
Properties properties = new Properties();
@@ -241,10 +270,6 @@ public static void createPropertiesFile(String filePath, Properties properties)
241270
parentDir.mkdirs();
242271
}
243272

244-
if (file.exists()) {
245-
throw new IOException("File exists: " + filePath);
246-
}
247-
248273
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
249274
for (String key : properties.stringPropertyNames()) {
250275
writer.write(key + "=" + properties.getProperty(key) + "\n");
@@ -261,10 +286,6 @@ public static void createScriptFile(String filePath, String scriptContent)
261286
parentDir.mkdirs();
262287
}
263288

264-
if (file.exists()) {
265-
throw new IOException("File exists: " + filePath);
266-
}
267-
268289
try (OutputStream output = new FileOutputStream(file);
269290
OutputStreamWriter writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
270291
writer.write(scriptContent);

0 commit comments

Comments
 (0)