OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.tests.CatalogConcurrencyTest Class Reference
+ Collaboration diagram for com.mapd.tests.CatalogConcurrencyTest:

Public Member Functions

void testCatalogConcurrency () throws Exception
 

Static Public Member Functions

static void main (String[] args) throws Exception
 

Static Package Attributes

static final String defPwd = "HyperInteractive"
 
static final String local = "localhost"
 
static final String defDb = "heavyai"
 
static final String admin = "admin"
 
static final int port = 6274
 
static final Logger logger = LoggerFactory.getLogger(CatalogConcurrencyTest.class)
 

Private Member Functions

void run_test (HeavyDBTestClient dba, HeavyDBTestClient user, String prefix, int max, List< Integer > dashboardIds) throws Exception
 
void runTest (String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword, List< Integer > dashboardIds) throws Exception
 

Detailed Description

Definition at line 25 of file CatalogConcurrencyTest.java.

Member Function Documentation

static void com.mapd.tests.CatalogConcurrencyTest.main ( String[]  args) throws Exception
inlinestatic

Definition at line 31 of file CatalogConcurrencyTest.java.

31  {
32  CatalogConcurrencyTest test = new CatalogConcurrencyTest();
33  test.testCatalogConcurrency();
34  }
void com.mapd.tests.CatalogConcurrencyTest.run_test ( HeavyDBTestClient  dba,
HeavyDBTestClient  user,
String  prefix,
int  max,
List< Integer >  dashboardIds 
) throws Exception
inlineprivate

Definition at line 36 of file CatalogConcurrencyTest.java.

References com.mapd.tests.CatalogConcurrencyTest.admin.

Referenced by com.mapd.tests.CatalogConcurrencyTest.runTest().

40  {
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;
48 
49  // Modify the fixed id dashboards in parallel.
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);
54  }
55 
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;");
62 
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;");
67 
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;");
72 
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;");
76 
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 + ";");
83 
84  logger.info(threadPrefix + "CREATE IF NOT EXISTS " + sharedTableName);
85  dba.runSql("CREATE TABLE IF NOT EXISTS " + sharedTableName + " (id INTEGER);");
86 
87  logger.info(threadPrefix + "DROP IF EXISTS " + sharedTableName);
88  dba.runSql("DROP TABLE IF EXISTS " + sharedTableName + ";");
89  }
90  }

+ Here is the caller graph for this function:

void com.mapd.tests.CatalogConcurrencyTest.runTest ( String  db,
String  dbaUser,
String  dbaPassword,
String  dbUser,
String  dbPassword,
List< Integer >  dashboardIds 
) throws Exception
inlineprivate

Definition at line 92 of file CatalogConcurrencyTest.java.

References com.mapd.tests.CatalogConcurrencyTest.local, com.mapd.tests.CatalogConcurrencyTest.port, run, and com.mapd.tests.CatalogConcurrencyTest.run_test().

Referenced by com.mapd.tests.CatalogConcurrencyTest.testCatalogConcurrency().

97  {
98  final int num_threads = 5, runs = 25;
99  Exception exceptions[] = new Exception[num_threads];
100 
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() {
107  @Override
108  public void run() {
109  try {
110  HeavyDBTestClient dba =
111  HeavyDBTestClient.getClient(local, port, db, dbaUser, dbaPassword);
112  HeavyDBTestClient user =
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(),
118  e);
119  exceptions[threadId] = e;
120  }
121  }
122  });
123  t.start();
124  threads.add(t);
125  }
126 
127  for (Thread t : threads) {
128  t.join();
129  }
130 
131  for (Exception e : exceptions) {
132  if (null != e) {
133  logger.error("Exception: " + e.getMessage(), e);
134  throw new Exception(e.getMessage(), e);
135  }
136  }
137  }
void run_test(HeavyDBTestClient dba, HeavyDBTestClient user, String prefix, int max, List< Integer > dashboardIds)
static bool run

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void com.mapd.tests.CatalogConcurrencyTest.testCatalogConcurrency ( ) throws Exception
inline

Definition at line 139 of file CatalogConcurrencyTest.java.

References com.mapd.tests.CatalogConcurrencyTest.admin, com.mapd.tests.CatalogConcurrencyTest.defDb, com.mapd.tests.CatalogConcurrencyTest.defPwd, com.mapd.tests.CatalogConcurrencyTest.local, com.mapd.tests.CatalogConcurrencyTest.port, and com.mapd.tests.CatalogConcurrencyTest.runTest().

139  {
140  logger.info("testCatalogConcurrency()");
141 
142  HeavyDBTestClient su = HeavyDBTestClient.getClient(local, port, defDb, admin, defPwd);
143 
144  su.runSql("DROP USER IF EXISTS bob;");
145  su.runSql("DROP USER IF EXISTS dba;");
146  su.runSql("DROP DATABASE IF EXISTS db1;");
147 
148  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
149  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
150 
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;");
154 
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;");
158 
159  su.runSql("CREATE DATABASE db1;");
160 
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;");
164 
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;");
168 
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;");
173 
174  // We create a series of dashboards with fixed ids to be modified in parallel.
175  HeavyDBTestClient dba =
176  HeavyDBTestClient.getClient(local, port, "db1", admin, defPwd);
177  for (TDashboard board : dba.get_dashboards()) {
178  logger.info("DROP DASHBOARD " + board.dashboard_name);
179  dba.delete_dashboard(board.dashboard_id);
180  }
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));
186  }
187  HeavyDBAsserts.assertEqual(5, dba.get_dashboards().size());
188 
189  runTest("db1", admin, defPwd, admin, defPwd, dashboardIds);
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);
194 
195  runTest(defDb, admin, defPwd, admin, defPwd, 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);
200 
201  for (TDashboard board : dba.get_dashboards()) {
202  logger.info("DROP DASHBOARD " + board.dashboard_name);
203  dba.delete_dashboard(board.dashboard_id);
204  }
205  su.runSql("DROP DATABASE db1;");
206  su.runSql("DROP USER bob;");
207  su.runSql("DROP USER dba;");
208 
209  logger.info("testCatalogConcurrency() done");
210  }
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword, List< Integer > dashboardIds)

+ Here is the call graph for this function:

Member Data Documentation

final String com.mapd.tests.CatalogConcurrencyTest.admin = "admin"
staticpackage
final String com.mapd.tests.CatalogConcurrencyTest.defDb = "heavyai"
staticpackage
final String com.mapd.tests.CatalogConcurrencyTest.defPwd = "HyperInteractive"
staticpackage
final String com.mapd.tests.CatalogConcurrencyTest.local = "localhost"
staticpackage
final Logger com.mapd.tests.CatalogConcurrencyTest.logger = LoggerFactory.getLogger(CatalogConcurrencyTest.class)
staticpackage

Definition at line 29 of file CatalogConcurrencyTest.java.

final int com.mapd.tests.CatalogConcurrencyTest.port = 6274
staticpackage

The documentation for this class was generated from the following file: