OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.tests.DumpRestoreConcurrencyTest Class Reference
+ Collaboration diagram for com.mapd.tests.DumpRestoreConcurrencyTest:

Classes

class  ThreadDbDumpRestoreQueries
 

Public Member Functions

void testConcurrency () throws Exception
 

Static Public Member Functions

static void main (String[] args) throws Exception
 

Package Functions

List< String > getDumpRestoreQueries (String table_identifier)
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(DumpRestoreConcurrencyTest.class)
 
static String tar_ball_path_prefix = "/tmp/_Orz__"
 

Private Member Functions

void deleteFileIfExist (String file)
 
void runTest () throws Exception
 
void runSqlAsUser (String sql, HeavyDBTestClient user, int threadId) throws Exception
 

Detailed Description

Definition at line 28 of file DumpRestoreConcurrencyTest.java.

Member Function Documentation

void com.mapd.tests.DumpRestoreConcurrencyTest.deleteFileIfExist ( String  file)
inlineprivate

Definition at line 42 of file DumpRestoreConcurrencyTest.java.

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

42  {
43  try {
44  Files.deleteIfExists((new File(file)).toPath());
45  } catch (Exception e) {
46  logger.error("While Deleting Archives Caught Exception: " + e.getMessage(), e);
47  }
48  }

+ Here is the caller graph for this function:

List<String> com.mapd.tests.DumpRestoreConcurrencyTest.getDumpRestoreQueries ( String  table_identifier)
inlinepackage

Definition at line 53 of file DumpRestoreConcurrencyTest.java.

References com.mapd.tests.DumpRestoreConcurrencyTest.tar_ball_path_prefix.

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

53  {
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);",
58  "DUMP TABLE " + table_identifier + " TO '" + tar_ball_path_prefix + "_"
59  + table_identifier + "';",
60  "RESTORE TABLE restored_" + table_identifier + " FROM '"
61  + tar_ball_path_prefix + "_" + table_identifier + "';");
62  }

+ Here is the caller graph for this function:

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

Definition at line 31 of file DumpRestoreConcurrencyTest.java.

31  {
32  DumpRestoreConcurrencyTest test = new DumpRestoreConcurrencyTest();
33  test.testConcurrency();
34  }
void com.mapd.tests.DumpRestoreConcurrencyTest.runSqlAsUser ( String  sql,
HeavyDBTestClient  user,
int  threadId 
) throws Exception
inlineprivate

Definition at line 128 of file DumpRestoreConcurrencyTest.java.

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

129  {
130  logger.info(threadId + " " + sql);
131  user.runSql(sql);
132  }

+ Here is the caller graph for this function:

void com.mapd.tests.DumpRestoreConcurrencyTest.runTest ( ) throws Exception
inlineprivate

Definition at line 64 of file DumpRestoreConcurrencyTest.java.

References com.mapd.tests.DumpRestoreConcurrencyTest.ThreadDbDumpRestoreQueries.archive, com.mapd.tests.DumpRestoreConcurrencyTest.deleteFileIfExist(), com.mapd.tests.DumpRestoreConcurrencyTest.getDumpRestoreQueries(), com.mapd.tests.DumpRestoreConcurrencyTest.ThreadDbDumpRestoreQueries.queries, com.mapd.tests.DumpRestoreConcurrencyTest.runSqlAsUser(), and com.mapd.tests.DumpRestoreConcurrencyTest.tar_ball_path_prefix.

Referenced by com.mapd.tests.DumpRestoreConcurrencyTest.testConcurrency().

64  {
65  List<ThreadDbDumpRestoreQueries> queriesPerThread =
66  new ArrayList<ThreadDbDumpRestoreQueries>(Arrays.asList(
67  new ThreadDbDumpRestoreQueries(
69  new ThreadDbDumpRestoreQueries(
71  new ThreadDbDumpRestoreQueries(
73  new ThreadDbDumpRestoreQueries(
75  new ThreadDbDumpRestoreQueries(
77 
78  final int num_threads = queriesPerThread.size();
79  Exception[] exceptions = new Exception[num_threads];
80  Thread[] threads = new Thread[num_threads];
81 
82  // Use a barrier here to synchronize the start of each competing thread and make
83  // sure there is a race condition. The barrier ensures no thread will run until they
84  // are all created and waiting for the barrier to complete.
85  final CyclicBarrier barrier = new CyclicBarrier(
86  num_threads, () -> { logger.info("Barrier acquired. Starting queries..."); });
87 
88  for (int i = 0; i < queriesPerThread.size(); i++) {
89  final ThreadDbDumpRestoreQueries threadQueries = queriesPerThread.get(i);
90  final int threadId = i;
91  threads[threadId] = new Thread(() -> {
92  try {
93  logger.info("Starting thread[" + threadId + "]");
94  HeavyDBTestClient user = HeavyDBTestClient.getClient(
95  "localhost", 6274, "heavyai", "admin", "HyperInteractive");
96  deleteFileIfExist(threadQueries.archive);
97  barrier.await();
98  for (final String query : threadQueries.queries) {
99  runSqlAsUser(query, user, threadId);
100  }
101  logger.info("Finished thread[" + threadId + "]");
102  } catch (Exception e) {
103  logger.error("Thread[" + threadId + "] Caught Exception: " + e.getMessage(), e);
104  exceptions[threadId] = e;
105  }
106  });
107  threads[threadId].start();
108  }
109 
110  for (Thread t : threads) {
111  t.join();
112  }
113 
114  // clean up archive files
115  for (int i = 0; i < queriesPerThread.size(); i++) {
116  final ThreadDbDumpRestoreQueries threadQueries = queriesPerThread.get(i);
117  deleteFileIfExist(threadQueries.archive);
118  }
119 
120  for (Exception e : exceptions) {
121  if (e != null) {
122  logger.error("Exception: " + e.getMessage(), e);
123  throw e;
124  }
125  }
126  }
List< String > getDumpRestoreQueries(String table_identifier)
void runSqlAsUser(String sql, HeavyDBTestClient user, int threadId)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 36 of file DumpRestoreConcurrencyTest.java.

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

36  {
37  logger.info("DumpRestoreConcurrencyTest()");
38  runTest();
39  logger.info("DumpRestoreConcurrencyTest() done");
40  }

+ Here is the call graph for this function:

Member Data Documentation

final Logger com.mapd.tests.DumpRestoreConcurrencyTest.logger = LoggerFactory.getLogger(DumpRestoreConcurrencyTest.class)
staticpackage

Definition at line 29 of file DumpRestoreConcurrencyTest.java.

String com.mapd.tests.DumpRestoreConcurrencyTest.tar_ball_path_prefix = "/tmp/_Orz__"
staticpackage

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