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;
26 LoggerFactory.getLogger(SelectUpdateDeleteDifferentTables.class);
49 public static void main(String[]
args)
throws Exception {
51 test.testConcurrency();
55 String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
59 final int num_rows = 400;
60 final int fragment_size = 25;
61 Exception exceptions[] =
new Exception[num_threads];
63 ArrayList<Thread> threads =
new ArrayList<>();
64 for (
int i = 0; i < num_threads; i++) {
65 logger.info(
"Starting " + i);
66 final int threadId = i;
68 Thread t =
new Thread(
new Runnable() {
71 long tid = Thread.currentThread().getId();
72 String logPrefix =
"[" + tid +
"]";
75 for (
int runId = 0; runId < runs; runId++) {
76 final String tableName = dbaUser +
"_" + threadId +
"_" + runId;
80 "localhost", 6274, db, dbUser, dbPassword);
82 user.runSql(
"CREATE TABLE " + tableName
83 +
"(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
84 + fragment_size +
")");
86 for (
int i = 0; i < num_rows; i++) {
87 final String integer_val = Integer.toString(i);
88 final String small_val = Integer.toString(i % 128);
89 final String fp_val = Double.toString(i * 1.1);
90 final String deci_val = Double.toString(i + 0.01);
91 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
92 final String values_string = String.join(
" , ",
101 user.runSql(
"INSERT INTO " + tableName +
" VALUES "
102 +
"(" + values_string +
")");
105 Random rand =
new Random(tid);
107 sql =
"ALTER TABLE " + tableName +
" ADD COLUMN zz TEXT ENCODING DICT(8);";
108 logger.info(logPrefix +
" " + sql);
113 sql =
"SELECT * FROM " + tableName +
" LIMIT 2;";
114 logger.info(logPrefix +
" " + sql);
117 sql =
"DELETE FROM " + tableName +
" WHERE y = " + rand.nextInt(num_rows)
119 logger.info(logPrefix +
" " + sql);
122 sql =
"ALTER TABLE " + tableName +
" DROP COLUMN x;";
123 logger.info(logPrefix +
" " + sql);
126 sql =
"SELECT * FROM " + tableName +
" WHERE str = '"
127 +
text_values[rand.nextInt(text_values.length)] +
"';";
128 logger.info(logPrefix +
" " + sql);
131 sql =
"SELECT COUNT(*) FROM " + tableName +
";";
132 logger.info(logPrefix +
" VALIDATE " + sql);
133 user.sqlValidate(sql);
135 final String tableRename = tableName +
"_rename";
136 sql =
"ALTER TABLE " + tableName +
" RENAME TO " + tableRename;
139 sql =
"TRUNCATE TABLE " + tableRename +
";";
140 logger.info(logPrefix +
" " + sql);
143 sql =
"INSERT INTO " + tableRename +
" VALUES "
144 +
"(" + tid +
"," + tid +
"," + tid +
"," + tid +
"," + tid +
","
145 + tid +
"," + tid +
"," + (tid % 2 == 0 ?
"'value_1'" :
"'value_2'")
147 logger.info(logPrefix +
" " + sql);
150 sql =
"DROP TABLE " + tableRename +
";";
151 logger.info(logPrefix +
" " + sql);
154 }
catch (Exception e) {
155 logger.error(logPrefix +
" Caught Exception: " + e.getMessage(), e);
156 exceptions[threadId] = e;
165 for (Thread t : threads) {
169 for (Exception e : exceptions) {
171 logger.error(
"Exception: " + e.getMessage(), e);
178 logger.info(
"SelectUpdateDeleteDifferentTables()");
181 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
182 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
183 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
185 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
187 su.runSql(
"CREATE DATABASE db1;");
188 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
189 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
190 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
191 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
193 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
196 su.runSql(
"DROP DATABASE db1;");
197 su.runSql(
"DROP USER bob;");
198 su.runSql(
"DROP USER dba;");
200 logger.info(
"SelectUpdateDeleteDifferentTables() done");
static final String[] text_values
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
static void main(String[] args)
static final Logger logger