OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EagainConcurrencyTest.java
Go to the documentation of this file.
1 /*
2  * Copyright 2015 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.tests;
17 
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 
21 import java.util.ArrayList;
22 
23 public class EagainConcurrencyTest {
24  final static Logger logger = LoggerFactory.getLogger(EagainConcurrencyTest.class);
25 
26  public static void main(String[] args) throws Exception {
28  test.testCatalogConcurrency();
29  }
30 
31  private void run_test(MapdTestClient dba, MapdTestClient user, String prefix, int max)
32  throws Exception {
33  String tableName = "table_" + prefix + "_";
34  long tid = Thread.currentThread().getId();
35  logger.info("[" + tid + "]"
36  + "CREATE " + tableName);
37  user.runSql("CREATE TABLE " + tableName + " (id integer);");
38 
39  for (int i = 0; i < max; i++) {
40  logger.info("[" + tid + "]"
41  + "INSERT INTO " + tableName);
42  user.runSql("INSERT INTO " + tableName + " VALUES (" + i + ");");
43 
44  user.get_status();
45  user.get_server_status();
46  user.get_hardware_info();
47 
48  logger.info("[" + tid + "]"
49  + "SELECT FROM " + tableName);
50  user.runSql("SELECT * FROM " + tableName + ";");
51  }
52 
53  logger.info("[" + tid + "]"
54  + "DROP " + tableName);
55  dba.runSql("DROP TABLE " + tableName + ";");
56  }
57 
58  private void runTest(
59  String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
60  throws Exception {
61  int num_threads = 5;
62  final int runs = 25;
63  Exception exceptions[] = new Exception[num_threads];
64 
65  ArrayList<Thread> threads = new ArrayList<>();
66  for (int i = 0; i < num_threads; i++) {
67  logger.info("Starting " + i);
68  final String prefix = "for_bob_" + i + "_";
69  final int threadId = i;
70  Thread t = new Thread(new Runnable() {
71  @Override
72  public void run() {
73  try {
74  MapdTestClient dba =
75  MapdTestClient.getClient("localhost", 6274, db, dbaUser, dbaPassword);
76  MapdTestClient user =
77  MapdTestClient.getClient("localhost", 6274, db, dbUser, dbPassword);
78  run_test(dba, user, prefix, runs);
79  } catch (Exception e) {
80  logger.error("[" + Thread.currentThread().getId() + "]"
81  + "Caught Exception: " + e.getMessage(),
82  e);
83  exceptions[threadId] = e;
84  }
85  }
86  });
87  t.start();
88  threads.add(t);
89  }
90 
91  for (Thread t : threads) {
92  t.join();
93  }
94 
95  for (Exception e : exceptions) {
96  if (null != e) {
97  logger.error("Exception: " + e.getMessage(), e);
98  throw new Exception(e.getMessage(), e);
99  }
100  }
101  }
102 
103  public void testCatalogConcurrency() throws Exception {
104  logger.info("testCatalogConcurrency()");
105 
106  MapdTestClient su = MapdTestClient.getClient(
107  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
108  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
109  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
110 
111  su.runSql("GRANT CREATE on DATABASE omnisci TO bob;");
112  su.runSql("GRANT CREATE VIEW on DATABASE omnisci TO bob;");
113  su.runSql("GRANT CREATE DASHBOARD on DATABASE omnisci TO bob;");
114 
115  su.runSql("GRANT DROP on DATABASE omnisci TO bob;");
116  su.runSql("GRANT DROP VIEW on DATABASE omnisci TO bob;");
117  su.runSql("GRANT DELETE DASHBOARD on DATABASE omnisci TO bob;");
118 
119  su.runSql("CREATE DATABASE db1;");
120 
121  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
122  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
123  su.runSql("GRANT CREATE DASHBOARD on DATABASE db1 TO bob;");
124 
125  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
126  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
127  su.runSql("GRANT DELETE DASHBOARD on DATABASE db1 TO bob;");
128 
129  su.runSql("GRANT ACCESS on database omnisci TO dba;");
130  su.runSql("GRANT ACCESS on database omnisci TO bob;");
131  su.runSql("GRANT ACCESS on database db1 TO dba;");
132  su.runSql("GRANT ACCESS on database db1 TO bob;");
133 
134  runTest("db1", "admin", "HyperInteractive", "admin", "HyperInteractive");
135  runTest("db1", "admin", "HyperInteractive", "dba", "password");
136  runTest("db1", "admin", "HyperInteractive", "bob", "password");
137  runTest("db1", "dba", "password", "admin", "HyperInteractive");
138  runTest("db1", "dba", "password", "bob", "password");
139 
140  runTest("omnisci", "admin", "HyperInteractive", "admin", "HyperInteractive");
141  runTest("omnisci", "admin", "HyperInteractive", "dba", "password");
142  runTest("omnisci", "admin", "HyperInteractive", "bob", "password");
143  runTest("omnisci", "dba", "password", "admin", "HyperInteractive");
144  runTest("omnisci", "dba", "password", "bob", "password");
145 
146  su.runSql("DROP DATABASE db1;");
147  su.runSql("DROP USER bob;");
148  su.runSql("DROP USER dba;");
149  }
150 }
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
void run_test(MapdTestClient dba, MapdTestClient user, String prefix, int max)
static bool run