提交 6c87b432 编写于 作者: T tristaZero

Merge branch 'dev' of ssh://github.com/shardingjdbc/sharding-jdbc into dev

......@@ -64,7 +64,7 @@ public final class Bootstrap {
public static void main(final String[] args) throws InterruptedException, IOException {
YamlProxyConfiguration localConfig = loadLocalConfiguration(new File(Bootstrap.class.getResource(getConfig(args)).getFile()));
int port = getPort(args);
ProxyListenerRegister.register();
new ProxyListenerRegister().register();
if (null == localConfig.getOrchestration()) {
startWithoutRegistryCenter(localConfig, port);
} else {
......
......@@ -20,8 +20,6 @@ package io.shardingsphere.proxy.listener;
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.transaction.listener.local.LocalTransactionListener;
import io.shardingsphere.transaction.listener.xa.XATransactionListener;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* Listener register for Proxy.
......@@ -29,16 +27,20 @@ import lombok.NoArgsConstructor;
* @author zhangliang
* @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProxyListenerRegister {
private final LocalTransactionListener localTransactionListener = new LocalTransactionListener();
private final XATransactionListener xaTransactionListener = new XATransactionListener();
private final RuleRegistry ruleRegistry = RuleRegistry.getInstance();
/**
* Register all listeners.
*
*/
public static void register() {
new LocalTransactionListener().register();
new XATransactionListener().register();
RuleRegistry.getInstance().register();
public void register() {
localTransactionListener.register();
xaTransactionListener.register();
ruleRegistry.register();
}
}
......@@ -17,12 +17,20 @@
package io.shardingsphere.proxy;
import io.shardingsphere.proxy.config.AllConfigTests;
import io.shardingsphere.proxy.listener.AllListenerTests;
import io.shardingsphere.proxy.runtime.AllRuntimeTests;
import io.shardingsphere.proxy.transport.AllTransportTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses(AllTransportTests.class)
@SuiteClasses({
AllRuntimeTests.class,
AllListenerTests.class,
AllConfigTests.class,
AllTransportTests.class
})
public final class AllTests {
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.proxy.config;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses(ProxyTableMetaDataConnectionManagerTest.class)
public final class AllConfigTests {
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.proxy.config;
import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.sql.Connection;
import java.sql.SQLException;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class ProxyTableMetaDataConnectionManagerTest {
@Mock
private JDBCBackendDataSource backendDataSource;
@Test
public void assertGetConnection() throws SQLException {
Connection connection = mock(Connection.class);
when(backendDataSource.getConnection("ds_name")).thenReturn(connection);
assertThat(new ProxyTableMetaDataConnectionManager(backendDataSource).getConnection("ds_name"), is(connection));
}
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.proxy.listener;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses(ProxyListenerRegisterTest.class)
public final class AllListenerTests {
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.proxy.listener;
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.transaction.listener.local.LocalTransactionListener;
import io.shardingsphere.transaction.listener.xa.XATransactionListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public final class ProxyListenerRegisterTest {
private final ProxyListenerRegister proxyListenerRegister = new ProxyListenerRegister();
@Mock
private LocalTransactionListener localTransactionListener;
@Mock
private XATransactionListener xaTransactionListener;
@Mock
private RuleRegistry ruleRegistry;
@Before
public void setUp() throws ReflectiveOperationException {
setField("localTransactionListener", localTransactionListener);
setField("xaTransactionListener", xaTransactionListener);
setField("ruleRegistry", ruleRegistry);
}
private void setField(final String fieldName, final Object fieldValue) throws ReflectiveOperationException {
Field field = ProxyListenerRegister.class.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(proxyListenerRegister, fieldValue);
}
@Test
public void assertRegister() {
proxyListenerRegister.register();
verify(localTransactionListener).register();
verify(xaTransactionListener).register();
verify(ruleRegistry).register();
}
}
......@@ -17,7 +17,6 @@
package io.shardingsphere.proxy.transport;
import io.shardingsphere.proxy.runtime.AllRuntimeTests;
import io.shardingsphere.proxy.transport.common.codec.AllCommonCodecTests;
import io.shardingsphere.proxy.transport.mysql.codec.MySQLPacketCodecTest;
import io.shardingsphere.proxy.transport.mysql.constant.AllMySQLConstantTests;
......@@ -28,7 +27,6 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
AllRuntimeTests.class,
AllCommonCodecTests.class,
AllMySQLConstantTests.class,
MySQLPacketCodecTest.class,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册