Skip to content

Commit f9653b2

Browse files
authored
test: Add E2E unit tests for CLP connector. (#54)
1 parent 5e7b648 commit f9653b2

File tree

11 files changed

+823
-0
lines changed

11 files changed

+823
-0
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,19 @@
24202420
<version>2.1.0-3</version>
24212421
</dependency>
24222422

2423+
<dependency>
2424+
<groupId>com.facebook.presto</groupId>
2425+
<artifactId>presto-clp</artifactId>
2426+
<version>${project.version}</version>
2427+
</dependency>
2428+
2429+
<dependency>
2430+
<groupId>com.facebook.presto</groupId>
2431+
<artifactId>presto-clp</artifactId>
2432+
<version>${project.version}</version>
2433+
<type>test-jar</type>
2434+
</dependency>
2435+
24232436
<!-- force newer version to be used for dependencies -->
24242437
<dependency>
24252438
<groupId>org.javassist</groupId>

presto-clp/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
<scope>test</scope>
130130
</dependency>
131131

132+
<dependency>
133+
<groupId>com.facebook.presto</groupId>
134+
<artifactId>presto-tests</artifactId>
135+
<scope>test</scope>
136+
</dependency>
137+
132138
<dependency>
133139
<groupId>org.apache.commons</groupId>
134140
<artifactId>commons-math3</artifactId>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.plugin.clp;
15+
16+
import com.facebook.airlift.log.Logger;
17+
import com.facebook.presto.Session;
18+
import com.facebook.presto.tests.DistributedQueryRunner;
19+
import com.google.common.collect.ImmutableMap;
20+
21+
import java.net.URI;
22+
import java.util.Map;
23+
import java.util.Optional;
24+
import java.util.function.BiFunction;
25+
26+
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
27+
28+
public class ClpQueryRunner
29+
{
30+
private static final Logger log = Logger.get(ClpQueryRunner.class);
31+
32+
public static final String CLP_CATALOG = "clp";
33+
public static final String CLP_CONNECTOR = CLP_CATALOG;
34+
public static final int DEFAULT_NUM_OF_WORKERS = 1;
35+
public static final String DEFAULT_SCHEMA = "default";
36+
37+
public static DistributedQueryRunner createQueryRunner(
38+
String metadataDbUrl,
39+
String metadataDbUser,
40+
String metadataDbPassword,
41+
String metadataDbTablePrefix,
42+
Optional<Integer> workerCount,
43+
Optional<BiFunction<Integer, URI, Process>> externalWorkerLauncher)
44+
throws Exception
45+
{
46+
log.info("Creating CLP query runner with default session");
47+
return createQueryRunner(
48+
createDefaultSession(),
49+
metadataDbUrl,
50+
metadataDbUser,
51+
metadataDbPassword,
52+
metadataDbTablePrefix,
53+
workerCount,
54+
externalWorkerLauncher);
55+
}
56+
57+
public static DistributedQueryRunner createQueryRunner(
58+
Session session,
59+
String metadataDbUrl,
60+
String metadataDbUser,
61+
String metadataDbPassword,
62+
String metadataDbTablePrefix,
63+
Optional<Integer> workerCount,
64+
Optional<BiFunction<Integer, URI, Process>> externalWorkerLauncher)
65+
throws Exception
66+
{
67+
DistributedQueryRunner clpQueryRunner = DistributedQueryRunner.builder(session)
68+
.setNodeCount(workerCount.orElse(DEFAULT_NUM_OF_WORKERS))
69+
.setExternalWorkerLauncher(externalWorkerLauncher)
70+
.build();
71+
Map<String, String> clpProperties = ImmutableMap.<String, String>builder()
72+
.put("clp.metadata-provider-type", "mysql")
73+
.put("clp.metadata-db-url", metadataDbUrl)
74+
.put("clp.metadata-db-user", metadataDbUser)
75+
.put("clp.metadata-db-password", metadataDbPassword)
76+
.put("clp.metadata-table-prefix", metadataDbTablePrefix)
77+
.put("clp.split-provider-type", "mysql")
78+
.build();
79+
80+
clpQueryRunner.installPlugin(new ClpPlugin());
81+
clpQueryRunner.createCatalog(CLP_CATALOG, CLP_CONNECTOR, clpProperties);
82+
return clpQueryRunner;
83+
}
84+
85+
/**
86+
* Creates a default mock session for query use.
87+
*
88+
* @return a default session
89+
*/
90+
private static Session createDefaultSession()
91+
{
92+
return testSessionBuilder()
93+
.setCatalog(CLP_CATALOG)
94+
.setSchema(DEFAULT_SCHEMA)
95+
.build();
96+
}
97+
98+
private ClpQueryRunner()
99+
{
100+
}
101+
}

0 commit comments

Comments
 (0)