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(AlterDropTruncateValidateConcurrencyTest.class);
50 public static void main(String[]
args)
throws Exception {
53 test.testConcurrency();
57 String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
61 final int num_rows = 1000;
62 final int fragment_size = 10;
63 final String tableName =
"test";
64 Exception exceptions[] =
new Exception[num_threads];
66 final CyclicBarrier barrier =
new CyclicBarrier(num_threads,
new Runnable() {
70 "localhost", 6274, db, dbaUser, dbaPassword);
71 dba.runSql(
"CREATE TABLE " + tableName
72 +
"(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
73 + fragment_size +
")");
75 for (
int i = 0; i < num_rows; i++) {
76 final String integer_val = Integer.toString(i);
77 final String small_val = Integer.toString(i % 128);
78 final String fp_val = Double.toString(i * 1.1);
79 final String deci_val = Double.toString(i + 0.01);
80 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
81 final String values_string = String.join(
" , ",
90 dba.runSql(
"INSERT INTO " + tableName +
" VALUES "
91 +
"(" + values_string +
")");
93 }
catch (Exception e) {
94 logger.error(
"[" + Thread.currentThread().getId() +
"]"
95 +
" Caught Exception: " + e.getMessage(),
102 ArrayList<Thread> threads =
new ArrayList<>();
103 for (
int i = 0; i < num_threads; i++) {
104 logger.info(
"Starting " + i);
105 final int threadId = i;
107 Thread t =
new Thread(
new Runnable() {
110 long tid = Thread.currentThread().getId();
111 String logPrefix =
"[" + tid +
"]";
118 "localhost", 6274, db, dbUser, dbPassword);
120 Random rand =
new Random(tid);
123 sql =
"ALTER TABLE " + tableName +
" ADD COLUMN zz TEXT ENCODING DICT(8);";
124 logger.info(logPrefix +
" " + sql);
130 sql =
"SELECT * FROM " + tableName +
" LIMIT 2;";
131 logger.info(logPrefix +
" " + sql);
134 sql =
"DELETE FROM " + tableName +
" WHERE y = " + rand.nextInt(num_rows)
136 logger.info(logPrefix +
" " + sql);
140 sql =
"ALTER TABLE " + tableName +
" DROP COLUMN x;";
141 logger.info(logPrefix +
" " + sql);
145 sql =
"SELECT * FROM " + tableName +
" WHERE str = '"
146 +
text_values[rand.nextInt(text_values.length)] +
"';";
147 logger.info(logPrefix +
" " + sql);
150 sql =
"SELECT COUNT(*) FROM " + tableName +
";";
151 logger.info(logPrefix +
" VALIDATE " + sql);
152 user.sqlValidate(sql);
154 sql =
"TRUNCATE TABLE " + tableName +
";";
155 logger.info(logPrefix +
" " + sql);
158 }
catch (Exception e) {
159 logger.error(logPrefix +
" Caught Exception: " + e.getMessage(), e);
160 exceptions[threadId] = e;
168 for (Thread t : threads) {
173 HeavyDBTestClient.getClient(
"localhost", 6274, db, dbaUser, dbaPassword);
174 dba.runSql(
"DROP TABLE " + tableName +
";");
176 for (Exception e : exceptions) {
178 logger.error(
"Exception: " + e.getMessage(), e);
185 logger.info(
"AlterDropTruncateValidateConcurrencyTest()");
188 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
190 su.runSql(
"DROP USER dba");
191 }
catch (Exception e) {
194 su.runSql(
"DROP USER bob");
195 }
catch (Exception e) {
197 su.runSql(
"DROP DATABASE IF EXISTS db1");
199 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
200 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
202 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
204 su.runSql(
"CREATE DATABASE db1;");
205 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
206 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
207 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
208 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
210 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
213 su.runSql(
"DROP DATABASE db1;");
214 su.runSql(
"DROP USER bob;");
215 su.runSql(
"DROP USER dba;");
217 logger.info(
"AlterDropTruncateValidateConcurrencyTest() done");
static final String[] text_values
static final Logger logger
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
static void main(String[] args)