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 435775a Refactor SpringBootJNDIDataSourceTest (#15250)
435775a is described below
commit 435775affe7274a645edce3192bbe2ba3a5f6521
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 5 20:16:54 2022 +0800
Refactor SpringBootJNDIDataSourceTest (#15250)
* Refactor SpringBootJNDIDataSourceTest
* Refactor SpringBootJNDIDataSourceTest
* Refactor SpringBootJNDIDataSourceTest
* Refactor SpringBootJNDIDataSourceTest
---
.../{ => jndi}/SpringBootJNDIDataSourceTest.java | 14 +++++------
.../InitialDataSourceInitialContextFactory.java} | 27 ++++++++++++----------
.../src/test/resources/application-jndi.properties | 10 +++-----
3 files changed, 25 insertions(+), 26 deletions(-)
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
similarity index 79%
rename from
shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
rename to
shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
index 8c47001..f0f9186 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spring.boot;
+package org.apache.shardingsphere.spring.boot.jndi;
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.database.DefaultSchema;
-import
org.apache.shardingsphere.spring.boot.fixture.TestJndiInitialContextFactory;
+import
org.apache.shardingsphere.spring.boot.jndi.fixture.InitialDataSourceInitialContextFactory;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -49,16 +49,16 @@ public class SpringBootJNDIDataSourceTest {
@BeforeClass
public static void setUp() {
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
TestJndiInitialContextFactory.class.getName());
- TestJndiInitialContextFactory.bind("java:comp/env/jdbc/jndi0", new
MockedDataSource());
- TestJndiInitialContextFactory.bind("java:comp/env/jdbc/jndi1", new
MockedDataSource());
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
InitialDataSourceInitialContextFactory.class.getName());
+ InitialDataSourceInitialContextFactory.bind("java:comp/env/jdbc/ds0",
new MockedDataSource());
+ InitialDataSourceInitialContextFactory.bind("java:comp/env/jdbc/ds1",
new MockedDataSource());
}
@Test
public void assertDataSources() {
Map<String, DataSource> dataSources =
dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources();
assertThat(dataSources.size(), is(2));
- assertTrue(dataSources.containsKey("jndi0"));
- assertTrue(dataSources.containsKey("jndi1"));
+ assertTrue(dataSources.containsKey("ds0"));
+ assertTrue(dataSources.containsKey("ds1"));
}
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestJndiInitialContextFactory.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/fixture/InitialDataSourceInitialContextFactory.java
similarity index 72%
rename from
shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestJndiInitialContextFactory.java
rename to
shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/fixture/InitialDataSourceInitialContextFactory.java
index 26dc4ac..2d58f0c 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestJndiInitialContextFactory.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/fixture/InitialDataSourceInitialContextFactory.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spring.boot.fixture;
+package org.apache.shardingsphere.spring.boot.jndi.fixture;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -25,9 +25,12 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
-public final class TestJndiInitialContextFactory implements
InitialContextFactory {
+/**
+ * Initial data source initial context factory.
+ */
+public final class InitialDataSourceInitialContextFactory implements
InitialContextFactory {
- private static JndiContext context;
+ private static InitialDataSourceContext context;
@Override
public Context getInitialContext(final Hashtable<?, ?> environment) {
@@ -35,19 +38,19 @@ public final class TestJndiInitialContextFactory implements
InitialContextFactor
}
/**
- * Bind.
+ * Bind JNDI object.
*
- * @param name bind
- * @param obj object
+ * @param name to be bind JNDI name
+ * @param value to be bind JNDI value
*/
- public static void bind(final String name, final Object obj) {
- getContext().bind(name, obj);
+ public static void bind(final String name, final Object value) {
+ getContext().bind(name, value);
}
- private static JndiContext getContext() {
+ private static InitialDataSourceContext getContext() {
if (null == context) {
try {
- context = new JndiContext();
+ context = new InitialDataSourceContext();
} catch (final NamingException ex) {
throw new IllegalStateException(ex);
}
@@ -55,11 +58,11 @@ public final class TestJndiInitialContextFactory implements
InitialContextFactor
return context;
}
- private static final class JndiContext extends InitialContext {
+ private static final class InitialDataSourceContext extends InitialContext
{
private final Map<String, Object> bindings = new HashMap<>();
- private JndiContext() throws NamingException {
+ private InitialDataSourceContext() throws NamingException {
super(true);
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-jndi.properties
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-jndi.properties
index cf7b901..72e28c6 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-jndi.properties
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-jndi.properties
@@ -15,10 +15,6 @@
# limitations under the License.
#
-spring.shardingsphere.datasource.names=jndi0,jndi1
-spring.shardingsphere.datasource.jndi0.jndi-name=java:comp/env/jdbc/jndi0
-spring.shardingsphere.datasource.jndi1.jndi-name=jdbc/jndi1
-
-spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.type=Static
-spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.props.write-data-source-name=jndi0
-spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.props.read-data-source-names=jndi1
+spring.shardingsphere.datasource.names=ds0,ds1
+spring.shardingsphere.datasource.ds0.jndi-name=java:comp/env/jdbc/ds0
+spring.shardingsphere.datasource.ds1.jndi-name=jdbc/ds1