16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import java.util.ArrayList;
24 final static Logger
logger = LoggerFactory.getLogger(EagainConcurrencyTest.class);
26 public static void main(String[]
args)
throws Exception {
28 test.testCatalogConcurrency();
36 int max)
throws Exception {
37 String tableName =
"table_" + prefix +
"_";
38 String viewName =
"view_" + prefix +
"_";
39 long tid = Thread.currentThread().getId();
41 logger.info(
"[" + tid +
"]"
42 +
"FIRST USER CONNECT");
44 HeavyDBTestClient.getClient(
"localhost", 6274, db, dbUser, dbPassword);
46 logger.info(
"[" + tid +
"]"
47 +
"CREATE " + tableName);
48 first_user.runSql(
"CREATE TABLE " + tableName +
" (id integer);");
50 logger.info(
"[" + tid +
"]"
51 +
"CREATE VIEW " + viewName);
53 "CREATE VIEW " + viewName +
" AS (SELECT id * 2 FROM " + tableName +
");");
55 logger.info(
"[" + tid +
"]"
56 +
"FIRST USER DISCONNECT");
57 first_user.disconnect();
59 for (
int i = 0; i < max; i++) {
60 logger.info(
"[" + tid +
"]"
63 HeavyDBTestClient.getClient(
"localhost", 6274, db, dbUser, dbPassword);
65 logger.info(
"[" + tid +
"]"
66 +
"INSERT INTO " + tableName);
67 user.runSql(
"INSERT INTO " + tableName +
" VALUES (" + i +
");");
70 user.get_server_status();
71 user.get_hardware_info();
73 logger.info(
"[" + tid +
"]"
74 +
"SELECT FROM " + tableName);
75 user.runSql(
"SELECT * FROM " + tableName +
";");
77 user.get_memory(
"cpu");
78 user.get_dashboards();
82 logger.info(
"[" + tid +
"]"
87 logger.info(
"[" + tid +
"]"
88 +
"DROP " + viewName);
89 dba.runSql(
"DROP VIEW " + viewName +
";");
91 logger.info(
"[" + tid +
"]"
92 +
"DROP " + tableName);
93 dba.runSql(
"DROP TABLE " + tableName +
";");
97 String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
101 Exception exceptions[] =
new Exception[num_threads];
103 ArrayList<Thread> threads =
new ArrayList<>();
104 for (
int i = 0; i < num_threads; i++) {
105 logger.info(
"Starting " + i);
106 final String prefix =
"for_bob_" + i +
"_";
107 final int threadId = i;
108 Thread t =
new Thread(
new Runnable() {
113 "localhost", 6274, db, dbaUser, dbaPassword);
114 run_test(dba, db, dbUser, dbPassword, prefix, runs);
115 }
catch (Exception e) {
116 logger.error(
"[" + Thread.currentThread().getId() +
"]"
117 +
"Caught Exception: " + e.getMessage(),
119 exceptions[threadId] = e;
127 for (Thread t : threads) {
131 for (Exception e : exceptions) {
133 logger.error(
"Exception: " + e.getMessage(), e);
134 throw new Exception(e.getMessage(), e);
140 logger.info(
"testCatalogConcurrency()");
143 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
144 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
145 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
147 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
148 su.runSql(
"GRANT CREATE VIEW on DATABASE heavyai TO bob;");
149 su.runSql(
"GRANT CREATE DASHBOARD on DATABASE heavyai TO bob;");
151 su.runSql(
"GRANT DROP on DATABASE heavyai TO bob;");
152 su.runSql(
"GRANT DROP VIEW on DATABASE heavyai TO bob;");
153 su.runSql(
"GRANT DELETE DASHBOARD on DATABASE heavyai TO bob;");
155 su.runSql(
"CREATE DATABASE db1;");
157 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
158 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
159 su.runSql(
"GRANT CREATE DASHBOARD on DATABASE db1 TO bob;");
161 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
162 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
163 su.runSql(
"GRANT DELETE DASHBOARD on DATABASE db1 TO bob;");
165 su.runSql(
"GRANT ACCESS on database heavyai TO dba;");
166 su.runSql(
"GRANT ACCESS on database heavyai TO bob;");
167 su.runSql(
"GRANT ACCESS on database db1 TO dba;");
168 su.runSql(
"GRANT ACCESS on database db1 TO bob;");
170 runTest(
"db1",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
171 runTest(
"db1",
"admin",
"HyperInteractive",
"dba",
"password");
172 runTest(
"db1",
"admin",
"HyperInteractive",
"bob",
"password");
173 runTest(
"db1",
"dba",
"password",
"admin",
"HyperInteractive");
174 runTest(
"db1",
"dba",
"password",
"bob",
"password");
176 runTest(
"heavyai",
"admin",
"HyperInteractive",
"admin",
"HyperInteractive");
177 runTest(
"heavyai",
"admin",
"HyperInteractive",
"dba",
"password");
178 runTest(
"heavyai",
"admin",
"HyperInteractive",
"bob",
"password");
179 runTest(
"heavyai",
"dba",
"password",
"admin",
"HyperInteractive");
180 runTest(
"heavyai",
"dba",
"password",
"bob",
"password");
182 su.runSql(
"DROP DATABASE db1;");
183 su.runSql(
"DROP USER bob;");
184 su.runSql(
"DROP USER dba;");
186 logger.info(
"testCatalogConcurrency() done");
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
static void main(String[] args)
void testCatalogConcurrency()
void run_test(HeavyDBTestClient dba, String db, String dbUser, String dbPassword, String prefix, int max)
static final Logger logger