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

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(DistributedConcurrencyTest.class)
 
static final String[] text_values
 

Private Member Functions

void runTest (String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword) throws Exception
 

Detailed Description

Definition at line 24 of file DistributedConcurrencyTest.java.

Member Function Documentation

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

Definition at line 48 of file DistributedConcurrencyTest.java.

48  {
49  DistributedConcurrencyTest test = new DistributedConcurrencyTest();
50  test.testConcurrency();
51  }
void com.mapd.tests.DistributedConcurrencyTest.runTest ( String  db,
String  dbaUser,
String  dbaPassword,
String  dbUser,
String  dbPassword 
) throws Exception
inlineprivate

Definition at line 53 of file DistributedConcurrencyTest.java.

References run, and com.mapd.tests.DistributedConcurrencyTest.text_values.

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

55  {
56  int num_threads = 5;
57  final int runs = 5;
58  final int max_num_rows = 400;
59  final int fragment_size = 25;
60  Exception exceptions[] = new Exception[num_threads];
61 
62  ArrayList<Thread> threads = new ArrayList<>();
63  for (int i = 0; i < num_threads; i++) {
64  logger.info("Starting " + i);
65  final int threadId = i;
66 
67  Thread t = new Thread(new Runnable() {
68  @Override
69  public void run() {
70  long tid = Thread.currentThread().getId();
71  String logPrefix = "[" + tid + "]";
72  String sql = "";
73 
74  for (int runId = 0; runId < runs; runId++) {
75  final String tableName = dbaUser + "_" + threadId + "_" + runId;
76 
77  try {
78  HeavyDBTestClient user = HeavyDBTestClient.getClient(
79  "localhost", 6274, db, dbUser, dbPassword);
80 
81  sql = "CREATE TABLE " + tableName
82  + "(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
83  + fragment_size + ")";
84  logger.info(logPrefix + " " + sql);
85  user.runSql(sql);
86 
87  Random rand = new Random(tid);
88  int num_rows = rand.nextInt(max_num_rows);
89 
90  for (int i = 0; i < num_rows; i++) {
91  final String integer_val = Integer.toString(i);
92  final String small_val = Integer.toString(i % 128);
93  final String fp_val = Double.toString(i * 1.1);
94  final String deci_val = Double.toString(i + 0.01);
95  final String str_val = "'" + text_values[i % text_values.length] + "'";
96  final String values_string = String.join(" , ",
97  integer_val,
98  integer_val,
99  small_val,
100  small_val,
101  fp_val,
102  fp_val,
103  deci_val,
104  str_val);
105  sql = "INSERT INTO " + tableName + " VALUES "
106  + "(" + values_string + ")";
107  user.runSql(sql);
108  if (i == 0) {
109  logger.info(logPrefix + " " + sql);
110  }
111  }
112 
113  sql = "ALTER TABLE " + tableName + " ADD COLUMN zz TEXT ENCODING DICT(8);";
114  logger.info(logPrefix + " " + sql);
115  user.runSql(sql);
116 
117  // TODO(adb): add get_table_details once thread safe
118 
119  sql = "SELECT * FROM " + tableName + " LIMIT 2;";
120  logger.info(logPrefix + " " + sql);
121  user.runSql(sql);
122 
123  sql = "VALIDATE CLUSTER;";
124  logger.info(logPrefix + " " + sql);
125  user.runSql(sql);
126 
127  sql = "status";
128  user.get_status();
129  sql = "hardware";
130  user.get_hardware_info();
131  sql = "memory";
132  user.get_memory("cpu");
133 
134  sql = "DELETE FROM " + tableName + " WHERE y = " + rand.nextInt(num_rows)
135  + ";";
136  logger.info(logPrefix + " " + sql);
137  user.runSql(sql);
138 
139  sql = "ALTER TABLE " + tableName + " DROP COLUMN x;";
140  logger.info(logPrefix + " " + sql);
141  user.runSql(sql);
142 
143  sql = "SELECT * FROM " + tableName + " WHERE str = '"
144  + text_values[rand.nextInt(text_values.length)] + "';";
145  logger.info(logPrefix + " " + sql);
146  user.runSql(sql);
147 
148  sql = "SELECT COUNT(*) FROM " + tableName + ";";
149  logger.info(logPrefix + " VALIDATE " + sql);
150  user.sqlValidate(sql);
151 
152  sql = "TRUNCATE TABLE " + tableName + ";";
153  logger.info(logPrefix + " " + sql);
154  user.runSql(sql);
155 
156  sql = "DROP TABLE " + tableName + ";";
157  logger.info(logPrefix + " " + sql);
158  user.runSql(sql);
159 
160  } catch (Exception e) {
161  logger.error(logPrefix + " While running query '" + sql
162  + "' it threw this: " + e.getMessage());
163  exceptions[threadId] = new Exception(
164  " While running query '" + sql + "' it threw this: " + e);
165  }
166  }
167  }
168  });
169  t.start();
170  threads.add(t);
171  }
172 
173  for (Thread t : threads) {
174  t.join();
175  }
176 
177  for (Exception e : exceptions) {
178  if (null != e) {
179  logger.error("Exception during threaded runs: " + e.getMessage());
180  throw e;
181  }
182  }
183  }
static bool run

+ Here is the caller graph for this function:

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

Definition at line 185 of file DistributedConcurrencyTest.java.

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

185  {
186  logger.info("DistributedConcurrencyTest()");
187 
188  HeavyDBTestClient su = HeavyDBTestClient.getClient(
189  "localhost", 6274, "heavyai", "admin", "HyperInteractive");
190  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
191  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
192 
193  su.runSql("GRANT CREATE on DATABASE heavyai TO bob;");
194 
195  su.runSql("CREATE DATABASE db1;");
196  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
197  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
198  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
199  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
200 
201  runTest("db1", "admin", "HyperInteractive", "admin", "HyperInteractive");
202  // TODO: run some tests as bob
203 
204  su.runSql("DROP DATABASE db1;");
205  su.runSql("DROP USER bob;");
206  su.runSql("DROP USER dba;");
207 
208  logger.info("DistributedConcurrencyTest() done");
209  }
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 25 of file DistributedConcurrencyTest.java.

final String [] com.mapd.tests.DistributedConcurrencyTest.text_values
staticpackage
Initial value:
= {"foo",
"bar",
"hello",
"world",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p"}

Definition at line 27 of file DistributedConcurrencyTest.java.

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


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