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

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

Member Function Documentation

◆ main()

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

Definition at line 50 of file AlterDropTruncateValidateConcurrencyTest.java.

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

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

◆ runTest()

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

Definition at line 56 of file AlterDropTruncateValidateConcurrencyTest.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.AlterDropTruncateValidateConcurrencyTest.testConcurrency().

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

Definition at line 184 of file AlterDropTruncateValidateConcurrencyTest.java.

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

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

184  {
185  logger.info("AlterDropTruncateValidateConcurrencyTest()");
186 
187  MapdTestClient su = MapdTestClient.getClient(
188  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
189  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
190  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
191 
192  su.runSql("GRANT CREATE on DATABASE omnisci TO bob;");
193 
194  su.runSql("CREATE DATABASE db1;");
195  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
196  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
197  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
198  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
199 
200  runTest("db1", "admin", "HyperInteractive", "admin", "HyperInteractive");
201  // TODO: run some tests as bob
202 
203  su.runSql("DROP DATABASE db1;");
204  su.runSql("DROP USER bob;");
205  su.runSql("DROP USER dba;");
206 
207  logger.info("AlterDropTruncateValidateConcurrencyTest() done");
208  }
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.AlterDropTruncateValidateConcurrencyTest.logger
staticpackage
Initial value:
=
LoggerFactory.getLogger(AlterDropTruncateValidateConcurrencyTest.class)

Definition at line 26 of file AlterDropTruncateValidateConcurrencyTest.java.

◆ text_values

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


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