16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
23 import ai.heavy.thrift.server.*;
26 final static String
defPwd =
"HyperInteractive",
local =
"localhost",
defDb =
"heavyai",
28 final static int port = 6274;
29 final static Logger
logger = LoggerFactory.getLogger(CatalogConcurrencyTest.class);
31 public static void main(String[]
args)
throws Exception {
33 test.testCatalogConcurrency();
40 List<Integer> dashboardIds)
throws Exception {
41 final String sharedTableName =
"table_shared";
42 for (
int i = 0; i < max; i++) {
43 final long tid = Thread.currentThread().getId();
44 final String threadPrefix =
"[" + tid +
"] ",
45 tableName =
"table_" + prefix +
"_" + i,
46 viewName =
"view_" + prefix +
"_" + i,
47 dashName =
"dash_" + prefix +
"_" + i;
50 for (
int id : dashboardIds) {
51 TDashboard board = dba.get_dashboard(id);
52 logger.info(
"REPLACE DASHBOARD id (" +
id +
") " + board.dashboard_name);
53 dba.replace_dashboard(board.dashboard_id, board.dashboard_name +
"_",
admin);
56 logger.info(threadPrefix +
"CREATE TABLE " + tableName);
57 user.runSql(
"CREATE TABLE " + tableName +
" (id text);");
58 HeavyDBAsserts.assertEqual(
true, null != dba.get_table_details(tableName));
59 logger.info(threadPrefix +
"INSERT INTO " + tableName);
60 user.runSql(
"INSERT INTO " + tableName +
" VALUES(1);");
61 dba.runSql(
"GRANT SELECT ON TABLE " + tableName +
" TO bob;");
63 logger.info(threadPrefix +
"CREATE VIEW " + viewName);
64 user.runSql(
"CREATE VIEW " + viewName +
" AS SELECT * FROM " + tableName +
";");
65 HeavyDBAsserts.assertEqual(
true, null != dba.get_table_details(viewName));
66 dba.runSql(
"GRANT SELECT ON VIEW " + viewName +
" TO bob;");
68 logger.info(threadPrefix +
"CREATE DASHBOARD " + dashName);
69 int dash_id = user.create_dashboard(dashName);
70 HeavyDBAsserts.assertEqual(
true, null != dba.get_dashboard(dash_id));
71 dba.runSql(
"GRANT VIEW ON DASHBOARD " + dash_id +
" TO bob;");
73 dba.runSql(
"REVOKE VIEW ON DASHBOARD " + dash_id +
" FROM bob;");
74 dba.runSql(
"REVOKE SELECT ON VIEW " + viewName +
" FROM bob;");
75 dba.runSql(
"REVOKE SELECT ON TABLE " + tableName +
" FROM bob;");
77 logger.info(threadPrefix +
"DELETE DASHBOARD " + dashName);
78 dba.delete_dashboard(dash_id);
79 logger.info(threadPrefix +
"DROP VIEW " + viewName);
80 dba.runSql(
"DROP VIEW " + viewName +
";");
81 logger.info(threadPrefix +
"DROP TABLE " + tableName);
82 dba.runSql(
"DROP TABLE " + tableName +
";");
84 logger.info(threadPrefix +
"CREATE IF NOT EXISTS " + sharedTableName);
85 dba.runSql(
"CREATE TABLE IF NOT EXISTS " + sharedTableName +
" (id INTEGER);");
87 logger.info(threadPrefix +
"DROP IF EXISTS " + sharedTableName);
88 dba.runSql(
"DROP TABLE IF EXISTS " + sharedTableName +
";");
97 List<Integer> dashboardIds)
throws Exception {
98 final int num_threads = 5, runs = 25;
99 Exception exceptions[] =
new Exception[num_threads];
101 ArrayList<Thread> threads =
new ArrayList<>();
102 for (
int i = 0; i < num_threads; i++) {
103 logger.info(
"Starting " + i);
104 final String prefix =
"for_bob_" + i +
"_";
105 final int threadId = i;
106 Thread t =
new Thread(
new Runnable() {
111 HeavyDBTestClient.getClient(
local,
port, db, dbaUser, dbaPassword);
113 HeavyDBTestClient.getClient(
local,
port, db, dbUser, dbPassword);
114 run_test(dba, user, prefix, runs, dashboardIds);
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()");
144 su.runSql(
"DROP USER IF EXISTS bob;");
145 su.runSql(
"DROP USER IF EXISTS dba;");
146 su.runSql(
"DROP DATABASE IF EXISTS db1;");
148 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
149 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
151 su.runSql(
"GRANT CREATE on DATABASE heavyai TO bob;");
152 su.runSql(
"GRANT CREATE VIEW on DATABASE heavyai TO bob;");
153 su.runSql(
"GRANT CREATE DASHBOARD on DATABASE heavyai TO bob;");
155 su.runSql(
"GRANT DROP on DATABASE heavyai TO bob;");
156 su.runSql(
"GRANT DROP VIEW on DATABASE heavyai TO bob;");
157 su.runSql(
"GRANT DELETE DASHBOARD on DATABASE heavyai TO bob;");
159 su.runSql(
"CREATE DATABASE db1;");
161 su.runSql(
"GRANT CREATE on DATABASE db1 TO bob;");
162 su.runSql(
"GRANT CREATE VIEW on DATABASE db1 TO bob;");
163 su.runSql(
"GRANT CREATE DASHBOARD on DATABASE db1 TO bob;");
165 su.runSql(
"GRANT DROP on DATABASE db1 TO bob;");
166 su.runSql(
"GRANT DROP VIEW on DATABASE db1 TO bob;");
167 su.runSql(
"GRANT DELETE DASHBOARD on DATABASE db1 TO bob;");
169 su.runSql(
"GRANT ACCESS on database heavyai TO dba;");
170 su.runSql(
"GRANT ACCESS on database heavyai TO bob;");
171 su.runSql(
"GRANT ACCESS on database db1 TO dba;");
172 su.runSql(
"GRANT ACCESS on database db1 TO bob;");
177 for (TDashboard board : dba.get_dashboards()) {
178 logger.info(
"DROP DASHBOARD " + board.dashboard_name);
179 dba.delete_dashboard(board.dashboard_id);
181 ArrayList<Integer> dashboardIds =
new ArrayList<>();
182 for (
int i = 0; i < 5; ++i) {
183 String dashName =
"dash_" + i;
184 logger.info(
"CREATE DASHBOARD " + dashName);
185 dashboardIds.add(dba.create_dashboard(dashName));
187 HeavyDBAsserts.assertEqual(5, dba.get_dashboards().size());
190 runTest(
"db1", admin,
defPwd,
"dba",
"password", dashboardIds);
191 runTest(
"db1", admin,
defPwd,
"bob",
"password", dashboardIds);
192 runTest(
"db1",
"dba",
"password", admin,
defPwd, dashboardIds);
193 runTest(
"db1",
"dba",
"password",
"bob",
"password", dashboardIds);
196 runTest(defDb, admin,
defPwd,
"dba",
"password", dashboardIds);
197 runTest(defDb, admin,
defPwd,
"bob",
"password", dashboardIds);
198 runTest(defDb,
"dba",
"password", admin,
defPwd, dashboardIds);
199 runTest(defDb,
"dba",
"password",
"bob",
"password", dashboardIds);
201 for (TDashboard board : dba.get_dashboards()) {
202 logger.info(
"DROP DASHBOARD " + board.dashboard_name);
203 dba.delete_dashboard(board.dashboard_id);
205 su.runSql(
"DROP DATABASE db1;");
206 su.runSql(
"DROP USER bob;");
207 su.runSql(
"DROP USER dba;");
209 logger.info(
"testCatalogConcurrency() done");
static void main(String[] args)
static final String defPwd
static final String defDb
void testCatalogConcurrency()
static final String admin
static final Logger logger
static final String local
void run_test(HeavyDBTestClient dba, HeavyDBTestClient user, String prefix, int max, List< Integer > dashboardIds)
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword, List< Integer > dashboardIds)