未验证 提交 e42a68dd 编写于 作者: J Juan Pan(Trista) 提交者: GitHub

Add SchemaNameCallback for proxy (#6785)

* Add SchemaNameCallback for proxy

* fix tests
上级 4875e8e2
......@@ -31,6 +31,7 @@ import org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfig
import org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
import org.apache.shardingsphere.infra.callback.orchestration.DataSourceCallback;
import org.apache.shardingsphere.infra.callback.orchestration.RuleCallback;
import org.apache.shardingsphere.infra.callback.orchestration.SchemaNameCallback;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
......@@ -72,6 +73,7 @@ public final class ConfigCenter {
this.repository = repository;
DataSourceCallback.getInstance().register(this::persistDataSourceConfiguration);
RuleCallback.getInstance().register(this::persistRuleConfigurations);
SchemaNameCallback.getInstance().register(this::persistSchemaName);
}
/**
......
......@@ -68,6 +68,7 @@ public final class SchemaChangedListener extends PostOrchestrationRepositoryEven
@Override
protected OrchestrationEvent createOrchestrationEvent(final DataChangedEvent event) {
// TODO Consider removing the following one.
if (configurationNode.getSchemaPath().equals(event.getKey())) {
return createSchemaNamesUpdatedEvent(event.getValue());
}
......@@ -101,7 +102,8 @@ public final class SchemaChangedListener extends PostOrchestrationRepositoryEven
}
private boolean isValidNodeChangedEvent(final String shardingSchemaName, final String nodeFullPath) {
return configurationNode.getDataSourcePath(shardingSchemaName).equals(nodeFullPath) || configurationNode.getRulePath(shardingSchemaName).equals(nodeFullPath);
return !existedSchemaNames.contains(shardingSchemaName)
|| configurationNode.getDataSourcePath(shardingSchemaName).equals(nodeFullPath) || configurationNode.getRulePath(shardingSchemaName).equals(nodeFullPath);
}
private OrchestrationEvent createAddedEvent(final String shardingSchemaName) {
......
......@@ -72,9 +72,9 @@ public final class SchemaChangedListenerTest {
@Test
public void assertCreateIgnoredEvent() {
assertThat(schemaChangedListener.createOrchestrationEvent(new DataChangedEvent("/test/config/schema/logic_db", "test", ChangedType.UPDATED)),
assertThat(schemaChangedListener.createOrchestrationEvent(new DataChangedEvent("/test/config/schema/encrypt_db", "test", ChangedType.UPDATED)),
instanceOf(IgnoredOrchestrationEvent.class));
assertThat(schemaChangedListener.createOrchestrationEvent(new DataChangedEvent("/test/config/schema/logic_db/rule", "test", ChangedType.IGNORED)),
assertThat(schemaChangedListener.createOrchestrationEvent(new DataChangedEvent("/test/config/schema/encrypt_db/rule", "test", ChangedType.IGNORED)),
instanceOf(IgnoredOrchestrationEvent.class));
}
......@@ -188,19 +188,19 @@ public final class SchemaChangedListenerTest {
}
@Test
public void assertCreateWithInvalidNodeChangedEvent() {
public void assertCreateWithSchemaDeletedEvent() {
String dataSource = readYAML(DATA_SOURCE_FILE);
DataChangedEvent dataChangedEvent = new DataChangedEvent("/test/config/schema/logic_db", dataSource, ChangedType.DELETED);
OrchestrationEvent actual = schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertThat(actual, instanceOf(IgnoredOrchestrationEvent.class));
assertThat(actual, instanceOf(SchemaDeletedEvent.class));
}
@Test
public void assertCreateWithNullShardingSchemaName() {
public void assertCreateWithSchemaDeletedEventWithDataSourceNode() {
String dataSource = readYAML(DATA_SOURCE_FILE);
DataChangedEvent dataChangedEvent = new DataChangedEvent("/test/config/schema/datasource", dataSource, ChangedType.DELETED);
OrchestrationEvent actual = schemaChangedListener.createOrchestrationEvent(dataChangedEvent);
assertThat(actual, instanceOf(IgnoredOrchestrationEvent.class));
assertThat(actual, instanceOf(SchemaDeletedEvent.class));
}
@Test
......
/*
* 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.infra.callback.orchestration;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.callback.Callback;
/**
* Schema name callback.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SchemaNameCallback extends Callback<Boolean> {
private static final SchemaNameCallback INSTANCE = new SchemaNameCallback();
/**
* Get instance.
*
* @return data source callback
*/
public static SchemaNameCallback getInstance() {
return INSTANCE;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册