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.");
53 HeavyDBTestClient dba = HeavyDBTestClient.getClient(
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]");
84 HeavyDBTestClient user = HeavyDBTestClient.getClient(
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]");
106 HeavyDBTestClient user = HeavyDBTestClient.getClient(
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]");
128 HeavyDBTestClient user = HeavyDBTestClient.getClient(
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]");
150 HeavyDBTestClient user = HeavyDBTestClient.getClient(
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) {
171 HeavyDBTestClient dba =
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);
void runSqlValidateAsUser(String sql, HeavyDBTestClient user, String logPrefix)
void runSqlAsUser(String sql, HeavyDBTestClient user, String logPrefix)