You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/14 09:24:42 UTC
[shardingsphere] branch master updated: [DistSQL] Add set and show
syntax for agent plugins variable (#12413)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new bbf4a3d [DistSQL] Add set and show syntax for agent plugins variable (#12413)
bbf4a3d is described below
commit bbf4a3dfe91d43659c5026f0434c8b8499abc3a4
Author: Raigor <ra...@gmail.com>
AuthorDate: Tue Sep 14 17:24:07 2021 +0800
[DistSQL] Add set and show syntax for agent plugins variable (#12413)
* Add variable AGENT_PLUGINS_ENABLED for DistSQL.
* Update test cases.
* Add system property util.
---
.../ral/common/SetDistSQLBackendHandler.java | 18 +++++++---
.../ral/common/ShowDistSQLBackendHandler.java | 12 ++++---
.../distsql/ral/common/enums/VariableEnum.java | 6 +++-
.../SystemPropertyUtil.java} | 36 +++++++++++--------
.../TextProtocolBackendHandlerFactoryTest.java | 4 +--
.../distsql/ral/SetVariableBackendHandlerTest.java | 42 ++++++++++++++++++----
.../ral/ShowVariableBackendHandlerTest.java | 13 +++++++
.../backend/util/SystemPropertyUtilTest.java} | 32 ++++++++---------
8 files changed, 113 insertions(+), 50 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java
index 8837d23..d48c24a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common;
import com.mchange.v1.db.sql.UnsupportedTypeException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.BooleanUtils;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.variable.SetVariableStatement;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -28,6 +29,7 @@ import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResp
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
import java.sql.SQLException;
@@ -49,11 +51,19 @@ public final class SetDistSQLBackendHandler implements TextProtocolBackendHandle
throw new UnsupportedTypeException(sqlStatement.getClass().getCanonicalName());
}
SetVariableStatement setVariableStatement = (SetVariableStatement) sqlStatement;
- if (VariableEnum.TRANSACTION_TYPE == VariableEnum.getValueOf(setVariableStatement.getName())) {
- backendConnection.getTransactionStatus().setTransactionType(getTransactionType(setVariableStatement.getValue()));
- return new UpdateResponseHeader(sqlStatement);
+ VariableEnum variable = VariableEnum.getValueOf(setVariableStatement.getName());
+ switch (variable) {
+ case AGENT_PLUGINS_ENABLED:
+ Boolean agentPluginsEnabled = BooleanUtils.toBooleanObject(setVariableStatement.getValue());
+ SystemPropertyUtil.setSystemProperty(variable.name(), null == agentPluginsEnabled ? Boolean.FALSE.toString() : agentPluginsEnabled.toString());
+ break;
+ case TRANSACTION_TYPE:
+ backendConnection.getTransactionStatus().setTransactionType(getTransactionType(setVariableStatement.getValue()));
+ break;
+ default:
+ throw new UnsupportedVariableException(setVariableStatement.getName());
}
- throw new UnsupportedVariableException(setVariableStatement.getName());
+ return new UpdateResponseHeader(sqlStatement);
}
private TransactionType getTransactionType(final String transactionTypeName) throws UnsupportedVariableException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
index f521fb4..48220ae 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryH
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
import java.sql.SQLException;
@@ -53,11 +54,14 @@ public final class ShowDistSQLBackendHandler implements TextProtocolBackendHandl
@Override
public ResponseHeader execute() {
ShowVariableStatement showVariableStatement = (ShowVariableStatement) sqlStatement;
- switch (VariableEnum.getValueOf(showVariableStatement.getName())) {
- case TRANSACTION_TYPE:
- return createResponsePackets(VariableEnum.TRANSACTION_TYPE.name(), backendConnection.getTransactionStatus().getTransactionType().name());
+ VariableEnum variable = VariableEnum.getValueOf(showVariableStatement.getName());
+ switch (variable) {
+ case AGENT_PLUGINS_ENABLED:
+ return createResponsePackets(variable.name(), SystemPropertyUtil.getSystemProperty(variable.name(), Boolean.FALSE.toString()));
case CACHED_CONNECTIONS:
- return createResponsePackets(VariableEnum.CACHED_CONNECTIONS.name(), backendConnection.getConnectionSize());
+ return createResponsePackets(variable.name(), backendConnection.getConnectionSize());
+ case TRANSACTION_TYPE:
+ return createResponsePackets(variable.name(), backendConnection.getTransactionStatus().getTransactionType().name());
default:
throw new UnsupportedVariableException(showVariableStatement.getName());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
index a5c68d6..a23cbb7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
@@ -24,7 +24,11 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception
*/
public enum VariableEnum {
- TRANSACTION_TYPE, CACHED_CONNECTIONS;
+ AGENT_PLUGINS_ENABLED,
+
+ CACHED_CONNECTIONS,
+
+ TRANSACTION_TYPE;
/**
* Returns the variable constant of the specified variable name.
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtil.java
similarity index 52%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtil.java
index a5c68d6..7c9f899 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtil.java
@@ -15,27 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums;
+package org.apache.shardingsphere.proxy.backend.util;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
/**
- * Variable enum.
+ * System property utility class.
*/
-public enum VariableEnum {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SystemPropertyUtil {
- TRANSACTION_TYPE, CACHED_CONNECTIONS;
+ /**
+ * Set system property.
+ *
+ * @param key property key
+ * @param value property value
+ */
+ public static void setSystemProperty(final String key, final String value) {
+ System.setProperty(key, value);
+ }
/**
- * Returns the variable constant of the specified variable name.
- * @param variableName variable name
- * @return variable constant
+ * Get system property.
+ *
+ * @param key property key
+ * @param defaultValue a default value
+ * @return property value
*/
- public static VariableEnum getValueOf(final String variableName) {
- try {
- return valueOf(variableName.toUpperCase());
- } catch (IllegalArgumentException ex) {
- throw new UnsupportedVariableException(variableName);
- }
+ public static String getSystemProperty(final String key, final String defaultValue) {
+ return System.getProperty(key, defaultValue);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
similarity index 98%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
index 82c9d8e..91b24b4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend;
+package org.apache.shardingsphere.proxy.backend.text;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -25,8 +25,6 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
-import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminQueryBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminUpdateBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
index 47a67ed..42ad4e0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
@@ -34,7 +34,9 @@ import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.SetDistSQLBackendHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Before;
import org.junit.Test;
@@ -86,8 +88,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeXA() throws SQLException {
backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler shardingCTLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "XA"), backendConnection);
- ResponseHeader actual = shardingCTLBackendHandler.execute();
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "XA"), backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(backendConnection.getTransactionStatus().getTransactionType(), is(TransactionType.XA));
}
@@ -95,8 +97,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeBASE() throws SQLException {
backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler shardingCTLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "BASE"), backendConnection);
- ResponseHeader actual = shardingCTLBackendHandler.execute();
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "BASE"), backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(backendConnection.getTransactionStatus().getTransactionType(), is(TransactionType.BASE));
}
@@ -104,8 +106,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeLOCAL() throws SQLException {
backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler shardingCTLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "LOCAL"), backendConnection);
- ResponseHeader actual = shardingCTLBackendHandler.execute();
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "LOCAL"), backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(backendConnection.getTransactionStatus().getTransactionType(), is(TransactionType.LOCAL));
}
@@ -120,4 +122,32 @@ public final class SetVariableBackendHandlerTest {
public void assertNotSupportedVariable() throws SQLException {
new SetDistSQLBackendHandler(new SetVariableStatement("@@session", "XXX"), backendConnection).execute();
}
+
+ @Test
+ public void assertSetAgentPluginsEnabledTrue() throws SQLException {
+ backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString()),
+ backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
+ assertThat(actual, instanceOf(UpdateResponseHeader.class));
+ assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.TRUE.toString()));
+ }
+
+ @Test
+ public void assertSetAgentPluginsEnabledFalse() throws SQLException {
+ backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "FALSE"), backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
+ assertThat(actual, instanceOf(UpdateResponseHeader.class));
+ assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.FALSE.toString()));
+ }
+
+ @Test
+ public void assertSetAgentPluginsEnabledFalseWithUnknownValue() throws SQLException {
+ backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "xxx"), backendConnection);
+ ResponseHeader actual = setDistSQLBackendHandler.execute();
+ assertThat(actual, instanceOf(UpdateResponseHeader.class));
+ assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.FALSE.toString()));
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
index aa0aaff..d3cce87 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.ShowDistSQLBackendHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Test;
@@ -66,4 +67,16 @@ public final class ShowVariableBackendHandlerTest {
backendConnection.setCurrentSchema("schema");
new ShowDistSQLBackendHandler(new ShowVariableStatement("cached_connectionss"), backendConnection).execute();
}
+
+ @Test
+ public void assertShowAgentPluginsEnabled() throws SQLException {
+ backendConnection.setCurrentSchema("schema");
+ ShowDistSQLBackendHandler backendHandler = new ShowDistSQLBackendHandler(new ShowVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name()), backendConnection);
+ ResponseHeader actual = backendHandler.execute();
+ assertThat(actual, instanceOf(QueryResponseHeader.class));
+ assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(), is(1));
+ backendHandler.next();
+ Collection<Object> rowData = backendHandler.getRowData();
+ assertThat(rowData.iterator().next(), is(Boolean.FALSE.toString()));
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtilTest.java
similarity index 53%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtilTest.java
index a5c68d6..ead9baa 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/enums/VariableEnum.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/SystemPropertyUtilTest.java
@@ -15,27 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums;
+package org.apache.shardingsphere.proxy.backend.util;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import org.junit.Test;
-/**
- * Variable enum.
- */
-public enum VariableEnum {
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SystemPropertyUtilTest {
- TRANSACTION_TYPE, CACHED_CONNECTIONS;
+ @Test
+ public void assertGetDefaultValue() {
+ assertThat(SystemPropertyUtil.getSystemProperty("key0", "value0"), is("value0"));
+ }
- /**
- * Returns the variable constant of the specified variable name.
- * @param variableName variable name
- * @return variable constant
- */
- public static VariableEnum getValueOf(final String variableName) {
- try {
- return valueOf(variableName.toUpperCase());
- } catch (IllegalArgumentException ex) {
- throw new UnsupportedVariableException(variableName);
- }
+ @Test
+ public void assertGetSystemPropertyAfterSet() {
+ SystemPropertyUtil.setSystemProperty("key1", "value1");
+ assertThat(SystemPropertyUtil.getSystemProperty("key1", "value0"), is("value1"));
}
}