未验证 提交 deaa87e3 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #7766 from taosdata/feature/TD-5992

Feature/td 5992 set configure once
...@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS) ...@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver) #INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .) #INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF (TD_MVN_INSTALLED) IF (TD_MVN_INSTALLED)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.34-dist.jar DESTINATION connector/jdbc) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.35-dist.jar DESTINATION connector/jdbc)
ENDIF () ENDIF ()
ELSEIF (TD_DARWIN) ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
......
...@@ -10,6 +10,7 @@ AUX_SOURCE_DIRECTORY(src SRC) ...@@ -10,6 +10,7 @@ AUX_SOURCE_DIRECTORY(src SRC)
IF (TD_LINUX) IF (TD_LINUX)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
# set the static lib name # set the static lib name
ADD_LIBRARY(taos_static STATIC ${SRC}) ADD_LIBRARY(taos_static STATIC ${SRC})
...@@ -21,7 +22,7 @@ IF (TD_LINUX) ...@@ -21,7 +22,7 @@ IF (TD_LINUX)
ADD_LIBRARY(taos SHARED ${SRC}) ADD_LIBRARY(taos SHARED ${SRC})
TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m rt cJson) TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m rt cJson)
IF (TD_LINUX_64) IF (TD_LINUX_64)
TARGET_LINK_LIBRARIES(taos lua) TARGET_LINK_LIBRARIES(taos lua cJson)
ENDIF () ENDIF ()
SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1)
...@@ -36,6 +37,7 @@ IF (TD_LINUX) ...@@ -36,6 +37,7 @@ IF (TD_LINUX)
ELSEIF (TD_DARWIN) ELSEIF (TD_DARWIN)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
# set the static lib name # set the static lib name
ADD_LIBRARY(taos_static STATIC ${SRC}) ADD_LIBRARY(taos_static STATIC ${SRC})
...@@ -59,6 +61,7 @@ ELSEIF (TD_DARWIN) ...@@ -59,6 +61,7 @@ ELSEIF (TD_DARWIN)
ELSEIF (TD_WINDOWS) ELSEIF (TD_WINDOWS)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
CONFIGURE_FILE("${TD_COMMUNITY_DIR}/src/client/src/taos.rc.in" "${TD_COMMUNITY_DIR}/src/client/src/taos.rc") CONFIGURE_FILE("${TD_COMMUNITY_DIR}/src/client/src/taos.rc.in" "${TD_COMMUNITY_DIR}/src/client/src/taos.rc")
...@@ -75,6 +78,7 @@ ELSEIF (TD_WINDOWS) ...@@ -75,6 +78,7 @@ ELSEIF (TD_WINDOWS)
ELSEIF (TD_DARWIN) ELSEIF (TD_DARWIN)
SET(CMAKE_MACOSX_RPATH 1) SET(CMAKE_MACOSX_RPATH 1)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
ADD_LIBRARY(taos_static STATIC ${SRC}) ADD_LIBRARY(taos_static STATIC ${SRC})
TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m lua cJson) TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m lua cJson)
......
...@@ -41,6 +41,14 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp ...@@ -41,6 +41,14 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions
(JNIEnv *, jclass, jint, jstring); (JNIEnv *, jclass, jint, jstring);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: setConfigImp
* Signature: (Ljava/lang/String;)Lcom/taosdata/jdbc/TSDBException;
*/
JNIEXPORT jobject JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setConfigImp
(JNIEnv *, jclass, jstring);
/* /*
* Class: com_taosdata_jdbc_TSDBJNIConnector * Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: getTsCharset * Method: getTsCharset
......
...@@ -200,6 +200,64 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp(JNIEnv *e ...@@ -200,6 +200,64 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp(JNIEnv *e
jniDebug("jni initialized successfully, config directory: %s", configDir); jniDebug("jni initialized successfully, config directory: %s", configDir);
} }
JNIEXPORT jobject createTSDBException(JNIEnv *env, int code, char *msg) {
// find class
jclass exception_clazz = (*env)->FindClass(env, "com/taosdata/jdbc/TSDBException");
// find methods
jmethodID init_method = (*env)->GetMethodID(env, exception_clazz, "<init>", "()V");
jmethodID setCode_method = (*env)->GetMethodID(env, exception_clazz, "setCode", "(I)V");
jmethodID setMessage_method = (*env)->GetMethodID(env, exception_clazz, "setMessage", "(Ljava/lang/String;)V");
// new exception
jobject exception_obj = (*env)->NewObject(env, exception_clazz, init_method);
// set code
(*env)->CallVoidMethod(env, exception_obj, setCode_method, code);
// set message
jstring message = (*env)->NewStringUTF(env, msg);
(*env)->CallVoidMethod(env, exception_obj, setMessage_method, message);
return exception_obj;
}
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: setConfigImp
* Signature: (Ljava/lang/String;)Lcom/taosdata/jdbc/TSDBException;
*/
JNIEXPORT jobject JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setConfigImp(JNIEnv *env, jclass jobj,
jstring config) {
/*
if (config == NULL) {
jniDebug("config value is null");
return -1;
}
const char *cfg = (*env)->GetStringUTFChars(env, config, NULL);
if (!cfg) {
return -1;
}
return 0;
*/
if (config == NULL) {
char *msg = "config value is null";
jniDebug("config value is null");
return createTSDBException(env, -1, msg);
}
const char *cfg = (*env)->GetStringUTFChars(env, config, NULL);
if (!cfg) {
char *msg = "config value is null";
jniDebug("config value is null");
return createTSDBException(env, -1, msg);
}
setConfRet result = taos_set_config(cfg);
int code = result.retCode;
char * msg = result.retMsg;
return createTSDBException(env, code, msg);
}
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv *env, jobject jobj, jint optionIndex, JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv *env, jobject jobj, jint optionIndex,
jstring optionValue) { jstring optionValue) {
if (optionValue == NULL) { if (optionValue == NULL) {
......
...@@ -2,6 +2,7 @@ EXPORTS ...@@ -2,6 +2,7 @@ EXPORTS
taos_init taos_init
taos_cleanup taos_cleanup
taos_options taos_options
taos_set_config
taos_connect taos_connect
taos_connect_auth taos_connect_auth
taos_close taos_close
......
...@@ -50,6 +50,7 @@ int tscLogFileNum = 10; ...@@ -50,6 +50,7 @@ int tscLogFileNum = 10;
static pthread_mutex_t rpcObjMutex; // mutex to protect open the rpc obj concurrently static pthread_mutex_t rpcObjMutex; // mutex to protect open the rpc obj concurrently
static pthread_once_t tscinit = PTHREAD_ONCE_INIT; static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
static pthread_mutex_t setConfMutex = PTHREAD_MUTEX_INITIALIZER;
// pthread_once can not return result code, so result code is set to a global variable. // pthread_once can not return result code, so result code is set to a global variable.
static volatile int tscInitRes = 0; static volatile int tscInitRes = 0;
...@@ -249,6 +250,7 @@ void taos_cleanup(void) { ...@@ -249,6 +250,7 @@ void taos_cleanup(void) {
pthread_mutex_destroy(&rpcObjMutex); pthread_mutex_destroy(&rpcObjMutex);
} }
pthread_mutex_destroy(&setConfMutex);
taosCacheCleanup(tscVgroupListBuf); taosCacheCleanup(tscVgroupListBuf);
tscVgroupListBuf = NULL; tscVgroupListBuf = NULL;
...@@ -437,3 +439,66 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { ...@@ -437,3 +439,66 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
atomic_store_32(&lock, 0); atomic_store_32(&lock, 0);
return ret; return ret;
} }
#include "cJSON.h"
static setConfRet taos_set_config_imp(const char *config){
setConfRet ret = {SET_CONF_RET_SUCC, {0}};
static bool setConfFlag = false;
if (setConfFlag) {
ret.retCode = SET_CONF_RET_ERR_ONLY_ONCE;
strcpy(ret.retMsg, "configuration can only set once");
return ret;
}
taosInitGlobalCfg();
cJSON *root = cJSON_Parse(config);
if (root == NULL){
ret.retCode = SET_CONF_RET_ERR_JSON_PARSE;
strcpy(ret.retMsg, "parse json error");
return ret;
}
int size = cJSON_GetArraySize(root);
if(!cJSON_IsObject(root) || size == 0) {
ret.retCode = SET_CONF_RET_ERR_JSON_INVALID;
strcpy(ret.retMsg, "json content is invalid, must be not empty object");
return ret;
}
if(size >= 1000) {
ret.retCode = SET_CONF_RET_ERR_TOO_LONG;
strcpy(ret.retMsg, "json object size is too long");
return ret;
}
for(int i = 0; i < size; i++){
cJSON *item = cJSON_GetArrayItem(root, i);
if(!item) {
ret.retCode = SET_CONF_RET_ERR_INNER;
strcpy(ret.retMsg, "inner error");
return ret;
}
if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){
ret.retCode = SET_CONF_RET_ERR_PART;
if (strlen(ret.retMsg) == 0){
snprintf(ret.retMsg, RET_MSG_LENGTH, "part error|%s", item->string);
}else{
int tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
size_t leftSize = tmp >= 0 ? tmp : 0;
strncat(ret.retMsg, "|", leftSize);
tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
leftSize = tmp >= 0 ? tmp : 0;
strncat(ret.retMsg, item->string, leftSize);
}
}
}
cJSON_Delete(root);
setConfFlag = true;
return ret;
}
setConfRet taos_set_config(const char *config){
pthread_mutex_lock(&setConfMutex);
setConfRet ret = taos_set_config_imp(config);
pthread_mutex_unlock(&setConfMutex);
return ret;
}
...@@ -17,5 +17,5 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR)) ...@@ -17,5 +17,5 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(cliTest ${SOURCE_LIST}) ADD_EXECUTABLE(cliTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES(cliTest taos tutil common gtest pthread) TARGET_LINK_LIBRARIES(cliTest taos cJson tutil common gtest pthread)
ENDIF() ENDIF()
#include <gtest/gtest.h>
#include <inttypes.h>
#include "taos.h"
#include "tglobal.h"
#include "tconfig.h"
/* test set config function */
TEST(testCase, set_config_test1) {
const char *config = "{\"debugFlag\":\"131\"}";
setConfRet ret = taos_set_config(config);
ASSERT_EQ(ret.retCode, 0);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
const char *config2 = "{\"debugFlag\":\"199\"}";
ret = taos_set_config(config2); // not take effect
ASSERT_EQ(ret.retCode, -5);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect
ASSERT_TRUE(readResult);
int32_t checkResult = taosCheckGlobalCfg();
ASSERT_EQ(checkResult, 0);
SGlobalCfg *cfg = taosGetConfigOption("debugFlag");
ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION);
int32_t result = *(int32_t *)cfg->ptr;
ASSERT_EQ(result, 131);
}
TEST(testCase, set_config_test2) {
const char *config = "{\"numOfCommitThreads\":\"10\"}";
taos_set_config(config);
bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect
ASSERT_TRUE(readResult);
int32_t checkResult = taosCheckGlobalCfg();
ASSERT_EQ(checkResult, 0);
SGlobalCfg *cfg = taosGetConfigOption("numOfCommitThreads");
int32_t result = *(int32_t*)cfg->ptr;
ASSERT_NE(result, 10); // numOfCommitThreads not type of TSDB_CFG_CTYPE_B_CLIENT
}
TEST(testCase, set_config_test3) {
const char *config = "{\"numOfCoitThreads\":\"10\", \"esdfa\":\"10\"}";
setConfRet ret = taos_set_config(config);
ASSERT_EQ(ret.retCode, -1);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
}
TEST(testCase, set_config_test4) {
const char *config = "{null}";
setConfRet ret = taos_set_config(config);
ASSERT_EQ(ret.retCode, -4);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
}
TEST(testCase, set_config_test5) {
const char *config = "\"ddd\"";
setConfRet ret = taos_set_config(config);
ASSERT_EQ(ret.retCode, -3);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
}
TEST(testCase, set_config_test6) {
const char *config = "{\"numOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitThreadsnumOfCoitT3333dd\":\"10\", \"esdfa\":\"10\"}";
setConfRet ret = taos_set_config(config);
ASSERT_EQ(ret.retCode, -1);
printf("msg:%d->%s", ret.retCode, ret.retMsg);
}
...@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED) ...@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME} ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
POST_BUILD POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.34-dist.jar ${LIBRARY_OUTPUT_PATH} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.35-dist.jar ${LIBRARY_OUTPUT_PATH}
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMENT "build jdbc driver") COMMENT "build jdbc driver")
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME}) ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.34</version> <version>2.0.35</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>JDBCDriver</name> <name>JDBCDriver</name>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.34</version> <version>2.0.35</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>JDBCDriver</name> <name>JDBCDriver</name>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url> <url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
......
...@@ -118,9 +118,6 @@ public class TSDBDriver extends AbstractDriver { ...@@ -118,9 +118,6 @@ public class TSDBDriver extends AbstractDriver {
} }
public Connection connect(String url, Properties info) throws SQLException { public Connection connect(String url, Properties info) throws SQLException {
if (url == null)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
if (!acceptsURL(url)) if (!acceptsURL(url))
return null; return null;
...@@ -135,8 +132,7 @@ public class TSDBDriver extends AbstractDriver { ...@@ -135,8 +132,7 @@ public class TSDBDriver extends AbstractDriver {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED);
try { try {
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), TSDBJNIConnector.init(props);
(String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE));
return new TSDBConnection(props, this.dbMetaData); return new TSDBConnection(props, this.dbMetaData);
} catch (SQLWarning sqlWarning) { } catch (SQLWarning sqlWarning) {
sqlWarning.printStackTrace(); sqlWarning.printStackTrace();
...@@ -205,6 +201,7 @@ public class TSDBDriver extends AbstractDriver { ...@@ -205,6 +201,7 @@ public class TSDBDriver extends AbstractDriver {
String dbProductName = url.substring(0, beginningOfSlashes); String dbProductName = url.substring(0, beginningOfSlashes);
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1); dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":")); dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PRODUCT_NAME, dbProductName);
// parse database name // parse database name
url = url.substring(beginningOfSlashes + 2); url = url.substring(beginningOfSlashes + 2);
......
...@@ -35,6 +35,7 @@ public class TSDBError { ...@@ -35,6 +35,7 @@ public class TSDBError {
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PRECISION, "unknown timestamp precision"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PRECISION, "unknown timestamp precision");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, "user is required"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, "user is required");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, "password is required"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, "password is required");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_JSON_FORMAT, "invalid json format");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
......
...@@ -31,6 +31,7 @@ public class TSDBErrorNumbers { ...@@ -31,6 +31,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_RESTFul_Client_IOException = 0x2318; public static final int ERROR_RESTFul_Client_IOException = 0x2318;
public static final int ERROR_USER_IS_REQUIRED = 0x2319; // user is required public static final int ERROR_USER_IS_REQUIRED = 0x2319; // user is required
public static final int ERROR_PASSWORD_IS_REQUIRED = 0x231a; // password is required public static final int ERROR_PASSWORD_IS_REQUIRED = 0x231a; // password is required
public static final int ERROR_INVALID_JSON_FORMAT = 0x231b;
public static final int ERROR_UNKNOWN = 0x2350; //unknown error public static final int ERROR_UNKNOWN = 0x2350; //unknown error
...@@ -72,6 +73,7 @@ public class TSDBErrorNumbers { ...@@ -72,6 +73,7 @@ public class TSDBErrorNumbers {
errorNumbers.add(ERROR_RESTFul_Client_IOException); errorNumbers.add(ERROR_RESTFul_Client_IOException);
errorNumbers.add(ERROR_USER_IS_REQUIRED); errorNumbers.add(ERROR_USER_IS_REQUIRED);
errorNumbers.add(ERROR_PASSWORD_IS_REQUIRED); errorNumbers.add(ERROR_PASSWORD_IS_REQUIRED);
errorNumbers.add(ERROR_INVALID_JSON_FORMAT);
errorNumbers.add(ERROR_RESTFul_Client_Protocol_Exception); errorNumbers.add(ERROR_RESTFul_Client_Protocol_Exception);
......
package com.taosdata.jdbc;
public class TSDBException {
private int code;
private String message;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
\ No newline at end of file
...@@ -16,18 +16,21 @@ ...@@ -16,18 +16,21 @@
*/ */
package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.alibaba.fastjson.JSONObject;
import com.taosdata.jdbc.utils.TaosInfo; import com.taosdata.jdbc.utils.TaosInfo;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.util.List; import java.util.List;
import java.util.Properties;
/** /**
* JNI connector * JNI connector
*/ */
public class TSDBJNIConnector { public class TSDBJNIConnector {
private static volatile Boolean isInitialized = false; private static final Object LOCK = new Object();
private static volatile boolean isInitialized;
private final TaosInfo taosInfo = TaosInfo.getInstance(); private final TaosInfo taosInfo = TaosInfo.getInstance();
private long taos = TSDBConstants.JNI_NULL_POINTER; // Connection pointer used in C private long taos = TSDBConstants.JNI_NULL_POINTER; // Connection pointer used in C
...@@ -38,24 +41,27 @@ public class TSDBJNIConnector { ...@@ -38,24 +41,27 @@ public class TSDBJNIConnector {
System.loadLibrary("taos"); System.loadLibrary("taos");
} }
public boolean isClosed() { public static void init(Properties props) throws SQLWarning {
return this.taos == TSDBConstants.JNI_NULL_POINTER; synchronized (LOCK) {
} if (!isInitialized) {
public boolean isResultsetClosed() { JSONObject configJSON = new JSONObject();
return this.isResultsetClosed; for (String key : props.stringPropertyNames()) {
configJSON.put(key, props.getProperty(key));
} }
setConfigImp(configJSON.toJSONString());
public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning { initImp(props.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, null));
synchronized (isInitialized) {
if (!isInitialized) { String locale = props.getProperty(TSDBDriver.PROPERTY_KEY_LOCALE);
initImp(configDir);
if (setOptions(0, locale) < 0) { if (setOptions(0, locale) < 0) {
throw TSDBError.createSQLWarning("Failed to set locale: " + locale + ". System default will be used."); throw TSDBError.createSQLWarning("Failed to set locale: " + locale + ". System default will be used.");
} }
String charset = props.getProperty(TSDBDriver.PROPERTY_KEY_CHARSET);
if (setOptions(1, charset) < 0) { if (setOptions(1, charset) < 0) {
throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used."); throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used.");
} }
String timezone = props.getProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
if (setOptions(2, timezone) < 0) { if (setOptions(2, timezone) < 0) {
throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used."); throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used.");
} }
...@@ -65,11 +71,13 @@ public class TSDBJNIConnector { ...@@ -65,11 +71,13 @@ public class TSDBJNIConnector {
} }
} }
public static native void initImp(String configDir); private static native void initImp(String configDir);
public static native int setOptions(int optionIndex, String optionValue); private static native int setOptions(int optionIndex, String optionValue);
public static native String getTsCharset(); private static native String getTsCharset();
private static native TSDBException setConfigImp(String config);
public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException { public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException {
if (this.taos != TSDBConstants.JNI_NULL_POINTER) { if (this.taos != TSDBConstants.JNI_NULL_POINTER) {
...@@ -159,6 +167,14 @@ public class TSDBJNIConnector { ...@@ -159,6 +167,14 @@ public class TSDBJNIConnector {
private native long isUpdateQueryImp(long connection, long pSql); private native long isUpdateQueryImp(long connection, long pSql);
public boolean isClosed() {
return this.taos == TSDBConstants.JNI_NULL_POINTER;
}
public boolean isResultsetClosed() {
return this.isResultsetClosed;
}
/** /**
* Free result set operation from C to release result set pointer by JNI * Free result set operation from C to release result set pointer by JNI
*/ */
...@@ -351,4 +367,6 @@ public class TSDBJNIConnector { ...@@ -351,4 +367,6 @@ public class TSDBJNIConnector {
} }
private native int insertLinesImp(String[] lines, long conn); private native int insertLinesImp(String[] lines, long conn);
} }
package com.taosdata.jdbc;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class SetConfigurationInJNITest {
private String host = "127.0.0.1";
private String dbname = "test_set_config";
@Test
public void setConfigInUrl() {
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata&debugFlag=143&rpcTimer=500");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void setConfigInProperties() {
try {
Properties props = new Properties();
props.setProperty("debugFlag", "143");
props.setProperty("r pcTimer", "500");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case1:set debugFlag=135
//expect:debugFlag:135
//result:pass
public void setConfigfordebugFlag() {
try {
Properties props = new Properties();
//set debugFlag=135
props.setProperty("debugFlag", "135");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case2:set debugFlag=abc (wrong type)
//expect:debugFlag:135
//result:pass
public void setConfigforwrongtype() {
try {
Properties props = new Properties();
//set debugFlag=135
props.setProperty("debugFlag", "abc");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case3:set rpcTimer=0 (smaller than the boundary conditions)
//expect:rpcTimer:300
//result:pass
public void setConfigrpcTimer() {
try {
Properties props = new Properties();
//set rpcTimer=0
props.setProperty("rpcTimer", "0");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case4:set rpcMaxTime=10000 (bigger than the boundary conditions)
//expect:rpcMaxTime:600
//result:pass
public void setConfigforrpcMaxTime() {
try {
Properties props = new Properties();
//set rpcMaxTime=10000
props.setProperty("rpcMaxTime", "10000");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case5:set numOfThreadsPerCore=aaa (wrong type)
//expect:numOfThreadsPerCore:1.0
//result:pass
public void setConfigfornumOfThreadsPerCore() {
try {
Properties props = new Properties();
//set numOfThreadsPerCore=aaa
props.setProperty("numOfThreadsPerCore", "aaa");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case6:set numOfThreadsPerCore=100000 (bigger than the boundary conditions)
//expect:numOfThreadsPerCore:1.0
//result:pass
public void setConfignumOfThreadsPerCore() {
try {
Properties props = new Properties();
//set numOfThreadsPerCore=100000
props.setProperty("numOfThreadsPerCore", "100000");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
// test case7:set both true and wrong config(debugFlag=0,rpcDebugFlag=143,cDebugFlag=143,rpcTimer=100000)
// expect:rpcDebugFlag:143,cDebugFlag:143,rpcTimer:300
// result:pass
public void setConfigformaxTmrCtrl() {
try {
Properties props = new Properties();
props.setProperty("debugFlag", "0");
props.setProperty("rpcDebugFlag", "143");
props.setProperty("cDebugFlag", "143");
props.setProperty("rpcTimer", "100000");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", props);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
//test case 8:use url to set with wrong type(debugFlag=abc,rpcTimer=abc)
//expect:default value
//result:pass
public void setConfigInUrlwithwrongtype() {
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata&debugFlag=abc&rpcTimer=abc");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
...@@ -5,9 +5,9 @@ import org.junit.Test; ...@@ -5,9 +5,9 @@ import org.junit.Test;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean; import java.lang.management.RuntimeMXBean;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -19,25 +19,25 @@ public class TSDBJNIConnectorTest { ...@@ -19,25 +19,25 @@ public class TSDBJNIConnectorTest {
@Test @Test
public void test() { public void test() {
try { try {
try { try {
//change sleepSeconds when debugging with attach to process to find PID //change sleepSeconds when debugging with attach to process to find PID
int sleepSeconds = -1; int sleepSeconds = -1;
if (sleepSeconds>0) { if (sleepSeconds > 0) {
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
String jvmName = runtimeBean.getName(); String jvmName = runtimeBean.getName();
long pid = Long.valueOf(jvmName.split("@")[0]); long pid = Long.valueOf(jvmName.split("@")[0]);
System.out.println("JVM PID = " + pid); System.out.println("JVM PID = " + pid);
Thread.sleep(sleepSeconds*1000); Thread.sleep(sleepSeconds * 1000);
}
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// init // init
TSDBJNIConnector.init("/etc/taos", null, null, null); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos");
TSDBJNIConnector.init(properties);
// connect // connect
TSDBJNIConnector connector = new TSDBJNIConnector(); TSDBJNIConnector connector = new TSDBJNIConnector();
...@@ -115,15 +115,13 @@ public class TSDBJNIConnectorTest { ...@@ -115,15 +115,13 @@ public class TSDBJNIConnectorTest {
} }
// close statement // close statement
connector.executeQuery("use d"); connector.executeQuery("use d");
String[] lines = new String[] {"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", String[] lines = new String[]{"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"}; "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"};
connector.insertLines(lines); connector.insertLines(lines);
// close connection // close connection
connector.closeConnection(); connector.closeConnection();
} catch (SQLWarning throwables) {
throwables.printStackTrace();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -140,11 +138,7 @@ public class TSDBJNIConnectorTest { ...@@ -140,11 +138,7 @@ public class TSDBJNIConnectorTest {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
} else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
} else if (code == TSDBConstants.JNI_FETCH_END) { } else return code != TSDBConstants.JNI_FETCH_END;
return false;
} else {
return true;
}
} }
} }
...@@ -62,6 +62,22 @@ typedef struct taosField { ...@@ -62,6 +62,22 @@ typedef struct taosField {
int16_t bytes; int16_t bytes;
} TAOS_FIELD; } TAOS_FIELD;
typedef enum {
SET_CONF_RET_SUCC = 0,
SET_CONF_RET_ERR_PART = -1,
SET_CONF_RET_ERR_INNER = -2,
SET_CONF_RET_ERR_JSON_INVALID = -3,
SET_CONF_RET_ERR_JSON_PARSE = -4,
SET_CONF_RET_ERR_ONLY_ONCE = -5,
SET_CONF_RET_ERR_TOO_LONG = -6
} SET_CONF_RET_CODE;
#define RET_MSG_LENGTH 1024
typedef struct setConfRet {
SET_CONF_RET_CODE retCode;
char retMsg[RET_MSG_LENGTH];
} setConfRet;
#ifdef _TD_GO_DLL_ #ifdef _TD_GO_DLL_
#define DLL_EXPORT __declspec(dllexport) #define DLL_EXPORT __declspec(dllexport)
#else #else
...@@ -71,6 +87,7 @@ typedef struct taosField { ...@@ -71,6 +87,7 @@ typedef struct taosField {
DLL_EXPORT int taos_init(); DLL_EXPORT int taos_init();
DLL_EXPORT void taos_cleanup(void); DLL_EXPORT void taos_cleanup(void);
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
DLL_EXPORT setConfRet taos_set_config(const char *config);
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
DLL_EXPORT void taos_close(TAOS *taos); DLL_EXPORT void taos_close(TAOS *taos);
......
...@@ -19,9 +19,9 @@ ELSE () ...@@ -19,9 +19,9 @@ ELSE ()
ENDIF () ENDIF ()
IF (TD_SOMODE_STATIC) IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(shell taos_static lua ${LINK_JEMALLOC}) TARGET_LINK_LIBRARIES(shell taos_static cJson lua ${LINK_JEMALLOC})
ELSE () ELSE ()
TARGET_LINK_LIBRARIES(shell taos lua ${LINK_JEMALLOC}) TARGET_LINK_LIBRARIES(shell taos cJson lua ${LINK_JEMALLOC})
ENDIF () ENDIF ()
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
...@@ -30,7 +30,7 @@ ELSEIF (TD_WINDOWS) ...@@ -30,7 +30,7 @@ ELSEIF (TD_WINDOWS)
LIST(APPEND SRC ./src/shellMain.c) LIST(APPEND SRC ./src/shellMain.c)
LIST(APPEND SRC ./src/shellWindows.c) LIST(APPEND SRC ./src/shellWindows.c)
ADD_EXECUTABLE(shell ${SRC}) ADD_EXECUTABLE(shell ${SRC})
TARGET_LINK_LIBRARIES(shell taos_static) TARGET_LINK_LIBRARIES(shell taos_static cJson)
IF (TD_POWER) IF (TD_POWER)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME power) SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME power)
...@@ -46,7 +46,7 @@ ELSEIF (TD_DARWIN) ...@@ -46,7 +46,7 @@ ELSEIF (TD_DARWIN)
LIST(APPEND SRC ./src/shellCheck.c) LIST(APPEND SRC ./src/shellCheck.c)
ADD_EXECUTABLE(shell ${SRC}) ADD_EXECUTABLE(shell ${SRC})
# linking with dylib # linking with dylib
TARGET_LINK_LIBRARIES(shell taos) TARGET_LINK_LIBRARIES(shell taos cJson)
# linking taos statically # linking taos statically
# TARGET_LINK_LIBRARIES(shell taos_static) # TARGET_LINK_LIBRARIES(shell taos_static)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
......
...@@ -9,9 +9,9 @@ AUX_SOURCE_DIRECTORY(. SRC) ...@@ -9,9 +9,9 @@ AUX_SOURCE_DIRECTORY(. SRC)
IF (TD_LINUX) IF (TD_LINUX)
ADD_EXECUTABLE(taosdump ${SRC}) ADD_EXECUTABLE(taosdump ${SRC})
IF (TD_SOMODE_STATIC) IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(taosdump taos_static) TARGET_LINK_LIBRARIES(taosdump taos_static cJson)
ELSE () ELSE ()
TARGET_LINK_LIBRARIES(taosdump taos) TARGET_LINK_LIBRARIES(taosdump taos cJson)
ENDIF () ENDIF ()
ENDIF () ENDIF ()
...@@ -19,8 +19,8 @@ IF (TD_DARWIN) ...@@ -19,8 +19,8 @@ IF (TD_DARWIN)
# missing <argp.h> for macosx # missing <argp.h> for macosx
# ADD_EXECUTABLE(taosdump ${SRC}) # ADD_EXECUTABLE(taosdump ${SRC})
# IF (TD_SOMODE_STATIC) # IF (TD_SOMODE_STATIC)
# TARGET_LINK_LIBRARIES(taosdump taos_static) # TARGET_LINK_LIBRARIES(taosdump taos_static cJson)
# ELSE () # ELSE ()
# TARGET_LINK_LIBRARIES(taosdump taos) # TARGET_LINK_LIBRARIES(taosdump taos cJson)
# ENDIF () # ENDIF ()
ENDIF () ENDIF ()
...@@ -17,5 +17,5 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR)) ...@@ -17,5 +17,5 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(osTest ${SOURCE_LIST}) ADD_EXECUTABLE(osTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES(osTest taos os tutil common gtest pthread) TARGET_LINK_LIBRARIES(osTest taos os cJson tutil common gtest pthread)
ENDIF() ENDIF()
...@@ -18,7 +18,7 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR)) ...@@ -18,7 +18,7 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(queryTest ${SOURCE_LIST}) ADD_EXECUTABLE(queryTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread) TARGET_LINK_LIBRARIES(queryTest taos cJson query gtest pthread)
ENDIF() ENDIF()
SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w)
......
...@@ -89,6 +89,7 @@ void taosDumpGlobalCfg(); ...@@ -89,6 +89,7 @@ void taosDumpGlobalCfg();
void taosInitConfigOption(SGlobalCfg cfg); void taosInitConfigOption(SGlobalCfg cfg);
SGlobalCfg * taosGetConfigOption(const char *option); SGlobalCfg * taosGetConfigOption(const char *option);
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}}; SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};
int32_t tsGlobalConfigNum = 0; int32_t tsGlobalConfigNum = 0;
#define ATOI_JUDGE if ( !value && strcmp(input_value, "0") != 0) { \
uError("atoi error, input value:%s",input_value); \
return false; \
}
static char *tsGlobalUnit[] = { static char *tsGlobalUnit[] = {
" ", " ",
"(%)", "(%)",
...@@ -44,12 +49,14 @@ char *tsCfgStatusStr[] = { ...@@ -44,12 +49,14 @@ char *tsCfgStatusStr[] = {
"program argument list" "program argument list"
}; };
static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
float value = (float)atof(input_value); float value = (float)atof(input_value);
ATOI_JUDGE
float *option = (float *)cfg->ptr; float *option = (float *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -57,16 +64,20 @@ static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -57,16 +64,20 @@ static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
double value = atof(input_value); double value = atof(input_value);
ATOI_JUDGE
double *option = (double *)cfg->ptr; double *option = (double *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -74,17 +85,21 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -74,17 +85,21 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int32_t *option = (int32_t *)cfg->ptr; int32_t *option = (int32_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -92,16 +107,20 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { ...@@ -92,16 +107,20 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int16_t *option = (int16_t *)cfg->ptr; int16_t *option = (int16_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (int16_t)value; *option = (int16_t)value;
...@@ -109,16 +128,20 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { ...@@ -109,16 +128,20 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
uint16_t *option = (uint16_t *)cfg->ptr; uint16_t *option = (uint16_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (uint16_t)value; *option = (uint16_t)value;
...@@ -126,16 +149,20 @@ static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { ...@@ -126,16 +149,20 @@ static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int8_t *option = (int8_t *)cfg->ptr; int8_t *option = (int8_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (int8_t)value; *option = (int8_t)value;
...@@ -143,8 +170,10 @@ static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { ...@@ -143,8 +170,10 @@ static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
...@@ -191,12 +220,13 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -191,12 +220,13 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
return true; return true;
} }
static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
uint32_t value = taosInetAddr(input_value); uint32_t value = taosInetAddr(input_value);
char * option = (char *)cfg->ptr; char * option = (char *)cfg->ptr;
if (value == INADDR_NONE) { if (value == INADDR_NONE) {
uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s",
cfg->option, input_value, option); cfg->option, input_value, option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
strncpy(option, input_value, cfg->ptrLength); strncpy(option, input_value, cfg->ptrLength);
...@@ -204,16 +234,19 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -204,16 +234,19 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], option); tsCfgStatusStr[cfg->cfgStatus], option);
return false;
} }
} }
return true;
} }
static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
int length = (int) strlen(input_value); int length = (int) strlen(input_value);
char *option = (char *)cfg->ptr; char *option = (char *)cfg->ptr;
if (length <= 0 || length > cfg->ptrLength) { if (length <= 0 || length > cfg->ptrLength) {
uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s",
cfg->option, input_value, cfg->ptrLength, option); cfg->option, input_value, cfg->ptrLength, option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
strncpy(option, input_value, cfg->ptrLength); strncpy(option, input_value, cfg->ptrLength);
...@@ -221,8 +254,10 @@ static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -221,8 +254,10 @@ static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], option); tsCfgStatusStr[cfg->cfgStatus], option);
return false;
} }
} }
return true;
} }
static void taosReadLogOption(char *option, char *value) { static void taosReadLogOption(char *option, char *value) {
...@@ -258,51 +293,59 @@ SGlobalCfg *taosGetConfigOption(const char *option) { ...@@ -258,51 +293,59 @@ SGlobalCfg *taosGetConfigOption(const char *option) {
return NULL; return NULL;
} }
static void taosReadConfigOption(const char *option, char *value, char *value2, char *value3) { bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3,
int8_t cfgStatus, int8_t sourceType) {
bool ret = false;
for (int i = 0; i < tsGlobalConfigNum; ++i) { for (int i = 0; i < tsGlobalConfigNum; ++i) {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue;
if (sourceType != 0 && !(cfg->cfgType & sourceType)) continue;
if (strcasecmp(cfg->option, option) != 0) continue; if (strcasecmp(cfg->option, option) != 0) continue;
switch (cfg->valType) { switch (cfg->valType) {
case TAOS_CFG_VTYPE_INT8: case TAOS_CFG_VTYPE_INT8:
taosReadInt8Config(cfg, value); ret = taosReadInt8Config(cfg, value);
break; break;
case TAOS_CFG_VTYPE_INT16: case TAOS_CFG_VTYPE_INT16:
taosReadInt16Config(cfg, value); ret = taosReadInt16Config(cfg, value);
break; break;
case TAOS_CFG_VTYPE_INT32: case TAOS_CFG_VTYPE_INT32:
taosReadInt32Config(cfg, value); ret = taosReadInt32Config(cfg, value);
break; break;
case TAOS_CFG_VTYPE_UINT16: case TAOS_CFG_VTYPE_UINT16:
taosReadUInt16Config(cfg, value); ret = taosReadUInt16Config(cfg, value);
break; break;
case TAOS_CFG_VTYPE_FLOAT: case TAOS_CFG_VTYPE_FLOAT:
taosReadFloatConfig(cfg, value); ret = taosReadFloatConfig(cfg, value);
break; break;
case TAOS_CFG_VTYPE_DOUBLE: case TAOS_CFG_VTYPE_DOUBLE:
taosReadDoubleConfig(cfg, value); ret = taosReadDoubleConfig(cfg, value);
break; break;
case TAOS_CFG_VTYPE_STRING: case TAOS_CFG_VTYPE_STRING:
taosReadStringConfig(cfg, value); ret = taosReadStringConfig(cfg, value);
break; break;
case TAOS_CFG_VTYPE_IPSTR: case TAOS_CFG_VTYPE_IPSTR:
taosReadIpStrConfig(cfg, value); ret = taosReadIpStrConfig(cfg, value);
break; break;
case TAOS_CFG_VTYPE_DIRECTORY: case TAOS_CFG_VTYPE_DIRECTORY:
taosReadDirectoryConfig(cfg, value); ret = taosReadDirectoryConfig(cfg, value);
break; break;
case TAOS_CFG_VTYPE_DATA_DIRCTORY: case TAOS_CFG_VTYPE_DATA_DIRCTORY:
if (taosReadDirectoryConfig(cfg, value)) { if (taosReadDirectoryConfig(cfg, value)) {
taosReadDataDirCfg(value, value2, value3); taosReadDataDirCfg(value, value2, value3);
ret = true;
} }
ret = false;
break; break;
default: default:
uError("config option:%s, input value:%s, can't be recognized", option, value); uError("config option:%s, input value:%s, can't be recognized", option, value);
break; ret = false;
}
if(ret && cfgStatus == TAOS_CFG_CSTATUS_OPTION){
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
} }
break;
} }
return ret;
} }
void taosInitConfigOption(SGlobalCfg cfg) { void taosInitConfigOption(SGlobalCfg cfg) {
...@@ -437,7 +480,7 @@ bool taosReadGlobalCfg() { ...@@ -437,7 +480,7 @@ bool taosReadGlobalCfg() {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
taosReadConfigOption(option, value, value2, value3); taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE, 0);
} }
fclose(fp); fclose(fp);
......
文件已添加
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h>
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
extern SGlobalCfg *taosGetConfigOption(const char *option) ;
int main( int argc, char *argv[]){
printf("start to test\n");
//case1:
//Test config to wrong type
const char config1[128] = "{\"cache\":\"4\"}";//input the parameter which want to be configured
taos_set_config(config1); //configure the parameter
SGlobalCfg *cfg1 ;
cfg1 = taosGetConfigOption("cache");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config cache to '4'success!\n");
else
printf("config cache failure!\n");
return 0 ;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h>
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
extern SGlobalCfg *taosGetConfigOption(const char *option) ;
int main( int argc, char *argv[]){
printf("start to test\n");
//case1:
//Test config with wrong JSON
//The result is failure
const char config1[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\135\"}";//input the parameter which want to be configured
taos_set_config(config1); //configure the parameter
SGlobalCfg *cfg1 ;
cfg1 = taosGetConfigOption("firstEp");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config firstEp 'BCC-2:6030'success!\n");
else
printf("config firstEp failure!\n");
SGlobalCfg *cfg2 ;
cfg2 = taosGetConfigOption("debugFlag");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config debugFlag '135'success!\n");
else
printf("config debugFlag failure!\n");
//case2:
//repair the JSON and try again
//The result is success
const char config2[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\"135\"}";//input the parameter which want to be configured
taos_set_config(config2); //configure the parameter
SGlobalCfg *cfg3 ;
cfg3 = taosGetConfigOption("firstEp");//check the option result
if(cfg3->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config firstEp 'BCC-2:6030'success!\n");
else
printf("config firstEp failure!\n");
SGlobalCfg *cfg4 ;
cfg4 = taosGetConfigOption("debugFlag");//check the option result
if(cfg4->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config debugFlag '135'success!\n");
else
printf("config debugFlag failure!\n");
return 0 ;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h>
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
extern SGlobalCfg *taosGetConfigOption(const char *option) ;
int main( int argc, char *argv[]){
printf("start to test\n");
//case1:
//Test config to wrong type
//The result is failure
const char config1[128] = "{\"debugFlag\":\"9999999999999999999999999\"}";//input the parameter which want to be configured
taos_set_config(config1); //configure the parameter
SGlobalCfg *cfg1 ;
cfg1 = taosGetConfigOption("debugFlag");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config debugFlag '9999999999999999999999999\n");
else
printf("config debugFlag failure!\n");
//case2:
//Try again with right parameter
//The result is failure
const char config2[128] = "{\"debugFlag\":\"135\"}";//input the parameter which want to be configured
taos_set_config(config2); //configure the parameter
SGlobalCfg *cfg2 ;
cfg2 = taosGetConfigOption("debugFlag");//check the option result
if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config debugflag '135'success!\n");
else
printf("config debugflag failure!\n");
return 0 ;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h>
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
extern SGlobalCfg *taosGetConfigOption(const char *option) ;
int main( int argc, char *argv[]){
printf("start to test\n");
//case1:
//Test config to wrong type
const char config1[128] = "{\"rpcTimer\":\"0\"}";//input the parameter which want to be configured
taos_set_config(config1); //configure the parameter
SGlobalCfg *cfg1 ;
cfg1 = taosGetConfigOption("rpcTimer");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config rpcTimer to '0'success!\n");
else
printf("config rpcTimer failure!\n");
//case2:
//Try again with right parameter
const char config2[128] = "{\"rpcTimer\":\"400\"}";//input the parameter which want to be configured
taos_set_config(config2); //configure the parameter
SGlobalCfg *cfg2 ;
cfg2 = taosGetConfigOption("rpcTimer");//check the option result
if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config rpcTimer '400'success!\n");
else
printf("config rpcTimer failure!\n");
return 0 ;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <taos.h>
#include "os.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
extern SGlobalCfg *taosGetConfigOption(const char *option) ;
int main( int argc, char *argv[]){
printf("start to test\n");
//case1:
//Test config firstEp success
const char config1[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\"135\"}";//input the parameter which want to be configured
taos_set_config(config1); //configure the parameter
SGlobalCfg *cfg1 ;
cfg1 = taosGetConfigOption("firstEp");//check the option result
if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config firstEp 'BCC-2:6030'success!\n");
else
printf("config firstEp failure!\n");
SGlobalCfg *cfg2 ;
cfg2 = taosGetConfigOption("debugFlag");//check the option result
if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config debugFlag '135' success!\n");
else
printf("config debugFlag failure!\n");
//case2:
//Test config only useful at the first time
//The result is failure
const char config2[128] = "{\"fqdn\":\"BCC-3\"}";//input the parameter which want to be configured
taos_set_config(config2); //configure the parameter
SGlobalCfg *cfg3 ;
cfg2 = taosGetConfigOption("fqdn");//check the option result
if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success
printf("config fqdn to 'BCC-3'success!\n");
else
printf("config fqdn failure!\n");
return 0 ;
}
...@@ -17,6 +17,12 @@ exe: ...@@ -17,6 +17,12 @@ exe:
gcc $(CFLAGS) ./stream.c -o $(ROOT)stream $(LFLAGS) gcc $(CFLAGS) ./stream.c -o $(ROOT)stream $(LFLAGS)
gcc $(CFLAGS) ./subscribe.c -o $(ROOT)subscribe $(LFLAGS) gcc $(CFLAGS) ./subscribe.c -o $(ROOT)subscribe $(LFLAGS)
gcc $(CFLAGS) ./apitest.c -o $(ROOT)apitest $(LFLAGS) gcc $(CFLAGS) ./apitest.c -o $(ROOT)apitest $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest-wrongtype.c -o $(ROOT)clientcfgtest-wrongtype $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest-wrongjson.c -o $(ROOT)clientcfgtest-wrongjson $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest-wrongvalue.c -o $(ROOT)clientcfgtest-wrongvalue $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest-taosd.c -o $(ROOT)clientcfgtest-taosd $(LFLAGS)
clean: clean:
rm $(ROOT)asyncdemo rm $(ROOT)asyncdemo
...@@ -26,3 +32,9 @@ clean: ...@@ -26,3 +32,9 @@ clean:
rm $(ROOT)stream rm $(ROOT)stream
rm $(ROOT)subscribe rm $(ROOT)subscribe
rm $(ROOT)apitest rm $(ROOT)apitest
rm $(ROOT)clientcfgtest
rm $(ROOT)clientcfgtest-wrongtype
rm $(ROOT)clientcfgtest-wrongjson
rm $(ROOT)clientcfgtest-wrongvalue
rm $(ROOT)clientcfgtest-taosd
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册