This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push:
new 8d57fdf PHOENIX-5825 Remove PhoenixCanaryTool and CanaryTestResult
from phoenix repo
8d57fdf is described below
commit 8d57fdfb5738548012cee7120ac1c5f0192ffcbf
Author: Istvan Toth <[email protected]>
AuthorDate: Wed Apr 8 10:49:34 2020 +0200
PHOENIX-5825 Remove PhoenixCanaryTool and CanaryTestResult from phoenix repo
also
* remove related tests
* remove argparse4j dependency
---
phoenix-core/pom.xml | 7 -
.../org/apache/phoenix/tool/CanaryTestResult.java | 86 -----
.../org/apache/phoenix/tool/PhoenixCanaryTool.java | 427 ---------------------
.../tool/ParameterizedPhoenixCanaryToolIT.java | 280 --------------
.../apache/phoenix/tool/PhoenixCanaryToolTest.java | 89 -----
5 files changed, 889 deletions(-)
diff --git a/phoenix-core/pom.xml b/phoenix-core/pom.xml
index 5728285..700fe8c 100644
--- a/phoenix-core/pom.xml
+++ b/phoenix-core/pom.xml
@@ -29,7 +29,6 @@
<properties>
<top.dir>${project.basedir}/..</top.dir>
- <argparse4j.version>0.8.1</argparse4j.version>
</properties>
<build>
@@ -292,12 +291,6 @@
<artifactId>sqlline</artifactId>
</dependency>
<dependency>
- <groupId>net.sourceforge.argparse4j</groupId>
- <artifactId>argparse4j</artifactId>
- <version>${argparse4j.version}</version>
- </dependency>
-
- <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/tool/CanaryTestResult.java
b/phoenix-core/src/main/java/org/apache/phoenix/tool/CanaryTestResult.java
deleted file mode 100644
index b72439c..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/tool/CanaryTestResult.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.tool;
-
-public class CanaryTestResult {
-
- private boolean isSuccessful;
- private long startTime;
- private long executionTime;
- private String message;
- private String testName;
- private String timestamp;
- private Object miscellaneous;
-
- public Object getMiscellaneous() {
- return miscellaneous;
- }
-
- public void setMiscellaneous(Object miscellaneous) {
- this.miscellaneous = miscellaneous;
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public void setStartTime(long startTime) {
- this.startTime = startTime;
- }
-
- public String getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(String timestamp) {
- this.timestamp = timestamp;
- }
-
- public boolean isSuccessful() {
- return isSuccessful;
- }
-
- public void setSuccessful(boolean successful) {
- isSuccessful = successful;
- }
-
- public long getExecutionTime() {
- return executionTime;
- }
-
- public void setExecutionTime(long executionTime) {
- this.executionTime = executionTime;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getTestName() {
- return testName;
- }
-
- public void setTestName(String testName) {
- this.testName = testName;
- }
-
-}
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/tool/PhoenixCanaryTool.java
b/phoenix-core/src/main/java/org/apache/phoenix/tool/PhoenixCanaryTool.java
deleted file mode 100644
index 2310d9f..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/tool/PhoenixCanaryTool.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.tool;
-
-import com.google.common.base.Throwables;
-import com.google.common.io.Files;
-import com.google.common.util.concurrent.SimpleTimeLimiter;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import net.sourceforge.argparse4j.ArgumentParsers;
-import net.sourceforge.argparse4j.inf.ArgumentParser;
-import net.sourceforge.argparse4j.inf.ArgumentParserException;
-import net.sourceforge.argparse4j.inf.Namespace;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.RetryCounter;
-import org.apache.hadoop.util.Tool;
-import org.apache.hadoop.util.ToolRunner;
-import org.apache.phoenix.util.EnvironmentEdgeManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A Canary Tool to perform synthetic tests for Phoenix
- * It assumes that TEST.PQSTEST or the schema.table passed in the argument
- * is already present as following command
- * CREATE TABLE IF NOT EXISTS TEST.PQSTEST (mykey INTEGER NOT NULL
- * PRIMARY KEY, mycolumn VARCHAR, insert_date TIMESTAMP);
- *
- */
-public class PhoenixCanaryTool extends Configured implements Tool {
-
- private static String TEST_SCHEMA_NAME = "TEST";
- private static String TEST_TABLE_NAME = "PQSTEST";
- private static String FQ_TABLE_NAME = "TEST.PQSTEST";
- private static Timestamp timestamp;
- private static final int MAX_CONNECTION_ATTEMPTS = 5;
- private final int FIRST_TIME_RETRY_TIMEOUT = 5000;
- private Sink sink = new StdOutSink();
- public static final String propFileName =
"phoenix-canary-file-sink.properties";
-
- /**
- * Base class for a Canary Test
- */
- private abstract static class CanaryTest {
-
- CanaryTestResult result = new CanaryTestResult();
-
- Connection connection = null;
-
- private void onCreate(Connection connection) {
- result.setTimestamp(getCurrentTimestamp());
- result.setStartTime(EnvironmentEdgeManager.currentTimeMillis());
- this.connection = connection;
- }
-
- abstract void onExecute() throws Exception;
-
- private void onExit() {
- result.setExecutionTime(EnvironmentEdgeManager.currentTimeMillis()
-
- result.getStartTime());
- }
-
- CanaryTestResult runTest(Connection connection) {
- try {
- onCreate(connection);
- onExecute();
- result.setSuccessful(true);
- result.setMessage("Test " + result.getTestName() + "
successful");
- } catch (Exception e) {
- result.setSuccessful(false);
- result.setMessage(Throwables.getStackTraceAsString(e));
- } finally {
- onExit();
- }
- return result;
- }
- }
-
- static class UpsertTableTest extends CanaryTest {
- void onExecute() throws Exception {
- result.setTestName("upsertTable");
- // Insert data
- timestamp = new
Timestamp(EnvironmentEdgeManager.currentTimeMillis());
- String stmt = "UPSERT INTO " + FQ_TABLE_NAME
- + "(mykey, mycolumn, insert_date) VALUES (?, ?, ?)";
- PreparedStatement ps = connection.prepareStatement(stmt);
- ps.setInt(1, 1);
- ps.setString(2, "Hello World");
- ps.setTimestamp(3, timestamp);
- ps.executeUpdate();
- connection.commit();
- }
- }
-
- static class ReadTableTest extends CanaryTest {
- void onExecute() throws Exception {
- result.setTestName("readTable");
- PreparedStatement ps = connection.prepareStatement("SELECT * FROM "
- + FQ_TABLE_NAME+" WHERE INSERT_DATE = ?");
- ps.setTimestamp(1,timestamp);
- ResultSet rs = ps.executeQuery();
-
- int totalRows = 0;
- while (rs.next()) {
- totalRows += 1;
- Integer myKey = rs.getInt(1);
- String myColumn = rs.getString(2);
- if (myKey != 1 || !myColumn.equals("Hello World")) {
- throw new Exception("Retrieved values do not " +
- "match the inserted values");
- }
- }
- if (totalRows != 1) {
- throw new Exception(totalRows + " rows fetched instead of just
one.");
- }
- ps.close();
- rs.close();
- }
- }
-
- /**
- * Sink interface used by the canary to output information
- */
- public interface Sink {
- List<CanaryTestResult> getResults();
-
- void updateResults(CanaryTestResult result);
-
- void publishResults() throws Exception;
-
- void clearResults();
- }
-
- public static class StdOutSink implements Sink {
- private List<CanaryTestResult> results = new ArrayList<>();
-
- @Override
- public void updateResults(CanaryTestResult result) {
- results.add(result);
- }
-
- @Override
- public List<CanaryTestResult> getResults() {
- return results;
- }
-
- @Override
- public void publishResults() {
-
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String resultJson = gson.toJson(results);
- System.out.println(resultJson);
- }
-
- @Override
- public void clearResults() {
- results.clear();
- }
- }
-
- /**
- * Implementation of File Out Sink
- */
- public static class FileOutSink implements Sink {
- private List<CanaryTestResult> results = new ArrayList<>();
- File dir;
- String logfileName;
-
- public FileOutSink() throws Exception {
- Properties prop = new Properties();
- InputStream input =
ClassLoader.getSystemResourceAsStream(propFileName);
- if (input == null) {
- throw new Exception("Cannot load " + propFileName + " file for
" + "FileOutSink.");
- }
- prop.load(input);
- logfileName = prop.getProperty("file.name");
- dir = new File(prop.getProperty("file.location"));
- dir.mkdirs();
- }
-
- @Override
- public void updateResults(CanaryTestResult result) {
- results.add(result);
- }
-
- @Override
- public List<CanaryTestResult> getResults() {
- return results;
- }
-
- @Override
- public void publishResults() throws Exception {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String resultJson = gson.toJson(results);
- String fileName = logfileName + "-" + new
SimpleDateFormat("yyyy.MM.dd.HH" + ".mm" +
- ".ss").format(new Date()) + ".log";
- File file = new File(dir, fileName);
- Files.write(Bytes.toBytes(resultJson), file);
- }
-
- @Override
- public void clearResults() {
- results.clear();
- }
- }
-
- private static final Logger LOGGER =
LoggerFactory.getLogger(PhoenixCanaryTool.class);
-
- private static String getCurrentTimestamp() {
- return new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.ms").format(new
Date());
- }
-
- private static Namespace parseArgs(String[] args) {
-
- ArgumentParser parser = ArgumentParsers.newFor("Phoenix Canary Test
Tool").build()
- .description("Phoenix Canary Test Tool");
-
- parser.addArgument("--hostname",
"-hn").type(String.class).nargs("?").help("Hostname on "
- + "which Phoenix is running.");
-
- parser.addArgument("--port",
"-p").type(String.class).nargs("?").help("Port on " +
- "which Phoenix is running.");
-
- parser.addArgument("--constring",
"-cs").type(String.class).nargs("?").help("Pass an " +
- "explicit connection String to connect to Phoenix. " +
- "default:
jdbc:phoenix:thin:serialization=PROTOBUF;url=[hostName:port]");
-
- parser.addArgument("--timeout",
"-t").type(String.class).nargs("?").setDefault("60").help
- ("Maximum time for which the app should run before returning
error. default:" + "" +
- " 60 sec");
-
- parser.addArgument("--testschema",
"-ts").type(String.class).nargs("?").setDefault
- (TEST_SCHEMA_NAME).help("Custom name for the test table. " +
"default: " +
- TEST_SCHEMA_NAME);
-
- parser.addArgument("--testtable",
"-tt").type(String.class).nargs("?").setDefault
- (TEST_TABLE_NAME).help("Custom name for the test table." + "
default: " +
- TEST_TABLE_NAME);
-
- parser.addArgument("--logsinkclass",
"-lsc").type(String.class).nargs("?").setDefault
- ("org.apache.phoenix.tool.PhoenixCanaryTool$StdOutSink").help
- ("Path to a Custom implementation for log sink class. default:
stdout");
-
- Namespace res = null;
- try {
- res = parser.parseKnownArgs(args, null);
- } catch (ArgumentParserException e) {
- parser.handleError(e);
- }
- return res;
- }
-
- private CanaryTestResult appInfo = new CanaryTestResult();
- private Connection connection = null;
-
- @Override
- public int run(String[] args) throws Exception {
-
- try {
- Namespace cArgs = parseArgs(args);
- if (cArgs == null) {
- LOGGER.error("Argument parsing failed.");
- throw new RuntimeException("Argument parsing failed");
- }
-
- final String hostName = cArgs.getString("hostname");
- final String port = cArgs.getString("port");
- final String timeout = cArgs.getString("timeout");
- final String conString = cArgs.getString("constring");
- final String testSchemaName = cArgs.getString("testschema");
- final String testTableName = cArgs.getString("testtable");
- final String logSinkClass = cArgs.getString("logsinkclass");
-
- TEST_TABLE_NAME = testTableName;
- TEST_SCHEMA_NAME = testSchemaName;
- FQ_TABLE_NAME = testSchemaName + "." + testTableName;
-
- // Check if at least one from host+port or con string is provided.
- if ((hostName == null || port == null) && conString == null) {
- throw new RuntimeException("Provide at least one from
host+port or constring");
- }
-
- int timeoutVal = Integer.parseInt(timeout);
-
- // Dynamically load a class for sink
- sink = (Sink)
ClassLoader.getSystemClassLoader().loadClass(logSinkClass).newInstance();
-
- long startTime = EnvironmentEdgeManager.currentTimeMillis();
-
- String connectionURL = (conString != null) ? conString :
- "jdbc:phoenix:thin:serialization=PROTOBUF;url=" + hostName
+ ":" + port;
-
- appInfo.setTestName("appInfo");
- appInfo.setMiscellaneous(connectionURL);
-
- connection = getConnectionWithRetry(connectionURL);
-
- if (connection == null) {
- LOGGER.error("Failed to get connection after multiple retries;
the connection is null");
- }
-
- SimpleTimeLimiter limiter = new SimpleTimeLimiter();
-
- limiter.callWithTimeout(new Callable<Void>() {
-
- public Void call() {
-
- sink.clearResults();
-
- // Execute tests
- LOGGER.info("Starting UpsertTableTest");
- sink.updateResults(new
UpsertTableTest().runTest(connection));
-
- LOGGER.info("Starting ReadTableTest");
- sink.updateResults(new
ReadTableTest().runTest(connection));
- return null;
-
- }
- }, timeoutVal, TimeUnit.SECONDS, true);
-
- long estimatedTime = EnvironmentEdgeManager.currentTimeMillis() -
startTime;
-
- appInfo.setExecutionTime(estimatedTime);
- appInfo.setSuccessful(true);
-
- } catch (Exception e) {
- LOGGER.error(Throwables.getStackTraceAsString(e));
- appInfo.setMessage(Throwables.getStackTraceAsString(e));
- appInfo.setSuccessful(false);
-
- } finally {
- sink.updateResults(appInfo);
- sink.publishResults();
- connection.close();
- }
-
- return 0;
- }
-
- private Connection getConnectionWithRetry(String connectionURL) {
- Connection connection=null;
- try{
- connection = getConnectionWithRetry(connectionURL, true);
- } catch (Exception e) {
- LOGGER.info("Failed to get connection with namespace enabled", e);
- try {
- connection = getConnectionWithRetry(connectionURL, false);
- } catch (Exception ex) {
- LOGGER.info("Failed to get connection without namespace
enabled", ex);
- }
- }
- return connection;
- }
-
- private Connection getConnectionWithRetry(String connectionURL, boolean
namespaceFlag)
- throws Exception {
- Properties connProps = new Properties();
- Connection connection = null;
-
- connProps.setProperty("phoenix.schema.mapSystemTablesToNamespace",
String.valueOf(namespaceFlag));
- connProps.setProperty("phoenix.schema.isNamespaceMappingEnabled",
String.valueOf(namespaceFlag));
-
- RetryCounter retrier = new RetryCounter(MAX_CONNECTION_ATTEMPTS,
- FIRST_TIME_RETRY_TIMEOUT, TimeUnit.MILLISECONDS);
- LOGGER.info("Trying to get the connection with "
- + retrier.getMaxAttempts() + " attempts with "
- + "connectionURL :" + connectionURL
- + "connProps :" + connProps);
- while (retrier.shouldRetry()) {
- try {
- connection = DriverManager.getConnection(connectionURL,
connProps);
- } catch (SQLException e) {
- LOGGER.info("Trying to establish connection with "
- + retrier.getAttemptTimes() + " attempts", e);
- }
- if (connection != null) {
- LOGGER.info("Successfully established connection within "
- + retrier.getAttemptTimes() + " attempts");
- break;
- }
- retrier.sleepUntilNextRetry();
- }
- return connection;
- }
-
- public static void main(final String[] args) {
- try {
- LOGGER.info("Starting Phoenix Canary Test tool...");
- ToolRunner.run(new PhoenixCanaryTool(), args);
- } catch (Exception e) {
- LOGGER.error("Error in running Phoenix Canary Test tool. " + e);
- }
- LOGGER.info("Exiting Phoenix Canary Test tool...");
- }
-}
diff --git
a/phoenix-core/src/test/java/org/apache/phoenix/tool/ParameterizedPhoenixCanaryToolIT.java
b/phoenix-core/src/test/java/org/apache/phoenix/tool/ParameterizedPhoenixCanaryToolIT.java
deleted file mode 100644
index ead0d83..0000000
---
a/phoenix-core/src/test/java/org/apache/phoenix/tool/ParameterizedPhoenixCanaryToolIT.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.phoenix.tool;
-
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
-import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.apache.phoenix.tool.PhoenixCanaryTool.propFileName;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(Parameterized.class)
-@Category(NeedsOwnMiniClusterTest.class)
-public class ParameterizedPhoenixCanaryToolIT extends BaseTest {
-
- private static final Logger LOGGER =
-
LoggerFactory.getLogger(ParameterizedPhoenixCanaryToolIT.class);
- private static final String stdOutSink
- =
"org.apache.phoenix.tool.PhoenixCanaryTool$StdOutSink";
- private static final String fileOutSink
- =
"org.apache.phoenix.tool.PhoenixCanaryTool$FileOutSink";
-
- private static Map<String, String> serverProps =
Maps.newHashMapWithExpectedSize(2);
- private static Map<String, String> clientProps =
Maps.newHashMapWithExpectedSize(2);
- private static String connString = "";
- private static Properties canaryProp = new Properties();
- private static Connection connection = null;
- private boolean isNamespaceEnabled;
- private boolean isPositiveTestType;
- private List<String> cmd = new ArrayList<>();
- private String resultSinkOption;
- private ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- public ParameterizedPhoenixCanaryToolIT(boolean isPositiveTestType,
- boolean isNamespaceEnabled, String resultSinkOption) {
- this.isPositiveTestType = isPositiveTestType;
- this.isNamespaceEnabled = isNamespaceEnabled;
- this.resultSinkOption = resultSinkOption;
- }
-
- @Parameterized.Parameters(name =
"ParameterizedPhoenixCanaryToolIT_isPositiveTestType={0}," +
- "isNamespaceEnabled={1},resultSinkOption={2}")
- public static Collection parametersList() {
- return Arrays.asList(new Object[][] {
- {true, true, stdOutSink},
- {true, true, fileOutSink},
- {false, true, stdOutSink},
- {false, true, fileOutSink},
- {true, false, stdOutSink},
- {true, false, fileOutSink},
- {false, false, stdOutSink},
- {false, false, fileOutSink}
- });
- }
-
- @Before
- public void setup() throws Exception {
- String createSchema;
- String createTable;
-
- if(needsNewCluster()) {
- setClientSideNamespaceProperties();
- setServerSideNamespaceProperties();
- tearDownMiniClusterAsync(1);
- setUpTestDriver(new
ReadOnlyProps(serverProps.entrySet().iterator()),
- new
ReadOnlyProps(clientProps.entrySet().iterator()));
- LOGGER.info("New cluster is spinned up with test
parameters " +
- "isPositiveTestType" +
this.isPositiveTestType +
- "isNamespaceEnabled" +
this.isNamespaceEnabled +
- "resultSinkOption" +
this.resultSinkOption);
- connString = BaseTest.getUrl();
- connection = getConnection();
- }
-
- if (this.isNamespaceEnabled) {
- createSchema = "CREATE SCHEMA IF NOT EXISTS TEST";
- connection.createStatement().execute(createSchema);
- }
- createTable = "CREATE TABLE IF NOT EXISTS TEST.PQSTEST " +
- "(mykey INTEGER NOT NULL
PRIMARY KEY, mycolumn VARCHAR," +
- " insert_date TIMESTAMP)";
- connection.createStatement().execute(createTable);
- cmd.add("--constring");
- cmd.add(connString);
- cmd.add("--logsinkclass");
- cmd.add(this.resultSinkOption);
- if (this.resultSinkOption.contains(stdOutSink)) {
- System.setOut(new java.io.PrintStream(out));
- } else {
- loadCanaryPropertiesFile(canaryProp);
- }
- }
-
- private boolean needsNewCluster() {
- if (connection == null) {
- return true;
- }
- if
(!clientProps.get(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE)
-
.equalsIgnoreCase(String.valueOf(this.isNamespaceEnabled))) {
- return true;
- }
- return false;
- }
-
- private void setClientSideNamespaceProperties() {
-
-
clientProps.put(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE,
- String.valueOf(this.isNamespaceEnabled));
-
- clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED,
- String.valueOf(this.isNamespaceEnabled));
- }
-
- private Connection getConnection() throws SQLException {
- Properties props = new Properties();
-
props.setProperty(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE,
- String.valueOf(this.isNamespaceEnabled));
-
- props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED,
- String.valueOf(this.isNamespaceEnabled));
- return DriverManager.getConnection(connString, props);
- }
-
- void setServerSideNamespaceProperties() {
- serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED,
- String.valueOf(this.isNamespaceEnabled));
-
serverProps.put(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE,
- String.valueOf(this.isNamespaceEnabled));
- }
-
- /*
- * This test runs in the test suit with
- * combination of parameters provided.
- * It tests the tool in positive type where test expects to pass
- * and negative type where test expects to fail.
- */
- @Test
- public void phoenixCanaryToolTest() throws SQLException, IOException {
- if (!isPositiveTestType) {
- dropTestTable();
- }
- PhoenixCanaryTool.main(cmd.toArray(new String[cmd.size()]));
- Boolean result = getAggregatedResult();
- if (isPositiveTestType) {
- assertTrue(result);
- } else {
- assertFalse(result);
- }
- }
-
- private Boolean getAggregatedResult() throws IOException {
- HashMap<String, Boolean> resultsMap;
- Boolean result = true;
- resultsMap = parsePublishedResults();
- for (Boolean b : resultsMap.values()) {
- result = result && b;
- }
- return result;
- }
-
- private HashMap<String, Boolean> parsePublishedResults() throws
IOException {
- Gson parser = new Gson();
- CanaryTestResult[] results;
- HashMap<String, Boolean> resultsMap = new HashMap<>();
-
- if (this.resultSinkOption.contains(fileOutSink)) {
- File resultFile = getTestResultsFile();
- results = parser.fromJson(new FileReader(resultFile),
- CanaryTestResult[].class);
- } else {
- String result = out.toString();
- results = parser.fromJson(result,
CanaryTestResult[].class);
- }
- for (CanaryTestResult r : results) {
- resultsMap.put(r.getTestName(), r.isSuccessful());
- }
- return resultsMap;
- }
-
- private File getTestResultsFile() {
- File[] files = getLogFileList();
- return files[0];
- }
-
- @After
- public void teardown() throws SQLException {
- if (this.isNamespaceEnabled) {
- dropTestTableAndSchema();
- } else {
- dropTestTable();
- }
- if (this.resultSinkOption.contains(fileOutSink)) {
- deleteResultSinkFile();
- }
- }
-
- private void deleteResultSinkFile() {
- File[] files = getLogFileList();
- for (final File file : files) {
- if (!file.delete()) {
- System.err.println("Can't remove " +
file.getAbsolutePath());
- }
- }
- }
-
- private File[] getLogFileList() {
- File dir = new File(canaryProp.getProperty("file.location"));
- return dir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".log");
- }
- });
- }
-
- private void loadCanaryPropertiesFile(Properties prop) {
- InputStream input =
ClassLoader.getSystemResourceAsStream(propFileName);
- try {
- prop.load(input);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- private void dropTestTable() throws SQLException {
- String dropTable = "DROP TABLE IF EXISTS TEST.PQSTEST";
- connection.createStatement().execute(dropTable);
- }
-
- private void dropTestTableAndSchema() throws SQLException {
- dropTestTable();
- String dropSchema = "DROP SCHEMA IF EXISTS TEST";
- connection.createStatement().execute(dropSchema);
- }
-
-}
diff --git
a/phoenix-core/src/test/java/org/apache/phoenix/tool/PhoenixCanaryToolTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/tool/PhoenixCanaryToolTest.java
deleted file mode 100644
index 94229c2..0000000
---
a/phoenix-core/src/test/java/org/apache/phoenix/tool/PhoenixCanaryToolTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.tool;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import static org.mockito.Mockito.when;
-import org.mockito.MockitoAnnotations;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-public class PhoenixCanaryToolTest {
-
- @Mock
- private Connection connection;
-
- @Mock
- private Statement statement;
-
- @Mock
- private PreparedStatement ps;
-
- @Mock
- private ResultSet rs;
-
- @Mock
- private DatabaseMetaData dbm;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void upsertTableTest() throws Exception {
- when(connection.createStatement()).thenReturn(statement);
- when(connection.prepareStatement(Mockito.anyString())).thenReturn(ps);
- when(statement.executeUpdate(Mockito.anyString())).thenReturn(1);
- CanaryTestResult result = new
PhoenixCanaryTool.UpsertTableTest().runTest(connection);
- assertEquals(true, result.isSuccessful());
- assertEquals("Test upsertTable successful", result.getMessage());
- }
-
- @Test
- public void readTableTest() throws Exception {
- when(connection.prepareStatement(Mockito.anyString())).thenReturn(ps);
- when(ps.executeQuery()).thenReturn(rs);
- when(rs.next()).thenReturn(true).thenReturn(false);
- when(rs.getInt(1)).thenReturn(1);
- when(rs.getString(2)).thenReturn("Hello World");
- CanaryTestResult result = new
PhoenixCanaryTool.ReadTableTest().runTest(connection);
- assertEquals(true, result.isSuccessful());
- assertEquals("Test readTable successful", result.getMessage());
- }
-
- @Test
- public void failTest() throws Exception {
- when(connection.prepareStatement(Mockito.anyString())).thenReturn(ps);
- when(ps.executeQuery()).thenReturn(rs);
- when(rs.getInt(1)).thenReturn(3);
- when(rs.getString(2)).thenReturn("Incorrect data");
- when(rs.next()).thenReturn(true).thenReturn(false);
- CanaryTestResult result = new
PhoenixCanaryTool.ReadTableTest().runTest(connection);
- assertEquals(false, result.isSuccessful());
- assert (result.getMessage().contains("Retrieved values do not match
the inserted values"));
- }
-}
\ No newline at end of file