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

Classes

class  ThreadDbQueries
 

Public Member Functions

void testConcurrency () throws Exception
 

Static Public Member Functions

static void main (String[] args) throws Exception
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(SystemTableConcurrencyTest.class)
 

Private Member Functions

void runTest () throws Exception
 
void runSqlAsUser (String sql, MapdTestClient user, int threadId) throws Exception
 

Detailed Description

Definition at line 25 of file SystemTableConcurrencyTest.java.

Member Function Documentation

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

Definition at line 28 of file SystemTableConcurrencyTest.java.

28  {
29  SystemTableConcurrencyTest test = new SystemTableConcurrencyTest();
30  test.testConcurrency();
31  }
void com.mapd.tests.SystemTableConcurrencyTest.runSqlAsUser ( String  sql,
MapdTestClient  user,
int  threadId 
) throws Exception
inlineprivate

Definition at line 171 of file SystemTableConcurrencyTest.java.

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

172  {
173  logger.info(threadId + " " + sql);
174  user.runSql(sql);
175  }

+ Here is the caller graph for this function:

void com.mapd.tests.SystemTableConcurrencyTest.runTest ( ) throws Exception
inlineprivate

Definition at line 39 of file SystemTableConcurrencyTest.java.

References i, com.mapd.tests.SystemTableConcurrencyTest.ThreadDbQueries.queries, com.mapd.tests.SystemTableConcurrencyTest.runSqlAsUser(), and t.

Referenced by com.mapd.tests.SystemTableConcurrencyTest.testConcurrency().

39  {
40  final List<ThreadDbQueries> queriesPerThread = Arrays.asList(
41  new ThreadDbQueries("omnisci",
42  Arrays.asList("CREATE USER user_1 (password = 'HyperInteractive');",
43  "ALTER USER user_1 (password = 'HyperInteractive2');",
44  "DROP USER user_1;",
45  "CREATE USER user_2 (password = 'HyperInteractive');",
46  "ALTER USER user_2 (password = 'HyperInteractive2');",
47  "DROP USER user_2;")),
48  new ThreadDbQueries("omnisci",
49  Arrays.asList("CREATE USER user_3 (password = 'HyperInteractive');",
50  "GRANT SELECT ON DATABASE omnisci TO user_3;",
51  "REVOKE SELECT ON DATABASE omnisci FROM user_3;",
52  "GRANT CREATE ON DATABASE omnisci TO user_3;",
53  "REVOKE CREATE ON DATABASE omnisci FROM user_3;",
54  "DROP USER user_3;")),
55  new ThreadDbQueries("omnisci",
56  Arrays.asList("CREATE DATABASE db_1;",
57  "CREATE DATABASE db_2;",
58  "DROP DATABASE db_1;",
59  "DROP DATABASE db_2;")),
60  new ThreadDbQueries("omnisci",
61  Arrays.asList("CREATE ROLE role_1;",
62  "CREATE ROLE role_2;",
63  "DROP ROLE role_1;",
64  "DROP ROLE role_2;")),
65  new ThreadDbQueries("omnisci",
66  Arrays.asList("CREATE TABLE table_1 (i INTEGER, t TEXT);",
67  "INSERT INTO table_1 VALUES (1, 'abc');",
68  "SELECT AVG(i) FROM table_1;",
69  "CREATE VIEW view_1 AS SELECT * FROM table_1;",
70  "SELECT * FROM view_1;",
71  "DROP VIEW view_1;",
72  "DROP TABLE table_1;")),
73  new ThreadDbQueries("omnisci",
74  Arrays.asList("CREATE USER user_4 (password = 'HyperInteractive');",
75  "CREATE USER user_5 (password = 'HyperInteractive');",
76  "CREATE ROLE role_3;",
77  "CREATE ROLE role_4;",
78  "GRANT role_3, role_4 TO user_4, user_5;",
79  "REVOKE role_3 FROM user_5;",
80  "REVOKE role_4 FROM user_4, user_5;",
81  "REVOKE role_3 FROM user_4;",
82  "DROP USER user_4;",
83  "DROP USER user_5;",
84  "DROP ROLE role_3;",
85  "DROP ROLE role_4;")),
86  new ThreadDbQueries(
87  "information_schema", Arrays.asList("SELECT * FROM users;")),
88  new ThreadDbQueries(
89  "information_schema", Arrays.asList("SELECT * FROM permissions;")),
90  new ThreadDbQueries(
91  "information_schema", Arrays.asList("SELECT * FROM databases;")),
92  new ThreadDbQueries(
93  "information_schema", Arrays.asList("SELECT * FROM roles;")),
94  new ThreadDbQueries(
95  "information_schema", Arrays.asList("SELECT * FROM tables;")),
96  new ThreadDbQueries("information_schema",
97  Arrays.asList("SELECT * FROM role_assignments;")),
98  new ThreadDbQueries(
99  "information_schema", Arrays.asList("SELECT * FROM dashboards;")),
100  new ThreadDbQueries(
101  "information_schema", Arrays.asList("SELECT * FROM memory_summary;")),
102  new ThreadDbQueries("information_schema",
103  Arrays.asList("SELECT * FROM memory_details;")));
104 
105  final int num_threads = queriesPerThread.size()
106  + 1; // +1 for dashboard creation/update thread, which is created separately.
107  Exception[] exceptions = new Exception[num_threads];
108  Thread[] threads = new Thread[num_threads];
109 
110  // Use a barrier here to synchronize the start of each competing thread and make
111  // sure there is a race condition. The barrier ensures no thread will run until they
112  // are all created and waiting for the barrier to complete.
113  final CyclicBarrier barrier = new CyclicBarrier(
114  num_threads, () -> { logger.info("Barrier acquired. Starting queries..."); });
115 
116  threads[0] = new Thread(() -> {
117  try {
118  logger.info("Starting thread[0]");
119  MapdTestClient user = MapdTestClient.getClient(
120  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
121  barrier.await();
122  logger.info("0 create dashboard \"dashboard_1\"");
123  int dashboardId = user.create_dashboard("dashboard_1");
124  logger.info("0 get dashboard " + dashboardId);
125  user.get_dashboard(dashboardId);
126  logger.info("0 replace dashboard " + dashboardId);
127  user.replace_dashboard(dashboardId, "dashboard_2", "admin");
128  logger.info("0 delete dashboard " + dashboardId);
129  user.delete_dashboard(dashboardId);
130  logger.info("Finished thread[0]");
131  } catch (Exception e) {
132  logger.error("Thread[0] Caught Exception: " + e.getMessage(), e);
133  exceptions[0] = e;
134  }
135  });
136  threads[0].start();
137 
138  for (int i = 0; i < queriesPerThread.size(); i++) {
139  final ThreadDbQueries threadQueries = queriesPerThread.get(i);
140  final int threadId = i + 1;
141  threads[threadId] = new Thread(() -> {
142  try {
143  logger.info("Starting thread[" + threadId + "]");
144  MapdTestClient user = MapdTestClient.getClient(
145  "localhost", 6274, threadQueries.database, "admin", "HyperInteractive");
146  barrier.await();
147  for (final String query : threadQueries.queries) {
148  runSqlAsUser(query, user, threadId);
149  }
150  logger.info("Finished thread[" + threadId + "]");
151  } catch (Exception e) {
152  logger.error("Thread[" + threadId + "] Caught Exception: " + e.getMessage(), e);
153  exceptions[threadId] = e;
154  }
155  });
156  threads[threadId].start();
157  }
158 
159  for (Thread t : threads) {
160  t.join();
161  }
162 
163  for (Exception e : exceptions) {
164  if (e != null) {
165  logger.error("Exception: " + e.getMessage(), e);
166  throw e;
167  }
168  }
169  }
void runSqlAsUser(String sql, MapdTestClient user, int threadId)
char * t

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void com.mapd.tests.SystemTableConcurrencyTest.testConcurrency ( ) throws Exception
inline

Definition at line 33 of file SystemTableConcurrencyTest.java.

References com.mapd.tests.SystemTableConcurrencyTest.runTest().

33  {
34  logger.info("SystemTableConcurrencyTest()");
35  runTest();
36  logger.info("SystemTableConcurrencyTest() done");
37  }

+ Here is the call graph for this function:

Member Data Documentation

final Logger com.mapd.tests.SystemTableConcurrencyTest.logger = LoggerFactory.getLogger(SystemTableConcurrencyTest.class)
staticpackage

Definition at line 26 of file SystemTableConcurrencyTest.java.


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