16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 import java.nio.file.Files;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.concurrent.CyclicBarrier;
29 final static Logger
logger = LoggerFactory.getLogger(DumpRestoreConcurrencyTest.class);
31 public static void main(String[]
args)
throws Exception {
33 test.testConcurrency();
37 logger.info(
"DumpRestoreConcurrencyTest()");
39 logger.info(
"DumpRestoreConcurrencyTest() done");
44 Files.deleteIfExists((
new File(file)).toPath());
45 }
catch (Exception e) {
46 logger.error(
"While Deleting Archives Caught Exception: " + e.getMessage(), e);
54 return Arrays.asList(
"DROP TABLE IF EXISTS " + table_identifier +
";",
55 "DROP TABLE IF EXISTS restored_" + table_identifier +
";",
56 "CREATE TABLE " + table_identifier +
" (v INT);",
57 "INSERT INTO " + table_identifier +
" VALUES (1),(2);",
59 + table_identifier +
"';",
60 "RESTORE TABLE restored_" + table_identifier +
" FROM '"
65 List<ThreadDbDumpRestoreQueries> queriesPerThread =
66 new ArrayList<ThreadDbDumpRestoreQueries>(Arrays.asList(
78 final int num_threads = queriesPerThread.size();
79 Exception[] exceptions =
new Exception[num_threads];
80 Thread[] threads =
new Thread[num_threads];
85 final CyclicBarrier barrier =
new CyclicBarrier(
86 num_threads, () -> { logger.info(
"Barrier acquired. Starting queries..."); });
88 for (
int i = 0; i < queriesPerThread.size(); i++) {
90 final int threadId = i;
91 threads[threadId] =
new Thread(() -> {
93 logger.info(
"Starting thread[" + threadId +
"]");
95 "localhost", 6274,
"heavyai",
"admin",
"HyperInteractive");
98 for (
final String query : threadQueries.
queries) {
101 logger.info(
"Finished thread[" + threadId +
"]");
102 }
catch (Exception e) {
103 logger.error(
"Thread[" + threadId +
"] Caught Exception: " + e.getMessage(), e);
104 exceptions[threadId] = e;
107 threads[threadId].start();
110 for (Thread t : threads) {
115 for (
int i = 0; i < queriesPerThread.size(); i++) {
120 for (Exception e : exceptions) {
122 logger.error(
"Exception: " + e.getMessage(), e);
130 logger.info(threadId +
" " + sql);
136 final String archive_file,
final List<String>
queries) {
137 this.archive = archive_file;
List< String > getDumpRestoreQueries(String table_identifier)
static String tar_ball_path_prefix
ThreadDbDumpRestoreQueries(final String archive_file, final List< String > queries)
static final Logger logger
static void main(String[] args)
void runSqlAsUser(String sql, HeavyDBTestClient user, int threadId)
void deleteFileIfExist(String file)
final List< String > queries