OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.tests.UpdateDeleteInsertConcurrencyTest Class Reference
+ Collaboration diagram for com.mapd.tests.UpdateDeleteInsertConcurrencyTest:

Public Member Functions

void testUpdateDeleteInsertConcurrency () 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, Boolean concurrentInserts) throws Exception
 

Detailed Description

Definition at line 25 of file UpdateDeleteInsertConcurrencyTest.java.

Member Function Documentation

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

Definition at line 50 of file UpdateDeleteInsertConcurrencyTest.java.

50  {
51  UpdateDeleteInsertConcurrencyTest test = new UpdateDeleteInsertConcurrencyTest();
52  test.testUpdateDeleteInsertConcurrency();
53  }
void com.mapd.tests.UpdateDeleteInsertConcurrencyTest.runTest ( String  db,
String  dbaUser,
String  dbaPassword,
String  dbUser,
String  dbPassword,
Boolean  concurrentInserts 
) throws Exception
inlineprivate

Definition at line 55 of file UpdateDeleteInsertConcurrencyTest.java.

References num_rows, run, Experimental.String, and com.mapd.tests.UpdateDeleteInsertConcurrencyTest.text_values.

Referenced by com.mapd.tests.UpdateDeleteInsertConcurrencyTest.testUpdateDeleteInsertConcurrency().

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

+ Here is the caller graph for this function:

void com.mapd.tests.UpdateDeleteInsertConcurrencyTest.testUpdateDeleteInsertConcurrency ( ) throws Exception
inline

Definition at line 211 of file UpdateDeleteInsertConcurrencyTest.java.

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

211  {
212  logger.info("testUpdateDeleteInsertConcurrency()");
213 
214  MapdTestClient su = MapdTestClient.getClient(
215  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
216  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
217  su.runSql("CREATE USER bob (password = 'password', is_super = 'false');");
218 
219  su.runSql("GRANT CREATE on DATABASE omnisci TO bob;");
220 
221  su.runSql("CREATE DATABASE db1;");
222  su.runSql("GRANT CREATE on DATABASE db1 TO bob;");
223  su.runSql("GRANT CREATE VIEW on DATABASE db1 TO bob;");
224  su.runSql("GRANT DROP on DATABASE db1 TO bob;");
225  su.runSql("GRANT DROP VIEW on DATABASE db1 TO bob;");
226 
227  runTest("db1",
228  "admin",
229  "HyperInteractive",
230  "admin",
231  "HyperInteractive",
232  /* concurrentInserts= */ false);
233  runTest("db1",
234  "admin",
235  "HyperInteractive",
236  "admin",
237  "HyperInteractive",
238  /* concurrentInserts= */ true);
239  // TODO: run some tests as bob
240 
241  su.runSql("DROP DATABASE db1;");
242  su.runSql("DROP USER bob;");
243  su.runSql("DROP USER dba;");
244  }
void runTest(String db, String dbaUser, String dbaPassword, String dbUser, String dbPassword, Boolean concurrentInserts)

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 26 of file UpdateDeleteInsertConcurrencyTest.java.

final String [] com.mapd.tests.UpdateDeleteInsertConcurrencyTest.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 UpdateDeleteInsertConcurrencyTest.java.

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


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