16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 import java.lang.Integer;
23 import java.lang.String;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.concurrent.CyclicBarrier;
34 public static void main(String[]
args)
throws Exception {
39 test.testConcurrency();
55 return LoggerFactory.getLogger(DdlConcurrencyTest.class);
59 return "DdlConcurrencyTest";
64 logger.info(
"Initializing test threads...");
65 ArrayList<SqlCommandThread[]> tests =
new ArrayList<>();
66 tests.add(
makeTests(
"ShowTable",
"SHOW TABLES;"));
67 tests.add(
makeTests(
"ShowTableDetails",
"SHOW TABLE DETAILS;"));
68 tests.add(
makeTests(
"ShowCreateTable",
"SHOW CREATE TABLE test_table;"));
69 tests.add(
makeTests(
"ShowServers",
"SHOW SERVERS;"));
70 tests.add(
makeTests(
"ShowCreateServer",
"SHOW CREATE SERVER test_server;"));
71 tests.add(
makeTests(
"ShowFunctions",
"SHOW FUNCTIONS;"));
72 tests.add(
makeTests(
"ShowRuntimeFunctions",
"SHOW RUNTIME FUNCTIONS;"));
73 tests.add(
makeTests(
"ShowRuntimeTF",
"SHOW RUNTIME TABLE FUNCTIONS;"));
74 tests.add(
makeTests(
"AlterDatabase",
"ALTER DATABASE " +
db +
" OWNER TO admin;"));
75 tests.add(
makeTests(
"ShowUserDetails",
"SHOW USER DETAILS;"));
76 tests.add(
makeTests(
"ShowRoles",
"SHOW ROLES"));
77 tests.add(
makeTests(
"ReassignOwned",
"REASSIGN OWNED BY test_user TO admin;"));
79 "CREATE POLICY ON COLUMN test_table.i TO test_user VALUES (1);",
82 "DROP POLICY ON COLUMN test_table.i FROM test_user;",
84 tests.add(
makeTests(
"ShowPolicy",
"SHOW POLICIES test_user;"));
85 tests.add(
makeTests(
"ShowSupportedDataSources",
"SHOW POLICIES test_user;"));
87 "CreateTable",
"CREATE TABLE IF NOT EXISTS test_table_<threadId> (i int);"));
88 tests.add(
makeTests(
"DropTable",
"DROP TABLE IF EXISTS test_table_<threadId>;"));
89 tests.add(
makeTests(
"InsertTable",
"INSERT INTO test_table (i) VALUES (2);"));
90 tests.add(
makeTests(
"UpdateTable",
"UPDATE test_table SET i = 3 WHERE i = 2;"));
92 "ALTER TABLE test_table ADD (x int DEFAULT 1);",
95 "DropColumn",
"ALTER TABLE test_table DROP COLUMN x;",
"does not exist"));
97 "ALTER TABLE test_table_<threadId> RENAME TO altered_table_<threadId>;",
98 Arrays.asList(
"not exist",
"Attempted to overwrite")));
105 Arrays.asList(
"does not exist",
"exists"),
106 "DROP TABLE IF EXISTS restore_table_<threadId>;"));
107 tests.add(
makeTests(
"TruncateTable",
"TRUNCATE TABLE test_table;"));
108 tests.add(
makeTests(
"OptimizeTable",
"OPTIMIZE TABLE test_table;"));
110 makeTests(
"CopyFrom",
"COPY test_table FROM '../Tests/FsiDataFiles/1.csv';"));
112 "COPY (SELECT * FROM test_table) TO '" +
scratchDirPath +
"/copy.csv';",
115 "CREATE DATABASE IF NOT EXISTS test_db_<threadId>;",
116 Collections.emptyList(),
117 "DROP DATABASE IF EXISTS test_db_<threadId>;"));
118 tests.add(
makeTests(
"DropDB",
"DROP DATABASE IF EXISTS test_db_<threadId>;"));
120 "CREATE USER test_user_<threadId> (password = 'pass');",
122 "DROP USER IF EXISTS test_user_<threadId>;"));
123 tests.add(
makeTests(
"DropUser",
"DROP USER IF EXISTS test_user_<threadId>;"));
124 tests.add(
makeTests(
"AlterUser",
"ALTER USER test_user (password = 'pass');"));
126 "ALTER USER test_user_<threadId> RENAME TO altered_user_<threadId>;",
127 Arrays.asList(
"doesn't exist",
"already exists",
"does not exist"),
128 "DROP USER IF EXISTS altered_user_<threadId>;"));
130 "CREATE ROLE test_role_<threadId>;",
132 "DROP ROLE IF EXISTS test_role_<threadId>;"));
133 tests.add(
makeTests(
"DropRole",
"DROP ROLE IF EXISTS test_role_<threadId>;"));
135 "GrantRole",
"GRANT test_role_<threadId> TO test_user;",
"does not exist"));
137 "REVOKE test_role_<threadId> FROM test_user;",
138 Arrays.asList(
"does not exist",
"have not been granted")));
139 tests.add(
makeTests(
"ValidateSystem",
"Validate"));
141 "CREATE VIEW IF NOT EXISTS test_view_<threadId> AS (SELECT * FROM test_table);"));
142 tests.add(
makeTests(
"DropView",
"DROP VIEW IF EXISTS test_view_<threadId>;"));
145 "CREATE SERVER IF NOT EXISTS test_server_<threadId> FOREIGN DATA WRAPPER "
146 +
"delimited_file WITH (storage_type = 'LOCAL_FILE', base_path = '"
147 + System.getProperty(
"user.dir") +
"');"));
148 tests.add(
makeTests(
"DropServer",
"DROP SERVER IF EXISTS test_server_<threadId>;"));
150 "ALTER SERVER test_server SET (s3_bucket = 'diff_bucket');"));
151 tests.add(
makeTests(
"CreateForeignTable",
152 "CREATE FOREIGN TABLE IF NOT EXISTS test_foreign_table_<threadId> "
153 +
"(b BOOLEAN, t TINYINT, s SMALLINT, i INTEGER, bi BIGINT, f FLOAT, "
154 +
"dc DECIMAL(10, 5), tm TIME, tp TIMESTAMP, d DATE, txt TEXT, "
155 +
"txt_2 TEXT ENCODING NONE) "
156 +
"SERVER default_local_delimited WITH "
157 +
"(file_path = '../Tests/FsiDataFiles/scalar_types.csv', "
158 +
"FRAGMENT_SIZE = 10);"));
160 "DROP FOREIGN TABLE IF EXISTS test_foreign_table_<threadId>;"));
162 "CREATE USER MAPPING IF NOT EXISTS FOR PUBLIC SERVER test_server WITH "
163 +
"(S3_ACCESS_KEY = 'test_key', S3_SECRET_KEY = 'test_key');"));
165 "DROP USER MAPPING IF EXISTS FOR PUBLIC SERVER test_server;"));
167 "ALTER FOREIGN TABLE test_foreign_table SET (refresh_update_type = 'APPEND');"));
168 tests.add(
makeTests(
"ShowDiskCacheUsage",
"SHOW DISK CACHE USAGE;"));
169 tests.add(
makeTests(
"RefreshForeignTable",
170 "REFRESH FOREIGN TABLES test_foreign_table_<threadId>;",
173 logger.info(
"Initialized test threads.");
180 final List<String> queries,
int threadId) {
181 List<String> customQueries =
new ArrayList<String>();
182 for (String query : queries) {
183 customQueries.add(query.replaceAll(
"<threadId>", Integer.toString(threadId)));
185 return customQueries;
190 final List<String> queries,
191 final List<String> expectedExceptions,
192 final List<String> cleanUpQueries,
195 for (
int threadId = 0; threadId <
numThreads; ++threadId) {
199 threadName, customQueries, threadId, expectedExceptions, customCleanUps);
207 Arrays.asList(query),
208 Collections.emptyList(),
209 Collections.emptyList(),
215 final String threadName,
final String query,
final String exception) {
217 Arrays.asList(query),
218 Arrays.asList(exception),
219 Collections.emptyList(),
225 final String threadName,
final String query,
final List<String> exceptions) {
227 Arrays.asList(query),
229 Collections.emptyList(),
236 final List<String> exceptions,
237 final String cleanUpQueries) {
239 Arrays.asList(query),
241 Arrays.asList(cleanUpQueries),
248 final String exceptions,
249 final String cleanUpQueries) {
251 Arrays.asList(query),
252 Arrays.asList(exceptions),
253 Arrays.asList(cleanUpQueries),
259 logger.info(
"Starting Setup...");
262 runAndLog(heavyAdmin,
"DROP DATABASE IF EXISTS " +
db +
";");
263 runAndLog(heavyAdmin,
"CREATE DATABASE " +
db +
";");
265 runAndLog(dbAdmin,
"DROP USER IF EXISTS test_user");
266 runAndLog(dbAdmin,
"CREATE USER test_user (password = 'pass');");
267 runAndLog(dbAdmin,
"CREATE TABLE test_table (i int);");
270 "CREATE SERVER test_server FOREIGN DATA WRAPPER delimited_file "
271 +
"WITH (storage_type = 'AWS_S3', s3_bucket = 'test_bucket', "
272 +
"aws_region = 'test_region');");
274 "CREATE FOREIGN TABLE IF NOT EXISTS test_foreign_table"
275 +
" (b BOOLEAN, t TINYINT, s SMALLINT, i INTEGER, bi BIGINT, f FLOAT, "
276 +
"dc DECIMAL(10, 5), tm TIME, tp TIMESTAMP, d DATE, txt TEXT, "
277 +
"txt_2 TEXT ENCODING NONE) "
278 +
"SERVER default_local_delimited WITH "
279 +
"(file_path = '../Tests/FsiDataFiles/scalar_types.csv', "
280 +
"FRAGMENT_SIZE = 10);");
282 logger.info(
"Finished Setup.");
287 logger.info(
"Starting cleanup...");
289 runAndLog(heavyAdmin,
"DROP USER test_user;");
290 runAndLog(heavyAdmin,
"DROP DATABASE " +
db +
";");
294 for (String query : test.cleanUpQueries) {
300 logger.info(
"Finished cleanup.");
305 logger.info(
"starting runTests.");
310 numTests += threadGroup.length;
320 logger.info(
"Waiting for threads to sync...");
334 logger.info(
"Finished runTests.");
List< SqlCommandThread[]> createTestThreads()
static int getNumIterations()
final SqlCommandThread[] makeTests(final String threadName, final String query, final List< String > exceptions)
void runAndLog(HeavyDBTestClient client, String sql)
void cleanUpTests(final List< SqlCommandThread[]> tests)
void runTests(final List< SqlCommandThread[]> tests)
static String getConfig()
final SqlCommandThread[] makeTests(final String threadName, final String query, final String exception)
static boolean deleteDirectory(File dir)
final SqlCommandThread[] makeTests(final String threadName, final List< String > queries, final List< String > expectedExceptions, final List< String > cleanUpQueries, int numThreads)
static boolean enableMonitorThread
static Logger getLogger()
static void printErrors(ArrayList< String > exceptionTexts)
static boolean getEnableMonitorThread()
static boolean enableHeavyConnect
final SqlCommandThread[] makeTests(final String threadName, final String query)
static CyclicBarrier createBarrier(int numThreadsToWait)
final SqlCommandThread[] makeTests(final String threadName, final String query, final String exceptions, final String cleanUpQueries)
static int getNumThreads()
ArrayList< String > exceptionTexts
static String scratchDirPath
static List< String > customizeQueriesByThreadId(final List< String > queries, int threadId)
static String getTestName()
static void main(String[] args)
static boolean getEnableHeavyConnect()
static final String defaultDb
final SqlCommandThread[] makeTests(final String threadName, final String query, final List< String > exceptions, final String cleanUpQueries)
HeavyDBTestClient getAdminClient(String db)