16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import java.util.ArrayList;
22 import java.util.Random;
23 import java.util.concurrent.CyclicBarrier;
27 LoggerFactory.getLogger(ForeignStorageConcurrencyTest.class);
29 public static void main(String[]
args)
throws Exception {
31 test.testConcurrency();
42 String userPassword)
throws Exception {
43 final int num_threads = 4;
44 ArrayList<Exception> exceptions =
new ArrayList<Exception>();
49 final CyclicBarrier barrier =
new CyclicBarrier(num_threads,
new Runnable() {
52 logger.info(
"Barrier acquired.");
54 "localhost", 6274, db, adminName, adminPassword);
56 dba.runSql(
"CREATE SERVER test_server "
57 +
"FOREIGN DATA WRAPPER delimited_file WITH (storage_type = 'LOCAL_FILE', "
58 +
"base_path = '" + System.getProperty(
"user.dir") +
"');");
60 dba.runSql(
"CREATE FOREIGN TABLE test_table "
61 +
"(b BOOLEAN, t TINYINT, s SMALLINT, i INTEGER, bi BIGINT, f FLOAT, "
62 +
"dc DECIMAL(10, 5), tm TIME, tp TIMESTAMP, d DATE, txt TEXT, "
63 +
"txt_2 TEXT ENCODING NONE) "
64 +
"SERVER test_server WITH "
65 +
"(file_path = '../Tests/FsiDataFiles/scalar_types.csv', "
66 +
"FRAGMENT_SIZE = 10);");
67 logger.info(
"Barrier released.");
68 }
catch (Exception e) {
69 logger.error(
"Barrier Caught Exception: " + e.getMessage(), e);
77 Thread[] threads =
new Thread[num_threads];
79 threads[0] =
new Thread(
new Runnable() {
83 logger.info(
"Starting thread[0]");
85 "localhost", 6274, db, userName, userPassword);
88 "ALTER FOREIGN TABLE test_table RENAME COLUMN t TO tint", user,
"0");
89 runSqlAsUser(
"SELECT * FROM test_table LIMIT 2", user,
"0");
90 runSqlAsUser(
"SELECT * FROM test_table WHERE txt = 'quoted text'", user,
"0");
92 logger.info(
"Finished thread[0]");
93 }
catch (Exception e) {
94 logger.error(
"Thread[0] Caught Exception: " + e.getMessage(), e);
101 threads[1] =
new Thread(
new Runnable() {
105 logger.info(
"Starting thread[1]");
107 "localhost", 6274, db, userName, userPassword);
109 runSqlAsUser(
"SELECT * FROM test_table LIMIT 2", user,
"1");
111 "ALTER FOREIGN TABLE test_table RENAME COLUMN s TO sint", user,
"1");
112 runSqlAsUser(
"SELECT * FROM test_table WHERE txt = 'quoted text'", user,
"1");
114 logger.info(
"Finished thread[1]");
115 }
catch (Exception e) {
116 logger.error(
"Thread[1] Caught Exception: " + e.getMessage(), e);
123 threads[2] =
new Thread(
new Runnable() {
127 logger.info(
"Starting thread[2]");
129 "localhost", 6274, db, userName, userPassword);
131 runSqlAsUser(
"SELECT * FROM test_table LIMIT 2", user,
"2");
132 runSqlAsUser(
"SELECT * FROM test_table WHERE txt = 'quoted text'", user,
"2");
134 "ALTER FOREIGN TABLE test_table RENAME COLUMN i TO iint", user,
"2");
136 logger.info(
"Finished thread[2]");
137 }
catch (Exception e) {
138 logger.error(
"Thread[0] Caught Exception: " + e.getMessage(), e);
145 threads[3] =
new Thread(
new Runnable() {
149 logger.info(
"Starting thread[3]");
151 "localhost", 6274, db, userName, userPassword);
153 runSqlAsUser(
"SELECT * FROM test_table LIMIT 2", user,
"3");
154 runSqlAsUser(
"SELECT * FROM test_table WHERE txt = 'quoted text'", user,
"3");
157 "ALTER FOREIGN TABLE test_table RENAME COLUMN b TO bint", user,
"3");
158 logger.info(
"Finished thread[3]");
159 }
catch (Exception e) {
160 logger.error(
"Thread[0] Caught Exception: " + e.getMessage(), e);
167 for (Thread t : threads) {
172 HeavyDBTestClient.getClient(
"localhost", 6274, db, adminName, adminPassword);
173 dba.runSql(
"DROP FOREIGN TABLE test_table;");
174 dba.runSql(
"DROP SERVER test_server;");
176 for (Exception e : exceptions) {
178 logger.error(
"Exception: " + e.getMessage(), e);
186 logger.info(logPrefix +
" " + sql);
192 logger.info(logPrefix +
" " + sql);
193 user.sqlValidate(sql);
197 logger.info(
"ForeignStorageConcurrencyTest()");
200 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
203 su.runSql(
"DROP DATABASE IF EXISTS db1;");
204 su.runSql(
"CREATE DATABASE db1;");
206 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
209 su.runSql(
"DROP DATABASE db1;");
211 logger.info(
"ForeignStorageConcurrencyTest() done");
void runTest(String db, String adminName, String adminPassword, String userName, String userPassword)
void runSqlValidateAsUser(String sql, HeavyDBTestClient user, String logPrefix)
void runSqlAsUser(String sql, HeavyDBTestClient user, String logPrefix)
static final Logger logger
static void main(String[] args)