未验证 提交 998788ad 编写于 作者: Z Zhang Yonglun 提交者: GitHub

#7318, add proxy yaml config file (#8037)

* #7318, add config-ha.yaml

* #7318, add config-ha.yaml

* #7318, add config-ha.yaml

* #7318, fix ci
上级 953ea659
......@@ -29,10 +29,10 @@ public final class HAOrder {
/**
* HA order.
*/
public static final int ORDER = 10;
public static final int ORDER = 20;
/**
* Algorithm provider HA order.
*/
public static final int ALGORITHM_PROVIDER_ORDER = 11;
public static final int ALGORITHM_PROVIDER_HA_ORDER = 21;
}
......@@ -85,6 +85,6 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapper
@Override
public int getOrder() {
return HAOrder.ALGORITHM_PROVIDER_ORDER;
return HAOrder.ALGORITHM_PROVIDER_HA_ORDER;
}
}
......@@ -80,7 +80,7 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapperTest {
@Test
public void assertGetOrder() {
assertThat(swapper.getOrder(), is(HAOrder.ALGORITHM_PROVIDER_ORDER));
assertThat(swapper.getOrder(), is(HAOrder.ALGORITHM_PROVIDER_HA_ORDER));
}
private YamlHARuleConfiguration createYamlHARuleConfiguration() {
......
......@@ -19,6 +19,7 @@ package org.apache.shardingsphere.ha.route.engine;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
......@@ -50,6 +51,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
......@@ -90,7 +92,8 @@ public final class HASQLRouterTest {
@Test
public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
......@@ -100,7 +103,8 @@ public final class HASQLRouterTest {
public void assertDecorateRouteContextToPrimaryDataSource() {
RouteContext actual = mockRouteContext();
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
......@@ -113,7 +117,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(REPLICA_DATASOURCE));
......@@ -126,7 +131,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
......@@ -139,7 +145,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
......@@ -152,7 +159,8 @@ public final class HASQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
......@@ -163,7 +171,8 @@ public final class HASQLRouterTest {
public void assertCreateRouteContextToPrimaryDataSource() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(InsertStatement.class));
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule), Collections.emptyMap(), mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData("logic_schema", Collections.emptyList(), Collections.singleton(rule),
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), mock(ShardingSphereSchema.class));
RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
......
#
# 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.
#
######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of HA rule.
#
######################################################################################################
#
#schemaName: ha_db
#
#dataSourceCommon:
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# maintenanceIntervalMilliseconds: 30000
#
#dataSources:
# primary_ds:
# url: jdbc:postgresql://127.0.0.1:5432/demo_primary_ds?serverTimezone=UTC&useSSL=false
# replica_ds_0:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0?serverTimezone=UTC&useSSL=false
# replica_ds_1:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1?serverTimezone=UTC&useSSL=false
#
#rules:
#- !HA
# dataSources:
# pr_ds:
# name: pr_ds
# primaryDataSourceName: primary_ds
# replicaDataSourceNames:
# - replica_ds_0
# - replica_ds_1
######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################
#schemaName: ha_db
#
#dataSourceCommon:
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# maintenanceIntervalMilliseconds: 30000
#
#dataSources:
# primary_ds:
# url: jdbc:mysql://127.0.0.1:3306/demo_primary_ds?serverTimezone=UTC&useSSL=false
# replica_ds_0:
# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_0?serverTimezone=UTC&useSSL=false
# replica_ds_1:
# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_1?serverTimezone=UTC&useSSL=false
#
#rules:
#- !HA
# dataSources:
# pr_ds:
# name: pr_ds
# primaryDataSourceName: primary_ds
# replicaDataSourceNames:
# - replica_ds_0
# - replica_ds_1
......@@ -62,6 +62,11 @@
<artifactId>shardingsphere-encrypt-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-ha-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册