forked from databricks/databricks-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeServiceConfigLoader.java
More file actions
93 lines (70 loc) · 3.01 KB
/
Copy pathFakeServiceConfigLoader.java
File metadata and controls
93 lines (70 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.databricks.jdbc.integration.fakeservice;
import com.databricks.jdbc.common.DatabricksJdbcConstants;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class FakeServiceConfigLoader {
public static final String DATABRICKS_HOST_PROP = "host.databricks";
public static final String CLOUD_FETCH_HOST_PROP = "host.cloudfetch";
public static final String PRESIGNED_URL_HOST = "host.presignedurl";
public static final String JWT_TOKEN_ENDPOINT_HOST_PROP = "host.jwt.token.endpoint";
public static final String TEST_CATALOG = "testcatalog";
public static final String TEST_SCHEMA = "testschema";
private static final DatabricksJdbcConstants.FakeServiceType fakeServiceType =
System.getenv("FAKE_SERVICE_TYPE") != null
? DatabricksJdbcConstants.FakeServiceType.valueOf(
System.getenv("FAKE_SERVICE_TYPE").toUpperCase())
: DatabricksJdbcConstants.FakeServiceType.SQL_EXEC;
private static final String SQL_EXEC_FAKE_SERVICE_TEST_PROPS =
"sqlexecfakeservicetest.properties";
private static final String SQL_GATEWAY_FAKE_SERVICE_TEST_PROPS =
"sqlgatewayfakeservicetest.properties";
private static final String FAKE_SERVICE_USER_AGENT = "DatabricksJdbcDriverOss-FakeService";
private static final String THRIFT_SERVER_FAKE_SERVICE_TEST_PROPS =
"thriftserverfakeservicetest.properties";
private static final Properties properties = new Properties();
static {
final String propsFileName = getPropsFileName();
try (InputStream input =
FakeServiceConfigLoader.class.getClassLoader().getResourceAsStream(propsFileName)) {
properties.load(input);
} catch (IOException e) {
throw new RuntimeException("Failed to load properties file: " + propsFileName, e);
}
}
public static DatabricksJdbcConstants.FakeServiceType getCloudFetchFakeServiceType() {
switch (fakeServiceType) {
case THRIFT_SERVER:
return DatabricksJdbcConstants.FakeServiceType.CLOUD_FETCH_THRIFT_SERVER;
case SQL_GATEWAY:
return DatabricksJdbcConstants.FakeServiceType.CLOUD_FETCH_SQL_GATEWAY;
default:
return DatabricksJdbcConstants.FakeServiceType.CLOUD_FETCH;
}
}
public static DatabricksJdbcConstants.FakeServiceType getFakeServiceType() {
return fakeServiceType;
}
public static String getProperty(String key) {
return properties.getProperty(key);
}
public static Properties getProperties() {
return properties;
}
public static String getFakeServiceUserAgent() {
return FAKE_SERVICE_USER_AGENT;
}
public static boolean shouldUseThriftClient() {
return !fakeServiceType.equals(DatabricksJdbcConstants.FakeServiceType.SQL_EXEC);
}
private static String getPropsFileName() {
switch (fakeServiceType) {
case THRIFT_SERVER:
return THRIFT_SERVER_FAKE_SERVICE_TEST_PROPS;
case SQL_GATEWAY:
return SQL_GATEWAY_FAKE_SERVICE_TEST_PROPS;
default:
return SQL_EXEC_FAKE_SERVICE_TEST_PROPS;
}
}
}