You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/04/09 03:30:21 UTC
[shardingsphere] branch master updated: Refactor DatabaseProtocolFrontendEngine to impl StatefulTypedSPI (#16688)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 f35339917e5 Refactor DatabaseProtocolFrontendEngine to impl StatefulTypedSPI (#16688)
f35339917e5 is described below
commit f35339917e553756abf01028ac07e8d264ecf284
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 9 11:30:15 2022 +0800
Refactor DatabaseProtocolFrontendEngine to impl StatefulTypedSPI (#16688)
---
.../frontend/netty/FrontendChannelInboundHandler.java | 2 +-
.../protocol/DatabaseProtocolFrontendEngineFactory.java | 11 ++++-------
.../fixture/DatabaseProtocolFrontendEngineFixture.java | 10 +++++-----
.../frontend/netty/FrontendChannelInboundHandlerTest.java | 2 +-
.../DatabaseProtocolFrontendEngineFactoryTest.java | 15 +++++++--------
.../proxy/frontend/mysql/MySQLFrontendEngine.java | 2 +-
.../proxy/frontend/opengauss/OpenGaussFrontendEngine.java | 2 +-
.../frontend/opengauss/OpenGaussFrontendEngineTest.java | 2 +-
.../frontend/postgresql/PostgreSQLFrontendEngine.java | 2 +-
.../frontend/postgresql/PostgreSQLFrontendEngineTest.java | 9 ---------
.../ReactiveDatabaseProtocolFrontendEngineFactory.java | 11 ++++-------
.../reactive/state/impl/ReactiveOKProxyState.java | 2 +-
...ReactiveDatabaseProtocolFrontendEngineFactoryTest.java | 5 +++--
.../DummyReactiveDatabaseProtocolFrontendEngine.java | 10 +++++-----
.../reactive/state/impl/ReactiveOKProxyStateTest.java | 3 ++-
.../mysql/command/ReactiveMySQLFrontendEngine.java | 10 +++++-----
.../frontend/spi/DatabaseProtocolFrontendEngine.java | 6 +++---
17 files changed, 45 insertions(+), 59 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index d08c820261a..eb9673f06da 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -53,7 +53,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
public FrontendChannelInboundHandler(final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final Channel channel) {
this.databaseProtocolFrontendEngine = databaseProtocolFrontendEngine;
- connectionSession = new ConnectionSession(DatabaseTypeRegistry.getActualDatabaseType(databaseProtocolFrontendEngine.getDatabaseType()), getTransactionRule().getDefaultType(), channel);
+ connectionSession = new ConnectionSession(DatabaseTypeRegistry.getActualDatabaseType(databaseProtocolFrontendEngine.getType()), getTransactionRule().getDefaultType(), channel);
}
private TransactionRule getTransactionRule() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactory.java
index 44fe762e93a..8cb3e944164 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactory.java
@@ -20,9 +20,11 @@ package org.apache.shardingsphere.proxy.frontend.protocol;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+import java.util.Properties;
/**
* Database protocol frontend engine factory.
@@ -41,11 +43,6 @@ public final class DatabaseProtocolFrontendEngineFactory {
* @return new instance of database protocol frontend engine
*/
public static DatabaseProtocolFrontendEngine newInstance(final DatabaseType databaseType) {
- for (DatabaseProtocolFrontendEngine each : ShardingSphereServiceLoader.newServiceInstances(DatabaseProtocolFrontendEngine.class)) {
- if (DatabaseTypeRegistry.getActualDatabaseType(each.getDatabaseType()).getName().equals(databaseType.getName())) {
- return each;
- }
- }
- throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType));
+ return TypedSPIRegistry.getRegisteredService(DatabaseProtocolFrontendEngine.class, databaseType.getName(), new Properties());
}
}
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
index 7d54399e1dd..97266bb82da 100644
--- 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
@@ -26,11 +26,6 @@ import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngi
public final class DatabaseProtocolFrontendEngineFixture implements DatabaseProtocolFrontendEngine {
- @Override
- public String getDatabaseType() {
- return new FixtureDatabaseType().getName();
- }
-
@Override
public FrontendContext getFrontendContext() {
return null;
@@ -58,4 +53,9 @@ public final class DatabaseProtocolFrontendEngineFixture implements DatabaseProt
@Override
public void handleException(final ConnectionSession connectionSession) {
}
+
+ @Override
+ public String getType() {
+ return new FixtureDatabaseType().getName();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
index 6fd298e1349..52e65c0b1fc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
@@ -66,7 +66,7 @@ public final class FrontendChannelInboundHandlerTest {
@Before
public void setup() {
when(frontendEngine.getAuthenticationEngine()).thenReturn(authenticationEngine);
- when(frontendEngine.getDatabaseType()).thenReturn("MySQL");
+ when(frontendEngine.getType()).thenReturn("MySQL");
when(authenticationEngine.handshake(any(ChannelHandlerContext.class))).thenReturn(CONNECTION_ID);
channel = new EmbeddedChannel(false, true);
frontendChannelInboundHandler = new FrontendChannelInboundHandler(frontendEngine, channel);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactoryTest.java
index 6adfdbf7efa..42bc6d66412 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/DatabaseProtocolFrontendEngineFactoryTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.frontend.protocol;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
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.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -28,14 +28,13 @@ import static org.junit.Assert.assertThat;
public final class DatabaseProtocolFrontendEngineFactoryTest {
- @Test(expected = UnsupportedOperationException.class)
- public void assertNewInstanceWhenUnsupported() {
- DatabaseProtocolFrontendEngineFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("Oracle"));
+ @Test
+ public void assertNewInstance() {
+ assertThat(DatabaseProtocolFrontendEngineFactory.newInstance(new FixtureDatabaseType()), instanceOf(DatabaseProtocolFrontendEngineFixture.class));
}
- @Test
- public void assertNewInstanceWithFixture() {
- DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine = DatabaseProtocolFrontendEngineFactory.newInstance(new FixtureDatabaseType());
- assertThat(databaseProtocolFrontendEngine, instanceOf(DatabaseProtocolFrontendEngineFixture.class));
+ @Test(expected = ServiceProviderNotFoundException.class)
+ public void assertNewInstanceWhenUnsupported() {
+ DatabaseProtocolFrontendEngineFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("Oracle"));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
index 55241b024d2..a2f81f80123 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
@@ -60,7 +60,7 @@ public final class MySQLFrontendEngine implements DatabaseProtocolFrontendEngine
}
@Override
- public String getDatabaseType() {
+ public String getType() {
return "MySQL";
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
index 43e38c985d8..6b47940a647 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
@@ -66,7 +66,7 @@ public final class OpenGaussFrontendEngine implements DatabaseProtocolFrontendEn
}
@Override
- public String getDatabaseType() {
+ public String getType() {
return "openGauss";
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngineTest.java
index 6bf4f457547..100ed944bae 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngineTest.java
@@ -88,6 +88,6 @@ public final class OpenGaussFrontendEngineTest {
@Test
public void assertGetDatabaseType() {
- assertThat(openGaussFrontendEngine.getDatabaseType(), is("openGauss"));
+ assertThat(openGaussFrontendEngine.getType(), is("openGauss"));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
index 68debdef424..cffc10204db 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
@@ -65,7 +65,7 @@ public final class PostgreSQLFrontendEngine implements DatabaseProtocolFrontendE
}
@Override
- public String getDatabaseType() {
+ public String getType() {
return "PostgreSQL";
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngineTest.java
index 79c9add412b..10210ac6ed4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngineTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.frontend.postgresql;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
@@ -28,8 +27,6 @@ import org.junit.Test;
import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentMap;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -37,12 +34,6 @@ import static org.mockito.Mockito.when;
public final class PostgreSQLFrontendEngineTest {
- @Test
- public void assertGetDatabaseType() {
- String actual = new PostgreSQLFrontendEngine().getDatabaseType();
- assertThat(actual, is(new PostgreSQLDatabaseType().getName()));
- }
-
@Test
public void assertRelease() {
ConnectionSession connectionSession = mock(ConnectionSession.class, RETURNS_DEEP_STUBS);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactory.java
index b4aad545f74..73c58f62894 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactory.java
@@ -19,9 +19,11 @@ package org.apache.shardingsphere.proxy.frontend.reactive.protocol;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.proxy.frontend.reactive.spi.ReactiveDatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+import java.util.Properties;
/**
* Reactive database protocol frontend engine factory.
@@ -40,11 +42,6 @@ public final class ReactiveDatabaseProtocolFrontendEngineFactory {
* @return new instance of reactive database protocol frontend engine
*/
public static ReactiveDatabaseProtocolFrontendEngine newInstance(final String databaseType) {
- for (ReactiveDatabaseProtocolFrontendEngine each : ShardingSphereServiceLoader.newServiceInstances(ReactiveDatabaseProtocolFrontendEngine.class)) {
- if (DatabaseTypeRegistry.getActualDatabaseType(each.getDatabaseType()).getName().equals(databaseType)) {
- return each;
- }
- }
- throw new UnsupportedOperationException(String.format("Cannot support database type '%s' in reactive", databaseType));
+ return TypedSPIRegistry.getRegisteredService(ReactiveDatabaseProtocolFrontendEngine.class, databaseType, new Properties());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyState.java
index ebe95d60c26..9f7eba0ad5c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyState.java
@@ -43,7 +43,7 @@ public final class ReactiveOKProxyState implements OKProxyState {
Attribute<ReactiveDatabaseProtocolFrontendEngine> attr = channel.attr(AttributeKey.valueOf(ReactiveDatabaseProtocolFrontendEngine.class.getName()));
ReactiveDatabaseProtocolFrontendEngine result = attr.get();
if (null == result) {
- result = ReactiveDatabaseProtocolFrontendEngineFactory.newInstance(databaseProtocolFrontendEngine.getDatabaseType());
+ result = ReactiveDatabaseProtocolFrontendEngineFactory.newInstance(databaseProtocolFrontendEngine.getType());
attr.setIfAbsent(result);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
index 47b49e55228..10da3d6b4fb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.reactive.protocol;
import org.apache.shardingsphere.proxy.frontend.reactive.protocol.fixture.DummyReactiveDatabaseProtocolFrontendEngine;
+import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
@@ -25,11 +26,11 @@ import static org.junit.Assert.assertTrue;
public final class ReactiveDatabaseProtocolFrontendEngineFactoryTest {
@Test
- public void assertNewInstanceWithExistType() {
+ public void assertNewInstance() {
assertTrue(ReactiveDatabaseProtocolFrontendEngineFactory.newInstance("Dummy") instanceof DummyReactiveDatabaseProtocolFrontendEngine);
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = ServiceProviderNotFoundException.class)
public void assertNewInstanceWithUnknownType() {
ReactiveDatabaseProtocolFrontendEngineFactory.newInstance("Unknown");
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/fixture/DummyReactiveDatabaseProtocolFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/fixture/DummyReactiveDatabaseProtocolFrontendEngine.java
index 64fca453b6b..ccd24f27182 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/fixture/DummyReactiveDatabaseProtocolFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/fixture/DummyReactiveDatabaseProtocolFrontendEngine.java
@@ -27,11 +27,6 @@ import org.apache.shardingsphere.proxy.frontend.reactive.spi.ReactiveDatabasePro
public final class DummyReactiveDatabaseProtocolFrontendEngine implements ReactiveDatabaseProtocolFrontendEngine {
- @Override
- public String getDatabaseType() {
- return "Dummy";
- }
-
@Override
public ReactiveCommandExecuteEngine getReactiveCommandExecuteEngine() {
return null;
@@ -64,4 +59,9 @@ public final class DummyReactiveDatabaseProtocolFrontendEngine implements Reacti
@Override
public void handleException(final ConnectionSession connectionSession) {
}
+
+ @Override
+ public String getType() {
+ return "Dummy";
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyStateTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyStateTest.java
index e5441d006c7..1e5099fe390 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyStateTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/state/impl/ReactiveOKProxyStateTest.java
@@ -40,6 +40,7 @@ public final class ReactiveOKProxyStateTest {
private final ReactiveOKProxyState state = new ReactiveOKProxyState();
+ @SuppressWarnings("unchecked")
@Test
public void assertExecute() {
ChannelHandlerContext channelHandlerContext = mock(ChannelHandlerContext.class);
@@ -50,7 +51,7 @@ public final class ReactiveOKProxyStateTest {
when(channel.<ReactiveDatabaseProtocolFrontendEngine>attr(AttributeKey.valueOf(ReactiveDatabaseProtocolFrontendEngine.class.getName()))).thenReturn(attribute);
when(channelHandlerContext.channel()).thenReturn(channel);
DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine = mock(DatabaseProtocolFrontendEngine.class);
- when(databaseProtocolFrontendEngine.getDatabaseType()).thenReturn("Dummy");
+ when(databaseProtocolFrontendEngine.getType()).thenReturn("Dummy");
ConnectionSession connectionSession = mock(ConnectionSession.class);
state.execute(channelHandlerContext, null, databaseProtocolFrontendEngine, connectionSession);
verify(attribute).setIfAbsent(any(DummyReactiveDatabaseProtocolFrontendEngine.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/ReactiveMySQLFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/ReactiveMySQLFrontendEngine.java
index 4afbc2315f8..bd5481a2098 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/ReactiveMySQLFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/ReactiveMySQLFrontendEngine.java
@@ -37,11 +37,6 @@ public final class ReactiveMySQLFrontendEngine implements ReactiveDatabaseProtoc
private final ReactiveCommandExecuteEngine reactiveCommandExecuteEngine =
(type, packet, connectionSession) -> ReactiveMySQLCommandExecutorFactory.newInstance((MySQLCommandPacketType) type, packet, connectionSession);
- @Override
- public String getDatabaseType() {
- return delegated.getDatabaseType();
- }
-
@Override
public FrontendContext getFrontendContext() {
return delegated.getFrontendContext();
@@ -75,4 +70,9 @@ public final class ReactiveMySQLFrontendEngine implements ReactiveDatabaseProtoc
public ReactiveCommandExecuteEngine getReactiveCommandExecuteEngine() {
return reactiveCommandExecuteEngine;
}
+
+ @Override
+ public String getType() {
+ return delegated.getType();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/spi/DatabaseProtocolFrontendEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/spi/DatabaseProtocolFrontendEngine.java
index 983e831952a..44a17de0809 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/spi/DatabaseProtocolFrontendEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/spi/DatabaseProtocolFrontendEngine.java
@@ -19,15 +19,15 @@ package org.apache.shardingsphere.proxy.frontend.spi;
import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.frontend.context.FrontendContext;
import org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationEngine;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeAwareSPI;
+import org.apache.shardingsphere.proxy.frontend.context.FrontendContext;
+import org.apache.shardingsphere.spi.type.typed.StatefulTypedSPI;
/**
* Database protocol frontend engine.
*/
-public interface DatabaseProtocolFrontendEngine extends DatabaseTypeAwareSPI {
+public interface DatabaseProtocolFrontendEngine extends StatefulTypedSPI {
/**
* Set database version.