OmniSciDB  2e3a973ef4
com.mapd.tests.CtasItasSelectUpdelConcurrencyTest Class Reference
+ Collaboration diagram for com.mapd.tests.CtasItasSelectUpdelConcurrencyTest:

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 27 of file CtasItasSelectUpdelConcurrencyTest.java.

Member Function Documentation

◆ main()

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

Definition at line 52 of file CtasItasSelectUpdelConcurrencyTest.java.

References com.mapd.tests.CtasItasSelectUpdelConcurrencyTest.testConcurrency().

52  {
53  CtasItasSelectUpdelConcurrencyTest test = new CtasItasSelectUpdelConcurrencyTest();
54  test.testConcurrency();
55  }
+ Here is the call graph for this function:

◆ runTest()

void com.mapd.tests.CtasItasSelectUpdelConcurrencyTest.runTest ( String  db,
String  dbaUser,
String  dbaPassword,
String  dbUser,
String  dbPassword 
) throws Exception
inlineprivate

Definition at line 57 of file CtasItasSelectUpdelConcurrencyTest.java.

References Double, com.mapd.tests.MapdTestClient.getClient(), num_rows, run, com.mapd.tests.MapdTestClient.runSql(), and com.mapd.tests.MapdTestClient.sqlValidate().

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

59  {
60  int num_threads = 5;
61  final int runs = 25;
62  final int num_rows = 1000;
63  final int fragment_size = 10;
64  final String tableName = "test";
65  Exception exceptions[] = new Exception[num_threads];
66 
67  final CyclicBarrier barrier = new CyclicBarrier(num_threads, new Runnable() {
68  public void run() {
69  try {
70  MapdTestClient dba =
71  MapdTestClient.getClient("localhost", 6274, db, dbaUser, dbaPassword);
72  dba.runSql("CREATE TABLE " + tableName
73  + "(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
74  + fragment_size + ")");
75 
76  for (int i = 0; i < num_rows; i++) {
77  final String integer_val = Integer.toString(i);
78  final String small_val = Integer.toString(i % 128);
79  final String fp_val = Double.toString(i * 1.1);
80  final String deci_val = Double.toString(i + 0.01);
81  final String str_val = "'" + text_values[i % text_values.length] + "'";
82  final String values_string = String.join(" , ",
83  integer_val,
84  integer_val,
85  small_val,
86  small_val,
87  fp_val,
88  fp_val,
89  deci_val,
90  str_val);
91  dba.runSql("INSERT INTO " + tableName + " VALUES "
92  + "(" + values_string + ")");
93  }
94 
95  } catch (Exception e) {
96  logger.error("[" + Thread.currentThread().getId() + "]"
97  + " Caught Exception: " + e.getMessage(),
98  e);
99  exceptions[0] = e;
100  }
101  }
102  });
103 
104  ArrayList<Thread> threads = new ArrayList<>();
105  for (int i = 0; i < num_threads; i++) {
106  logger.info("Starting " + i);
107  final int threadId = i;
108 
109  Thread t = new Thread(new Runnable() {
110  @Override
111  public void run() {
112  long tid = Thread.currentThread().getId();
113  String logPrefix = "[" + tid + "]";
114  String sql = "";
115 
116  final String ctasTableName = "ctas_test";
117 
118  try {
119  barrier.await();
120 
121  MapdTestClient user =
122  MapdTestClient.getClient("localhost", 6274, db, dbUser, dbPassword);
123 
124  Random rand = new Random(tid);
125 
126  if (threadId == 2) {
127  sql = "CREATE TABLE " + ctasTableName + " AS (SELECT x, y, deci, str FROM "
128  + tableName + ");";
129  logger.info(logPrefix + " " + sql);
130  user.runSql(sql);
131  }
132 
133  sql = "SELECT * FROM " + tableName + " LIMIT 2;";
134  logger.info(logPrefix + " " + sql);
135  user.runSql(sql);
136 
137  boolean ctas_table_created = false;
138  while (!ctas_table_created) {
139  ctas_table_created = true;
140  try {
141  sql = "SELECT COUNT(*) FROM " + ctasTableName + ";";
142  logger.info(logPrefix + " VALIDATE " + sql);
143  user.sqlValidate(sql);
144  } catch (TOmniSciException e) {
145  if (e.getError_msg().indexOf("not found") != -1) {
146  Thread.sleep(1000);
147  ctas_table_created = false;
148  } else {
149  throw e;
150  }
151  }
152  }
153 
154  sql = "DELETE FROM " + ctasTableName + " WHERE y = " + rand.nextInt(num_rows)
155  + ";";
156  logger.info(logPrefix + " " + sql);
157  user.runSql(sql);
158 
159  if (threadId == 0) {
160  sql = "ALTER TABLE " + tableName + " ADD COLUMN n TEXT ENCODING DICT(8);";
161  logger.info(logPrefix + " VALIDATE " + sql);
162  user.runSql(sql);
163 
164  sql = "INSERT INTO " + tableName + " VALUES "
165  + "(" + tid + "," + tid + "," + tid + "," + tid + "," + tid + ","
166  + tid + "," + tid + "," + (tid % 2 == 0 ? "'mapd'" : "'omnisci'")
167  + ", 'z');";
168  logger.info(logPrefix + " " + sql);
169  user.runSql(sql);
170  }
171 
172  sql = "INSERT INTO " + ctasTableName + " (SELECT x, y, deci, str FROM "
173  + tableName + " WHERE str = '"
174  + text_values[rand.nextInt(text_values.length)] + "');";
175  logger.info(logPrefix + " " + sql);
176  user.runSql(sql);
177 
178  sql = "TRUNCATE TABLE " + tableName + ";";
179  logger.info(logPrefix + " " + sql);
180  user.runSql(sql);
181 
182  } catch (Exception e) {
183  logger.error(logPrefix + " Caught Exception: " + e.getMessage(), e);
184  exceptions[threadId] = e;
185  }
186  }
187  });
188  t.start();
189  threads.add(t);
190  }
191 
192  for (Thread t : threads) {
193  t.join();
194  }
195 
196  MapdTestClient dba =
197  MapdTestClient.getClient("localhost", 6274, db, dbaUser, dbaPassword);
198  dba.runSql("DROP TABLE " + tableName + ";");
199 
200  for (Exception e : exceptions) {
201  if (null != e) {
202  logger.error("Exception: " + e.getMessage(), e);
203  throw e;
204  }
205  }
206  }
const int8_t const int64_t * num_rows
static bool run
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testConcurrency()

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

Definition at line 208 of file CtasItasSelectUpdelConcurrencyTest.java.

References com.mapd.tests.MapdTestClient.getClient(), com.mapd.tests.MapdTestClient.runSql(), and com.mapd.tests.CtasItasSelectUpdelConcurrencyTest.runTest().

Referenced by com.mapd.tests.CtasItasSelectUpdelConcurrencyTest.main().

208  {
209  logger.info("CtasItasSelectUpdelConcurrencyTest()");
210 
211  MapdTestClient su = MapdTestClient.getClient(
212  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
213  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
214  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
215 
216  su.runSql("GRANT CREATE on DATABASE omnisci TO bob;");
217 
218  su.runSql("CREATE DATABASE db1;");
219  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
220  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
221  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
222  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
223 
224  runTest("db1", "admin", "HyperInteractive", "admin", "HyperInteractive");
225  // TODO: run some tests as bob
226 
227  su.runSql("DROP DATABASE db1;");
228  su.runSql("DROP USER bob;");
229  su.runSql("DROP USER dba;");
230 
231  logger.info("CtasItasSelectUpdelConcurrencyTest() done");
232  }
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ logger

final Logger com.mapd.tests.CtasItasSelectUpdelConcurrencyTest.logger
staticpackage
Initial value:
=
LoggerFactory.getLogger(CtasItasSelectUpdelConcurrencyTest.class)

Definition at line 28 of file CtasItasSelectUpdelConcurrencyTest.java.

◆ text_values

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


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