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(ReductionConcurrencyTest.class);
48 public static void main(String[]
args)
throws Exception {
50 test.testConcurrency();
59 int fragmentSize)
throws Exception {
62 Exception exceptions[] =
new Exception[num_threads];
64 ArrayList<Thread> threads =
new ArrayList<>();
65 for (
int i = 0; i < num_threads; i++) {
66 logger.info(
"Starting " + i);
67 final int threadId = i;
69 Thread t =
new Thread(
new Runnable() {
72 long tid = Thread.currentThread().getId();
73 String logPrefix =
"[" + tid +
"]";
76 for (
int runId = 0; runId < runs; runId++) {
77 final String tableName = dbaUser +
"_" + threadId +
"_" + runId;
81 "localhost", 6274, db, dbUser, dbPassword);
82 user.runSql(
"DROP TABLE IF EXISTS " + tableName +
";");
83 user.runSql(
"CREATE TABLE " + tableName
84 +
"(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
85 + fragmentSize +
")");
87 for (
int i = 0; i < numRows; i++) {
88 final String integer_val = Integer.toString(i);
89 final String small_val = Integer.toString(i % 128);
90 final String fp_val = Double.toString(i * 1.1);
91 final String deci_val = Double.toString(i + 0.01);
92 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
93 final String values_string = String.join(
" , ",
102 user.runSql(
"INSERT INTO " + tableName +
" VALUES "
103 +
"(" + values_string +
")");
106 Random rand =
new Random(tid);
108 sql =
"SELECT * FROM " + tableName +
" LIMIT 2;";
109 logger.info(logPrefix +
" " + sql);
112 sql =
"SELECT x, sum(1) FROM " + tableName +
" GROUP BY 1;";
113 logger.info(logPrefix +
" " + sql);
116 sql =
"SELECT x, y, sum(1) FROM " + tableName +
" GROUP BY 1, 2;";
117 logger.info(logPrefix +
" " + sql);
120 sql =
"SELECT x, y, z, sum(1) FROM " + tableName +
" GROUP BY 1, 2, 3;";
121 logger.info(logPrefix +
" " + sql);
124 sql =
"SELECT x, y, avg(z), sum(1) FROM " + tableName +
" GROUP BY 1, 2;";
125 logger.info(logPrefix +
" " + sql);
128 sql =
"SELECT x, y, max(z), sum(1) FROM " + tableName +
" GROUP BY 1, 2;";
129 logger.info(logPrefix +
" " + sql);
132 sql =
"SELECT x, y, min(z), sum(1) FROM " + tableName +
" GROUP BY 1, 2;";
133 logger.info(logPrefix +
" " + sql);
136 sql =
"SELECT * FROM " + tableName +
" WHERE str = '"
137 +
text_values[rand.nextInt(text_values.length)] +
"';";
138 logger.info(logPrefix +
" " + sql);
141 }
catch (Exception e) {
142 logger.error(logPrefix +
" Caught Exception: " + e.getMessage(), e);
143 exceptions[threadId] = e;
152 for (Thread t : threads) {
156 for (Exception e : exceptions) {
158 logger.error(
"Exception: " + e.getMessage(), e);
165 logger.info(
"ReductionConcurrencyTest()");
168 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
169 su.runSql(
"DROP USER IF EXISTS dba;");
170 su.runSql(
"DROP USER IF EXISTS bob;");
171 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
172 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
174 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
176 su.runSql(
"DROP DATABASE IF EXISTS db1;");
177 su.runSql(
"CREATE DATABASE db1;");
179 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
180 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
181 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
182 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
185 for (
int i = 0; i < 3; ++i) {
187 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive", 10, 3);
189 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive", 30, 3);
192 su.runSql(
"DROP DATABASE db1;");
193 su.runSql(
"DROP USER bob;");
194 su.runSql(
"DROP USER dba;");
196 logger.info(
"ReductionConcurrencyTest() done");
static final Logger logger
static void main(String[] args)
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword, int numRows, int fragmentSize)
static final String[] text_values