This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 96c8e11 Add more test of DatabaseProtocolFrontendEngineFactory
(#7151)
96c8e11 is described below
commit 96c8e11f386386308c97178336658d5aa44800ae
Author: xbkaishui <[email protected]>
AuthorDate: Mon Aug 31 23:48:31 2020 +0800
Add more test of DatabaseProtocolFrontendEngineFactory (#7151)
* add more test with NewInstance
* fix test execute bug
* review changes
* add mock frontend engine as spi for test
* add FixtureDatabase Type
* Add final class, add instanceOf assert
---
.../DatabaseProtocolFrontendEngineFactoryTest.java | 12 +++++
.../DatabaseProtocolFrontendEngineFixture.java | 58 ++++++++++++++++++++++
.../FixtureDatabaseType.java} | 29 ++++++++---
...shardingsphere.infra.database.type.DatabaseType | 18 +++++++
...oxy.frontend.spi.DatabaseProtocolFrontendEngine | 18 +++++++
5 files changed, 128 insertions(+), 7 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
index 139fa64..0aa9ff9 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
@@ -18,12 +18,24 @@
package org.apache.shardingsphere.proxy.frontend;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
+import
org.apache.shardingsphere.proxy.frontend.fixture.DatabaseProtocolFrontendEngineFixture;
+import org.apache.shardingsphere.proxy.frontend.fixture.FixtureDatabaseType;
+import
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
public final class DatabaseProtocolFrontendEngineFactoryTest {
@Test(expected = UnsupportedOperationException.class)
public void assertNewInstanceWhenUnsupported() {
DatabaseProtocolFrontendEngineFactory.newInstance(DatabaseTypes.getActualDatabaseType("Oracle"));
}
+
+ @Test
+ public void assertNewInstanceWithFixture() {
+ DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine =
DatabaseProtocolFrontendEngineFactory.newInstance(new FixtureDatabaseType());
+ assertThat(databaseProtocolFrontendEngine,
instanceOf(DatabaseProtocolFrontendEngineFixture.class));
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/DatabaseProtocolFrontendEngineFixture.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/DatabaseProtocolFrontendEngineFixture.java
new file mode 100644
index 0000000..926dc9c
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/DatabaseProtocolFrontendEngineFixture.java
@@ -0,0 +1,58 @@
+/*
+ * 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.shardingsphere.proxy.frontend.fixture;
+
+import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
+import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.frontend.context.FrontendContext;
+import org.apache.shardingsphere.proxy.frontend.engine.AuthenticationEngine;
+import org.apache.shardingsphere.proxy.frontend.engine.CommandExecuteEngine;
+import
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
+
+public final class DatabaseProtocolFrontendEngineFixture implements
DatabaseProtocolFrontendEngine {
+
+ @Override
+ public String getDatabaseType() {
+ return new FixtureDatabaseType().getName();
+ }
+
+ @Override
+ public FrontendContext getFrontendContext() {
+ return null;
+ }
+
+ @Override
+ public DatabasePacketCodecEngine getCodecEngine() {
+ return null;
+ }
+
+ @Override
+ public AuthenticationEngine getAuthEngine() {
+ return null;
+ }
+
+ @Override
+ public CommandExecuteEngine getCommandExecuteEngine() {
+ return null;
+ }
+
+ @Override
+ public void release(final BackendConnection backendConnection) {
+
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
similarity index 56%
copy from
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
copy to
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
index 139fa64..01357da 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/DatabaseProtocolFrontendEngineFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
@@ -15,15 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.frontend;
+package org.apache.shardingsphere.proxy.frontend.fixture;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
-public final class DatabaseProtocolFrontendEngineFactoryTest {
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.mockito.Mockito.mock;
+
+public final class FixtureDatabaseType implements DatabaseType {
+
+ @Override
+ public String getName() {
+ return "FixtureDB";
+ }
+
+ @Override
+ public Collection<String> getJdbcUrlPrefixes() {
+ return Collections.singleton("jdbc:fixture");
+ }
- @Test(expected = UnsupportedOperationException.class)
- public void assertNewInstanceWhenUnsupported() {
-
DatabaseProtocolFrontendEngineFactory.newInstance(DatabaseTypes.getActualDatabaseType("Oracle"));
+ @Override
+ public DataSourceMetaData getDataSourceMetaData(final String url, final
String username) {
+ return mock(DataSourceMetaData.class);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
new file mode 100644
index 0000000..a4c767c
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.proxy.frontend.fixture.FixtureDatabaseType
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine
new file mode 100644
index 0000000..1c94ce4
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/resources/META-INF/services/org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.proxy.frontend.fixture.DatabaseProtocolFrontendEngineFixture