75 final int num_rows = 1000;
76 final int fragment_size = 10;
77 final String tableName =
"test";
78 Exception exceptions[] =
new Exception[num_threads];
80 final CyclicBarrier barrier =
new CyclicBarrier(num_threads,
new Runnable() {
83 HeavyDBTestClient dba = HeavyDBTestClient.getClient(
84 "localhost", 6274, db, dbaUser, dbaPassword);
85 final String createPrefix =
87 dba.runSql(createPrefix + tableName
88 +
"(x BIGINT, y INTEGER, z SMALLINT, a TINYINT, f FLOAT, d DOUBLE, deci DECIMAL(18,6), str TEXT ENCODING NONE) WITH (FRAGMENT_SIZE = "
89 + fragment_size +
")");
90 if (!concurrentInserts) {
91 for (
int i = 0; i < num_rows; i++) {
92 final String integer_val = Integer.toString(i);
93 final String small_val = Integer.toString(i % 128);
94 final String fp_val = Double.toString(i * 1.1);
95 final String deci_val = Double.toString(i + 0.01);
96 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
97 final String values_string = String.join(
" , ",
106 dba.runSql(
"INSERT INTO " + tableName +
" VALUES "
107 +
"(" + values_string +
")");
110 }
catch (Exception e) {
111 logger.error(
"[" + Thread.currentThread().getId() +
"]"
112 +
" Caught Exception: " + e.getMessage(),
119 ArrayList<Thread> threads =
new ArrayList<>();
120 for (
int i = 0; i < num_threads; i++) {
121 logger.info(
"Starting " + i);
122 final int threadId = i;
124 Thread t =
new Thread(
new Runnable() {
127 long tid = Thread.currentThread().getId();
128 String logPrefix =
"[" + tid +
"]";
134 HeavyDBTestClient user = HeavyDBTestClient.getClient(
135 "localhost", 6274, db, dbUser, dbPassword);
137 if (concurrentInserts) {
138 for (
int i = 0; i < num_rows / num_threads; i++) {
139 final String integer_val = Integer.toString(i);
140 final String small_val = Integer.toString(i % 128);
141 final String fp_val = Double.toString(i * 1.1);
142 final String deci_val = Double.toString(i + 0.01);
143 final String str_val =
"'" +
text_values[i % text_values.length] +
"'";
144 final String values_string = String.join(
" , ",
153 user.runSql(
"INSERT INTO " + tableName +
" VALUES "
154 +
"(" + values_string +
")");
158 Random rand =
new Random(tid);
160 sql =
"DELETE FROM " + tableName +
" WHERE x = " + (tid * 2) +
";";
161 logger.info(logPrefix +
" " + sql);
164 sql =
"DELETE FROM " + tableName +
" WHERE y = " + rand.nextInt(num_rows)
166 logger.info(logPrefix +
" " + sql);
169 sql =
"SELECT COUNT(*) FROM " + tableName +
" WHERE x > " + (tid * 2) +
";";
170 logger.info(logPrefix +
" " + sql);
173 sql =
"DELETE FROM " + tableName +
" WHERE str = '"
174 +
text_values[rand.nextInt(text_values.length)] +
"';";
175 logger.info(logPrefix +
" " + sql);
178 sql =
"SELECT * FROM " + tableName +
" WHERE str = '"
179 +
text_values[rand.nextInt(text_values.length)] +
"';";
180 logger.info(logPrefix +
" " + sql);
183 sql =
"DELETE FROM " + tableName +
" WHERE d < " + rand.nextInt(num_rows / 4)
185 logger.info(logPrefix +
" " + sql);
188 sql =
"INSERT INTO " + tableName +
" VALUES "
189 +
"(" + tid +
"," + tid +
"," + tid +
"," + tid +
"," + tid +
","
190 + tid +
"," + tid +
"," + (tid % 2 == 0 ?
"'value_1'" :
"'value_2'")
192 logger.info(logPrefix +
" " + sql);
195 sql =
"DELETE FROM " + tableName +
" WHERE z = " + tid +
";";
196 logger.info(logPrefix +
" " + sql);
199 }
catch (Exception e) {
200 logger.error(logPrefix +
" Caught Exception: " + e.getMessage(), e);
201 exceptions[threadId] = e;
209 for (Thread t : threads) {
213 HeavyDBTestClient dba =
214 HeavyDBTestClient.getClient(
"localhost", 6274, db, dbaUser, dbaPassword);
215 dba.runSql(
"DROP TABLE " + tableName +
";");
217 for (Exception e : exceptions) {
219 logger.error(
"Exception: " + e.getMessage(), e);
static final String[] text_values
Boolean useTemporaryTables_