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

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
 
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 SelectUpdateDeleteDifferentTables.java.

Member Function Documentation

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

Definition at line 49 of file SelectUpdateDeleteDifferentTables.java.

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

Definition at line 54 of file SelectUpdateDeleteDifferentTables.java.

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 177 of file SelectUpdateDeleteDifferentTables.java.

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

177  {
178  logger.info("SelectUpdateDeleteDifferentTables()");
179 
180  HeavyDBTestClient su = HeavyDBTestClient.getClient(
181  "localhost", 6274, "heavyai", "admin", "HyperInteractive");
182  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
183  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
184 
185  su.runSql("GRANT CREATE on DATABASE heavyai TO bob;");
186 
187  su.runSql("CREATE DATABASE db1;");
188  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
189  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
190  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
191  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
192 
193  runTest("db1", "admin", "HyperInteractive", "admin", "HyperInteractive");
194  // TODO: run some tests as bob
195 
196  su.runSql("DROP DATABASE db1;");
197  su.runSql("DROP USER bob;");
198  su.runSql("DROP USER dba;");
199 
200  logger.info("SelectUpdateDeleteDifferentTables() done");
201  }
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.SelectUpdateDeleteDifferentTables.logger
staticpackage
Initial value:
=
LoggerFactory.getLogger(SelectUpdateDeleteDifferentTables.class)

Definition at line 25 of file SelectUpdateDeleteDifferentTables.java.

final String [] com.mapd.tests.SelectUpdateDeleteDifferentTables.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 28 of file SelectUpdateDeleteDifferentTables.java.

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


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