OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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

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

Definition at line 50 of file AlterDropTruncateValidateConcurrencyTest.java.

50  {
51  AlterDropTruncateValidateConcurrencyTest test =
52  new AlterDropTruncateValidateConcurrencyTest();
53  test.testConcurrency();
54  }
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 run, and com.mapd.tests.AlterDropTruncateValidateConcurrencyTest.text_values.

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  HeavyDBTestClient dba = HeavyDBTestClient.getClient(
70  "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  HeavyDBTestClient user = HeavyDBTestClient.getClient(
118  "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  HeavyDBTestClient dba =
173  HeavyDBTestClient.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  }
static bool run

+ Here is the caller graph for this function:

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

Definition at line 184 of file AlterDropTruncateValidateConcurrencyTest.java.

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

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

Definition at line 26 of file AlterDropTruncateValidateConcurrencyTest.java.

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.

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


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