16 package com.mapd.tests;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 import java.lang.Integer;
23 import java.lang.RuntimeException;
24 import java.lang.String;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Random;
29 import java.util.concurrent.CyclicBarrier;
31 import ai.heavy.thrift.server.TDBException;
34 public final static String
db =
"TestDB",
userName =
"admin",
46 static Random
rand =
new Random();
51 public static int[]
ports = null;
57 File[] files = dir.listFiles();
59 for (File file : files) {
70 String portString = System.getProperty(
"PORT_LIST");
72 if (portString != null) {
73 List<String> portList = Arrays.asList(portString.split(
","));
74 if (portList.size() > 0) {
75 retPorts =
new int[portList.size()];
76 for (
int i = 0; i < portList.size(); ++i) {
77 retPorts[i] = Integer.parseInt(portList.get(i));
82 retPorts =
new int[1];
89 String propertyString = System.getProperty(
"NUM_THREADS");
90 if (propertyString == null) {
93 return Integer.parseInt(propertyString);
99 String propertyString = System.getProperty(
"NUM_ITERATIONS");
100 if (propertyString == null) {
103 return Integer.parseInt(propertyString);
109 String propertyString = System.getProperty(
"ENABLE_HEAVY_CONNECT");
110 if (propertyString == null) {
113 return Boolean.parseBoolean(propertyString);
120 String propertyString = System.getProperty(
"ENABLE_MONITOR_THREAD");
121 if (propertyString == null) {
124 return Boolean.parseBoolean(propertyString);
130 String log =
"Config for " +
testName +
":\n{\n ports = {\n";
131 for (
int port :
ports) {
132 log +=
" " + port +
"\n";
142 return new CyclicBarrier(numThreadsToWait,
new Runnable() {
145 logger.info(
"Threads Synched");
152 if (exceptionTexts.size() > 0) {
153 String errors =
"\n";
154 for (String s : exceptionTexts) {
157 logger.error(
"Found exceptions:" + errors);
162 return ports[rand.nextInt(ports.length)];
166 public abstract void runTests(
final List<SqlCommandThread[]> tests) throws Exception;
167 public abstract
void setUpTests() throws Exception;
168 public abstract
void cleanUpTests(final List<SqlCommandThread[]> tests)
174 throw new RuntimeException(
"Derived test has not set a test name");
177 throw new RuntimeException(
"Derived test has not initialized logger");
193 logger.info(
" " + sql);
209 int finishedThreads = 0;
210 int totalThreads = monitoredThreads.size() *
numThreads;
211 while (finishedThreads < totalThreads) {
215 if (thread.getState() == Thread.State.TERMINATED) {
220 logger.info(
"Threads running: " + (totalThreads - finishedThreads));
223 }
catch (Exception e) {
224 logger.error(
"Monitoring thread: " + e.getMessage());
240 final List<String> exceptions,
246 this.threadName = threadName +
"[" + port +
"][" + threadId +
"]";
247 this.expectedExceptionTexts = exceptions;
254 final List<String> exceptions,
272 for (
int iteration = 0; iteration <
iterations; ++iteration) {
274 logger.info(
" " +
threadName +
"[" + iteration +
"]: " + query);
277 }
catch (TDBException e) {
278 boolean foundExpected =
false;
280 if (e.error_msg.contains(exceptionText)) {
281 foundExpected =
true;
284 if (!foundExpected) {
290 }
catch (TDBException e) {
291 logger.error(
" " +
threadName +
": caught exception - " + e.error_msg);
292 exceptionTexts.add(
threadName +
": " + e.error_msg);
293 }
catch (Exception e) {
294 logger.error(
" " +
threadName +
": caught exception - " + e.getMessage());
295 exceptionTexts.add(
threadName +
": " + e.getMessage());
static int getNumIterations()
abstract void setUpTests()
void runAndLog(HeavyDBTestClient client, String sql)
static final String localhost
static String getConfig()
static final String password
final List< String > queries
static boolean deleteDirectory(File dir)
static int getRandomPort()
List< SqlCommandThread[]> monitoredThreads
MonitoringThread(List< SqlCommandThread[]> monitoredThreads, int numThreads)
static boolean enableMonitorThread
static void printErrors(ArrayList< String > exceptionTexts)
static boolean getEnableMonitorThread()
static boolean enableHeavyConnect
static CyclicBarrier createBarrier(int numThreadsToWait)
final List< String > cleanUpQueries
static int getNumThreads()
ArrayList< String > exceptionTexts
abstract List< SqlCommandThread[]> createTestThreads()
static final String userName
final List< String > expectedExceptionTexts
abstract void runTests(final List< SqlCommandThread[]> tests)
SqlCommandThread(final String threadName, final List< String > queries, int threadId, int port, int iterations, final List< String > exceptions, final List< String > cleanUpQueries)
static boolean getEnableHeavyConnect()
static final String defaultDb
SqlCommandThread(final String threadName, final List< String > queries, int threadId, final List< String > exceptions, final List< String > cleanUpQueries)
static final boolean defaultEnableHeavyConnect
static final boolean defaultEnableMonitorThread
abstract void cleanUpTests(final List< SqlCommandThread[]> tests)
HeavyDBTestClient getAdminClient(String db)
static final int defaultNumIterations
static final int defaultPort
static final int defaultNumThreads