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;
25 final static Logger
logger = LoggerFactory.getLogger(DistributedConcurrencyTest.class);
48 public static void main(String[]
args)
throws Exception {
50 test.testConcurrency();
54 String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
58 final int max_num_rows = 400;
59 final int fragment_size = 25;
60 Exception exceptions[] =
new Exception[num_threads];
62 ArrayList<Thread> threads =
new ArrayList<>();
63 for (
int i = 0; i < num_threads; i++) {
64 logger.info(
"Starting " + i);
65 final int threadId = i;
67 Thread t =
new Thread(
new Runnable() {
70 long tid = Thread.currentThread().getId();
71 String logPrefix =
"[" + tid +
"]";
74 for (
int runId = 0; runId < runs; runId++) {
75 final String tableName = dbaUser +
"_" + threadId +
"_" + runId;
79 "localhost", 6274, db, dbUser, dbPassword);
81 sql =
"CREATE TABLE " + tableName
82 +
"(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
83 + fragment_size +
")";
84 logger.info(logPrefix +
" " + sql);
87 Random rand =
new Random(tid);
88 int num_rows = rand.nextInt(max_num_rows);
90 for (
int i = 0; i < num_rows; i++) {
91 final String integer_val = Integer.toString(i);
92 final String small_val = Integer.toString(i % 128);
93 final String fp_val = Double.toString(i * 1.1);
94 final String deci_val = Double.toString(i + 0.01);
95 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
96 final String values_string = String.join(
" , ",
105 sql =
"INSERT INTO " + tableName +
" VALUES "
106 +
"(" + values_string +
")";
109 logger.info(logPrefix +
" " + sql);
113 sql =
"ALTER TABLE " + tableName +
" ADD COLUMN zz TEXT ENCODING DICT(8);";
114 logger.info(logPrefix +
" " + sql);
119 sql =
"SELECT * FROM " + tableName +
" LIMIT 2;";
120 logger.info(logPrefix +
" " + sql);
123 sql =
"VALIDATE CLUSTER;";
124 logger.info(logPrefix +
" " + sql);
130 user.get_hardware_info();
132 user.get_memory(
"cpu");
134 sql =
"DELETE FROM " + tableName +
" WHERE y = " + rand.nextInt(num_rows)
136 logger.info(logPrefix +
" " + sql);
139 sql =
"ALTER TABLE " + tableName +
" DROP COLUMN x;";
140 logger.info(logPrefix +
" " + sql);
143 sql =
"SELECT * FROM " + tableName +
" WHERE str = '"
144 +
text_values[rand.nextInt(text_values.length)] +
"';";
145 logger.info(logPrefix +
" " + sql);
148 sql =
"SELECT COUNT(*) FROM " + tableName +
";";
149 logger.info(logPrefix +
" VALIDATE " + sql);
150 user.sqlValidate(sql);
152 sql =
"TRUNCATE TABLE " + tableName +
";";
153 logger.info(logPrefix +
" " + sql);
156 sql =
"DROP TABLE " + tableName +
";";
157 logger.info(logPrefix +
" " + sql);
160 }
catch (Exception e) {
161 logger.error(logPrefix +
" While running query '" + sql
162 +
"' it threw this: " + e.getMessage());
163 exceptions[threadId] =
new Exception(
164 " While running query '" + sql +
"' it threw this: " + e);
173 for (Thread t : threads) {
177 for (Exception e : exceptions) {
179 logger.error(
"Exception during threaded runs: " + e.getMessage());
186 logger.info(
"DistributedConcurrencyTest()");
189 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
190 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
191 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
193 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
195 su.runSql(
"CREATE DATABASE db1;");
196 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
197 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
198 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
199 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
201 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
204 su.runSql(
"DROP DATABASE db1;");
205 su.runSql(
"DROP USER bob;");
206 su.runSql(
"DROP USER dba;");
208 logger.info(
"DistributedConcurrencyTest() done");
static final Logger logger
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
static void main(String[] args)
static final String[] text_values