Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
4311751a
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4311751a
编写于
8月 27, 2020
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor RequiredArgsConstructor.createOrchestrationEvent's return value to Optional
上级
f2b7f126
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
153 addition
and
143 deletion
+153
-143
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/listener/PostOrchestrationRepositoryEventListener.java
...on/listener/PostOrchestrationRepositoryEventListener.java
+4
-2
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/test/java/org/apache/shardingsphere/orchestration/core/common/event/IgnoredOrchestrationEventTest.java
...tion/core/common/event/IgnoredOrchestrationEventTest.java
+0
-32
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/test/java/org/apache/shardingsphere/orchestration/core/common/listener/PostOrchestrationRepositoryEventListenerTest.java
...istener/PostOrchestrationRepositoryEventListenerTest.java
+5
-4
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/AuthenticationChangedListener.java
...n/core/config/listener/AuthenticationChangedListener.java
+9
-7
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/PropertiesChangedListener.java
...ation/core/config/listener/PropertiesChangedListener.java
+7
-5
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
...estration/core/config/listener/SchemaChangedListener.java
+11
-11
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/AuthenticationChangedListenerTest.java
...re/config/listener/AuthenticationChangedListenerTest.java
+9
-3
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/PropertiesChangedListenerTest.java
...n/core/config/listener/PropertiesChangedListenerTest.java
+8
-1
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
...ation/core/config/listener/SchemaChangedListenerTest.java
+63
-60
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-metadata/src/main/java/org/apache/shardingsphere/orchestration/core/metadata/listener/MetaDataChangedListener.java
...ation/core/metadata/listener/MetaDataChangedListener.java
+3
-2
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-metadata/src/test/java/org/apache/shardingsphere/orchestration/core/metadata/listener/MetaDataChangedListenerTest.java
...n/core/metadata/listener/MetaDataChangedListenerTest.java
+6
-5
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/listener/DataSourceStateChangedListener.java
...ore/registry/listener/DataSourceStateChangedListener.java
+5
-3
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/listener/InstanceStateChangedListener.java
.../core/registry/listener/InstanceStateChangedListener.java
+4
-2
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/test/java/org/apache/shardingsphere/orchestration/core/registry/listener/DataSourceStateChangedListenerTest.java
...registry/listener/DataSourceStateChangedListenerTest.java
+9
-3
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/test/java/org/apache/shardingsphere/orchestration/core/registry/listener/InstanceStateChangedListenerTest.java
...e/registry/listener/InstanceStateChangedListenerTest.java
+10
-3
未找到文件。
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/listener/PostOrchestrationRepositoryEventListener.java
浏览文件 @
4311751a
...
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.orchestration.core.common.eventbus.Orchestratio
...
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.orchestration.core.common.eventbus.Orchestratio
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Optional
;
/**
/**
* Post orchestration repository event listener.
* Post orchestration repository event listener.
...
@@ -51,10 +52,11 @@ public abstract class PostOrchestrationRepositoryEventListener implements Orches
...
@@ -51,10 +52,11 @@ public abstract class PostOrchestrationRepositoryEventListener implements Orches
private
void
watch
(
final
String
watchKey
,
final
Collection
<
ChangedType
>
watchedChangedTypeList
)
{
private
void
watch
(
final
String
watchKey
,
final
Collection
<
ChangedType
>
watchedChangedTypeList
)
{
orchestrationRepository
.
watch
(
watchKey
,
dataChangedEvent
->
{
orchestrationRepository
.
watch
(
watchKey
,
dataChangedEvent
->
{
if
(
watchedChangedTypeList
.
contains
(
dataChangedEvent
.
getChangedType
()))
{
if
(
watchedChangedTypeList
.
contains
(
dataChangedEvent
.
getChangedType
()))
{
eventBus
.
post
(
createOrchestrationEvent
(
dataChangedEvent
));
Optional
<
OrchestrationEvent
>
event
=
createOrchestrationEvent
(
dataChangedEvent
);
event
.
ifPresent
(
eventBus:
:
post
);
}
}
});
});
}
}
protected
abstract
O
rchestrationEvent
createOrchestrationEvent
(
DataChangedEvent
event
);
protected
abstract
O
ptional
<
OrchestrationEvent
>
createOrchestrationEvent
(
DataChangedEvent
event
);
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/test/java/org/apache/shardingsphere/orchestration/core/common/event/IgnoredOrchestrationEventTest.java
已删除
100644 → 0
浏览文件 @
f2b7f126
/*
* 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.orchestration.core.common.event
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
IgnoredOrchestrationEventTest
{
@Test
public
void
assertInstants
()
{
IgnoredOrchestrationEvent
ignored
=
new
IgnoredOrchestrationEvent
();
assertThat
(
ignored
.
getClass
().
getName
(),
is
(
IgnoredOrchestrationEvent
.
class
.
getName
()));
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/test/java/org/apache/shardingsphere/orchestration/core/common/listener/PostOrchestrationRepositoryEventListenerTest.java
浏览文件 @
4311751a
...
@@ -29,6 +29,7 @@ import org.mockito.junit.MockitoJUnitRunner;
...
@@ -29,6 +29,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
...
@@ -48,8 +49,8 @@ public final class PostOrchestrationRepositoryEventListenerTest {
...
@@ -48,8 +49,8 @@ public final class PostOrchestrationRepositoryEventListenerTest {
PostOrchestrationRepositoryEventListener
postEventListener
=
new
PostOrchestrationRepositoryEventListener
(
orchestrationRepository
,
Collections
.
singletonList
(
"test"
))
{
PostOrchestrationRepositoryEventListener
postEventListener
=
new
PostOrchestrationRepositoryEventListener
(
orchestrationRepository
,
Collections
.
singletonList
(
"test"
))
{
@Override
@Override
protected
O
rchestrationEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
O
ptional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
mock
(
OrchestrationEvent
.
class
);
return
Optional
.
of
(
mock
(
OrchestrationEvent
.
class
)
);
}
}
};
};
doAnswer
(
invocationOnMock
->
{
doAnswer
(
invocationOnMock
->
{
...
@@ -66,8 +67,8 @@ public final class PostOrchestrationRepositoryEventListenerTest {
...
@@ -66,8 +67,8 @@ public final class PostOrchestrationRepositoryEventListenerTest {
PostOrchestrationRepositoryEventListener
postEventListener
=
new
PostOrchestrationRepositoryEventListener
(
orchestrationRepository
,
Arrays
.
asList
(
"test"
,
"dev"
))
{
PostOrchestrationRepositoryEventListener
postEventListener
=
new
PostOrchestrationRepositoryEventListener
(
orchestrationRepository
,
Arrays
.
asList
(
"test"
,
"dev"
))
{
@Override
@Override
protected
O
rchestrationEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
O
ptional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
mock
(
OrchestrationEvent
.
class
);
return
Optional
.
of
(
mock
(
OrchestrationEvent
.
class
)
);
}
}
};
};
doAnswer
(
invocationOnMock
->
{
doAnswer
(
invocationOnMock
->
{
...
...
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/AuthenticationChangedListener.java
浏览文件 @
4311751a
...
@@ -17,16 +17,18 @@
...
@@ -17,16 +17,18 @@
package
org.apache.shardingsphere.orchestration.core.config.listener
;
package
org.apache.shardingsphere.orchestration.core.config.listener
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.auth.AuthenticationChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.config.ConfigCenterNode
;
import
org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfiguration
;
import
org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfiguration
;
import
org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper
;
import
org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper
;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.auth.AuthenticationChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.config.ConfigCenterNode
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
/**
/**
* Authentication changed listener.
* Authentication changed listener.
...
@@ -38,7 +40,7 @@ public final class AuthenticationChangedListener extends PostOrchestrationReposi
...
@@ -38,7 +40,7 @@ public final class AuthenticationChangedListener extends PostOrchestrationReposi
}
}
@Override
@Override
protected
AuthenticationChangedEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
Optional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
new
AuthenticationChangedEvent
(
new
AuthenticationYamlSwapper
().
swapToObject
(
YamlEngine
.
unmarshal
(
event
.
getValue
(),
YamlAuthenticationConfiguration
.
class
)));
return
Optional
.
of
(
new
AuthenticationChangedEvent
(
new
AuthenticationYamlSwapper
().
swapToObject
(
YamlEngine
.
unmarshal
(
event
.
getValue
(),
YamlAuthenticationConfiguration
.
class
)
)));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/PropertiesChangedListener.java
浏览文件 @
4311751a
...
@@ -17,14 +17,16 @@
...
@@ -17,14 +17,16 @@
package
org.apache.shardingsphere.orchestration.core.config.listener
;
package
org.apache.shardingsphere.orchestration.core.config.listener
;
import
org.apache.shardingsphere.
orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.
infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.orchestration.
repository.api.listener.DataChanged
Event
;
import
org.apache.shardingsphere.orchestration.
core.common.event.Orchestration
Event
;
import
org.apache.shardingsphere.orchestration.core.common.event.props.PropertiesChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.props.PropertiesChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.config.ConfigCenterNode
;
import
org.apache.shardingsphere.orchestration.core.config.ConfigCenterNode
;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
/**
/**
* Properties changed listener.
* Properties changed listener.
...
@@ -36,7 +38,7 @@ public final class PropertiesChangedListener extends PostOrchestrationRepository
...
@@ -36,7 +38,7 @@ public final class PropertiesChangedListener extends PostOrchestrationRepository
}
}
@Override
@Override
protected
PropertiesChangedEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
Optional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
new
PropertiesChangedEvent
(
YamlEngine
.
unmarshalProperties
(
event
.
getValue
(
)));
return
Optional
.
of
(
new
PropertiesChangedEvent
(
YamlEngine
.
unmarshalProperties
(
event
.
getValue
()
)));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
浏览文件 @
4311751a
...
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
...
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine
;
import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine
;
import
org.apache.shardingsphere.orchestration.core.common.event.DataSourceChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.DataSourceChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.IgnoredOrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaAddedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaAddedEvent
;
...
@@ -45,6 +44,7 @@ import java.util.HashSet;
...
@@ -45,6 +44,7 @@ import java.util.HashSet;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -67,38 +67,38 @@ public final class SchemaChangedListener extends PostOrchestrationRepositoryEven
...
@@ -67,38 +67,38 @@ public final class SchemaChangedListener extends PostOrchestrationRepositoryEven
}
}
@Override
@Override
protected
O
rchestrationEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
O
ptional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
// TODO Consider removing the following one.
// TODO Consider removing the following one.
if
(
configurationNode
.
getSchemaPath
().
equals
(
event
.
getKey
()))
{
if
(
configurationNode
.
getSchemaPath
().
equals
(
event
.
getKey
()))
{
return
createSchemaNamesUpdatedEvent
(
event
.
getValue
());
return
createSchemaNamesUpdatedEvent
(
event
.
getValue
());
}
}
String
shardingSchemaName
=
configurationNode
.
getSchemaName
(
event
.
getKey
());
String
shardingSchemaName
=
configurationNode
.
getSchemaName
(
event
.
getKey
());
if
(
Strings
.
isNullOrEmpty
(
shardingSchemaName
)
||
!
isValidNodeChangedEvent
(
shardingSchemaName
,
event
.
getKey
()))
{
if
(
Strings
.
isNullOrEmpty
(
shardingSchemaName
)
||
!
isValidNodeChangedEvent
(
shardingSchemaName
,
event
.
getKey
()))
{
return
new
IgnoredOrchestrationEvent
();
return
Optional
.
empty
();
}
}
if
(
ChangedType
.
ADDED
==
event
.
getChangedType
())
{
if
(
ChangedType
.
ADDED
==
event
.
getChangedType
())
{
return
createAddedEvent
(
shardingSchemaName
);
return
Optional
.
of
(
createAddedEvent
(
shardingSchemaName
)
);
}
}
if
(
ChangedType
.
UPDATED
==
event
.
getChangedType
())
{
if
(
ChangedType
.
UPDATED
==
event
.
getChangedType
())
{
return
createUpdatedEvent
(
shardingSchemaName
,
event
);
return
Optional
.
of
(
createUpdatedEvent
(
shardingSchemaName
,
event
)
);
}
}
if
(
ChangedType
.
DELETED
==
event
.
getChangedType
())
{
if
(
ChangedType
.
DELETED
==
event
.
getChangedType
())
{
return
createDeletedEvent
(
shardingSchemaName
);
return
Optional
.
of
(
createDeletedEvent
(
shardingSchemaName
)
);
}
}
return
new
IgnoredOrchestrationEvent
();
return
Optional
.
empty
();
}
}
private
O
rchestrationEvent
createSchemaNamesUpdatedEvent
(
final
String
shardingSchemaNames
)
{
private
O
ptional
<
OrchestrationEvent
>
createSchemaNamesUpdatedEvent
(
final
String
shardingSchemaNames
)
{
Collection
<
String
>
persistShardingSchemaNames
=
configurationNode
.
splitSchemaName
(
shardingSchemaNames
);
Collection
<
String
>
persistShardingSchemaNames
=
configurationNode
.
splitSchemaName
(
shardingSchemaNames
);
Set
<
String
>
addedSchemaNames
=
SetUtils
.
difference
(
new
HashSet
<>(
persistShardingSchemaNames
),
new
HashSet
<>(
existedSchemaNames
));
Set
<
String
>
addedSchemaNames
=
SetUtils
.
difference
(
new
HashSet
<>(
persistShardingSchemaNames
),
new
HashSet
<>(
existedSchemaNames
));
if
(!
addedSchemaNames
.
isEmpty
())
{
if
(!
addedSchemaNames
.
isEmpty
())
{
return
createAddedEvent
(
addedSchemaNames
.
iterator
().
next
(
));
return
Optional
.
of
(
createAddedEvent
(
addedSchemaNames
.
iterator
().
next
()
));
}
}
Set
<
String
>
deletedSchemaNames
=
SetUtils
.
difference
(
new
HashSet
<>(
existedSchemaNames
),
new
HashSet
<>(
persistShardingSchemaNames
));
Set
<
String
>
deletedSchemaNames
=
SetUtils
.
difference
(
new
HashSet
<>(
existedSchemaNames
),
new
HashSet
<>(
persistShardingSchemaNames
));
if
(!
deletedSchemaNames
.
isEmpty
())
{
if
(!
deletedSchemaNames
.
isEmpty
())
{
return
createDeletedEvent
(
deletedSchemaNames
.
iterator
().
next
(
));
return
Optional
.
of
(
createDeletedEvent
(
deletedSchemaNames
.
iterator
().
next
()
));
}
}
return
new
IgnoredOrchestrationEvent
();
return
Optional
.
empty
();
}
}
private
boolean
isValidNodeChangedEvent
(
final
String
shardingSchemaName
,
final
String
nodeFullPath
)
{
private
boolean
isValidNodeChangedEvent
(
final
String
shardingSchemaName
,
final
String
nodeFullPath
)
{
...
...
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/AuthenticationChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -17,17 +17,22 @@
...
@@ -17,17 +17,22 @@
package
org.apache.shardingsphere.orchestration.core.config.listener
;
package
org.apache.shardingsphere.orchestration.core.config.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.auth.AuthenticationChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.Optional
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
AuthenticationChangedListenerTest
{
public
final
class
AuthenticationChangedListenerTest
{
...
@@ -47,7 +52,8 @@ public final class AuthenticationChangedListenerTest {
...
@@ -47,7 +52,8 @@ public final class AuthenticationChangedListenerTest {
@Test
@Test
public
void
assertCreateOrchestrationEvent
()
{
public
void
assertCreateOrchestrationEvent
()
{
assertThat
(
authenticationChangedListener
.
createOrchestrationEvent
(
Optional
<
OrchestrationEvent
>
actual
=
authenticationChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"test"
,
AUTHENTICATION_YAML
,
ChangedType
.
UPDATED
));
new
DataChangedEvent
(
"test"
,
AUTHENTICATION_YAML
,
ChangedType
.
UPDATED
)).
getAuthentication
().
getUsers
().
get
(
"root1"
).
getPassword
(),
is
(
"root1"
));
assertTrue
(
actual
.
isPresent
());
assertThat
(((
AuthenticationChangedEvent
)
actual
.
get
()).
getAuthentication
().
getUsers
().
get
(
"root1"
).
getPassword
(),
is
(
"root1"
));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/PropertiesChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.orchestration.core.config.listener
;
package
org.apache.shardingsphere.orchestration.core.config.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.props.PropertiesChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
...
@@ -26,8 +28,11 @@ import org.junit.runner.RunWith;
...
@@ -26,8 +28,11 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.Optional
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PropertiesChangedListenerTest
{
public
final
class
PropertiesChangedListenerTest
{
...
@@ -46,6 +51,8 @@ public final class PropertiesChangedListenerTest {
...
@@ -46,6 +51,8 @@ public final class PropertiesChangedListenerTest {
@Test
@Test
public
void
assertCreateOrchestrationEvent
()
{
public
void
assertCreateOrchestrationEvent
()
{
assertThat
(
propertiesChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"test"
,
PROPERTIES_YAML
,
ChangedType
.
UPDATED
)).
getProps
().
get
(
"sql.show"
),
is
(
true
));
Optional
<
OrchestrationEvent
>
actual
=
propertiesChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"test"
,
PROPERTIES_YAML
,
ChangedType
.
UPDATED
));
assertTrue
(
actual
.
isPresent
());
assertThat
(((
PropertiesChangedEvent
)
actual
.
get
()).
getProps
().
get
(
"sql.show"
),
is
(
true
));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -22,15 +22,14 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
...
@@ -22,15 +22,14 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.infra.config.RuleConfiguration
;
import
org.apache.shardingsphere.infra.config.RuleConfiguration
;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration
;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration
;
import
org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration
;
import
org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.core.common.event.DataSourceChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.DataSourceChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.
Ignored
OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaAddedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaAddedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaDeletedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.schema.SchemaDeletedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration
;
import
org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -42,11 +41,14 @@ import java.nio.file.Files;
...
@@ -42,11 +41,14 @@ import java.nio.file.Files;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
...
@@ -72,29 +74,28 @@ public final class SchemaChangedListenerTest {
...
@@ -72,29 +74,28 @@ public final class SchemaChangedListenerTest {
@Test
@Test
public
void
assertCreateIgnoredEvent
()
{
public
void
assertCreateIgnoredEvent
()
{
assertThat
(
schemaChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/config/schema/encrypt_db"
,
"test"
,
ChangedType
.
UPDATED
)),
assertFalse
(
schemaChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/config/schema/encrypt_db"
,
"test"
,
ChangedType
.
UPDATED
)).
isPresent
());
instanceOf
(
IgnoredOrchestrationEvent
.
class
));
assertFalse
(
schemaChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/config/schema/encrypt_db/rule"
,
"test"
,
ChangedType
.
IGNORED
)).
isPresent
());
assertThat
(
schemaChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/config/schema/encrypt_db/rule"
,
"test"
,
ChangedType
.
IGNORED
)),
instanceOf
(
IgnoredOrchestrationEvent
.
class
));
}
}
@Test
@Test
public
void
assertCreateDataSourceChangedEventForExistedSchema
()
{
public
void
assertCreateDataSourceChangedEventForExistedSchema
()
{
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/sharding_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/sharding_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
OrchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
Optional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertThat
(
actual
,
instanceOf
(
DataSourceChangedEvent
.
class
));
assertTrue
(
actual
.
isPresent
());
assertThat
(((
DataSourceChangedEvent
)
actual
).
getShardingSchemaName
(),
is
(
"sharding_db"
));
assertThat
(
actual
.
get
(),
instanceOf
(
DataSourceChangedEvent
.
class
));
assertThat
(((
DataSourceChangedEvent
)
actual
.
get
()).
getShardingSchemaName
(),
is
(
"sharding_db"
));
}
}
@Test
@Test
public
void
assertCreateRuleConfigurationsChangedEventForExistedSchema
()
{
public
void
assertCreateRuleConfigurationsChangedEventForExistedSchema
()
{
String
shardingRule
=
readYAML
(
SHARDING_RULE_FILE
);
String
shardingRule
=
readYAML
(
SHARDING_RULE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/sharding_db/rule"
,
shardingRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/sharding_db/rule"
,
shardingRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
RuleConfigurationsChangedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
RuleConfigurationsChangedEvent
)
actual
).
getShardingSchemaName
(),
is
(
"sharding_db"
));
assertThat
(((
RuleConfigurationsChangedEvent
)
actual
.
get
()
).
getShardingSchemaName
(),
is
(
"sharding_db"
));
Collection
<
RuleConfiguration
>
ruleConfigurations
=
((
RuleConfigurationsChangedEvent
)
actual
).
getRuleConfigurations
();
Collection
<
RuleConfiguration
>
ruleConfigurations
=
((
RuleConfigurationsChangedEvent
)
actual
.
get
()
).
getRuleConfigurations
();
assertThat
(
ruleConfigurations
.
size
(),
is
(
1
));
assertThat
(
ruleConfigurations
.
size
(),
is
(
1
));
assertThat
(((
ShardingRuleConfiguration
)
ruleConfigurations
.
iterator
().
next
()).
getTables
().
size
(),
is
(
1
));
assertThat
(((
ShardingRuleConfiguration
)
ruleConfigurations
.
iterator
().
next
()).
getTables
().
size
(),
is
(
1
));
}
}
...
@@ -103,9 +104,9 @@ public final class SchemaChangedListenerTest {
...
@@ -103,9 +104,9 @@ public final class SchemaChangedListenerTest {
public
void
assertCreateMasterSlaveRuleChangedEventForExistedSchema
()
{
public
void
assertCreateMasterSlaveRuleChangedEventForExistedSchema
()
{
String
masterSlaveRule
=
readYAML
(
MASTER_SLAVE_RULE_FILE
);
String
masterSlaveRule
=
readYAML
(
MASTER_SLAVE_RULE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/masterslave_db/rule"
,
masterSlaveRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/masterslave_db/rule"
,
masterSlaveRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
RuleConfigurationsChangedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
RuleConfigurationsChangedEvent
event
=
(
RuleConfigurationsChangedEvent
)
actual
;
RuleConfigurationsChangedEvent
event
=
(
RuleConfigurationsChangedEvent
)
actual
.
get
()
;
assertThat
(
event
.
getShardingSchemaName
(),
is
(
"masterslave_db"
));
assertThat
(
event
.
getShardingSchemaName
(),
is
(
"masterslave_db"
));
assertThat
(
event
.
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
assertThat
(
event
.
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
MasterSlaveRuleConfiguration
masterSlaveRuleConfig
=
(
MasterSlaveRuleConfiguration
)
event
.
getRuleConfigurations
().
iterator
().
next
();
MasterSlaveRuleConfiguration
masterSlaveRuleConfig
=
(
MasterSlaveRuleConfiguration
)
event
.
getRuleConfigurations
().
iterator
().
next
();
...
@@ -116,9 +117,9 @@ public final class SchemaChangedListenerTest {
...
@@ -116,9 +117,9 @@ public final class SchemaChangedListenerTest {
public
void
assertCreateEncryptRuleChangedEventForExistedSchema
()
{
public
void
assertCreateEncryptRuleChangedEventForExistedSchema
()
{
String
encryptRule
=
readYAML
(
ENCRYPT_RULE_FILE
);
String
encryptRule
=
readYAML
(
ENCRYPT_RULE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/encrypt_db/rule"
,
encryptRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/encrypt_db/rule"
,
encryptRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
RuleConfigurationsChangedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
RuleConfigurationsChangedEvent
event
=
(
RuleConfigurationsChangedEvent
)
actual
;
RuleConfigurationsChangedEvent
event
=
(
RuleConfigurationsChangedEvent
)
actual
.
get
()
;
assertThat
(
event
.
getShardingSchemaName
(),
is
(
"encrypt_db"
));
assertThat
(
event
.
getShardingSchemaName
(),
is
(
"encrypt_db"
));
assertThat
(
event
.
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
assertThat
(
event
.
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
EncryptRuleConfiguration
encryptRuleConfig
=
(
EncryptRuleConfiguration
)
event
.
getRuleConfigurations
().
iterator
().
next
();
EncryptRuleConfiguration
encryptRuleConfig
=
(
EncryptRuleConfiguration
)
event
.
getRuleConfigurations
().
iterator
().
next
();
...
@@ -132,8 +133,9 @@ public final class SchemaChangedListenerTest {
...
@@ -132,8 +133,9 @@ public final class SchemaChangedListenerTest {
public
void
assertCreateIgnoredOrchestrationEventForNewSchema
()
{
public
void
assertCreateIgnoredOrchestrationEventForNewSchema
()
{
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
""
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
""
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
"rule"
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
"rule"
,
ChangedType
.
UPDATED
);
OrchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
Optional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertThat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertTrue
(
actual
.
isPresent
());
assertThat
(
actual
.
get
(),
instanceOf
(
SchemaAddedEvent
.
class
));
}
}
@Test
@Test
...
@@ -145,9 +147,9 @@ public final class SchemaChangedListenerTest {
...
@@ -145,9 +147,9 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
shardingRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
shardingRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
ShardingRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
ShardingRuleConfiguration
.
class
));
}
}
@Test
@Test
...
@@ -159,9 +161,9 @@ public final class SchemaChangedListenerTest {
...
@@ -159,9 +161,9 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
masterSlaveRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
masterSlaveRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
}
}
@Test
@Test
...
@@ -173,34 +175,36 @@ public final class SchemaChangedListenerTest {
...
@@ -173,34 +175,36 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
encryptRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
encryptRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
}
}
@Test
@Test
public
void
assertCreateSchemaDeletedEventForNewSchema
()
{
public
void
assertCreateSchemaDeletedEventForNewSchema
()
{
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
DELETED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/datasource"
,
dataSource
,
ChangedType
.
DELETED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaDeletedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaDeletedEvent
)
actual
).
getSchemaName
(),
is
(
"logic_db"
));
assertThat
(((
SchemaDeletedEvent
)
actual
.
get
()
).
getSchemaName
(),
is
(
"logic_db"
));
}
}
@Test
@Test
public
void
assertCreateWithSchemaDeletedEvent
()
{
public
void
assertCreateWithSchemaDeletedEvent
()
{
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db"
,
dataSource
,
ChangedType
.
DELETED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db"
,
dataSource
,
ChangedType
.
DELETED
);
OrchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
Optional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertThat
(
actual
,
instanceOf
(
SchemaDeletedEvent
.
class
));
assertTrue
(
actual
.
isPresent
());
assertThat
(
actual
.
get
(),
instanceOf
(
SchemaDeletedEvent
.
class
));
}
}
@Test
@Test
public
void
assertCreateWithSchemaDeletedEventWithDataSourceNode
()
{
public
void
assertCreateWithSchemaDeletedEventWithDataSourceNode
()
{
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
String
dataSource
=
readYAML
(
DATA_SOURCE_FILE
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/datasource"
,
dataSource
,
ChangedType
.
DELETED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/datasource"
,
dataSource
,
ChangedType
.
DELETED
);
OrchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
Optional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertThat
(
actual
,
instanceOf
(
SchemaDeletedEvent
.
class
));
assertTrue
(
actual
.
isPresent
());
assertThat
(
actual
.
get
(),
instanceOf
(
SchemaDeletedEvent
.
class
));
}
}
@Test
@Test
...
@@ -210,9 +214,9 @@ public final class SchemaChangedListenerTest {
...
@@ -210,9 +214,9 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
encryptRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
encryptRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
encryptRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
encryptRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
EncryptRuleConfiguration
.
class
));
}
}
@Test
@Test
...
@@ -222,9 +226,9 @@ public final class SchemaChangedListenerTest {
...
@@ -222,9 +226,9 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
shardingRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
shardingRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
shardingRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
shardingRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
ShardingRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
ShardingRuleConfiguration
.
class
));
}
}
@Test
@Test
...
@@ -234,40 +238,39 @@ public final class SchemaChangedListenerTest {
...
@@ -234,40 +238,39 @@ public final class SchemaChangedListenerTest {
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
masterSlaveRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/rule"
)).
thenReturn
(
masterSlaveRule
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
when
(
configurationRepository
.
get
(
"/config/schema/logic_db/datasource"
)).
thenReturn
(
dataSource
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
masterSlaveRule
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/logic_db/rule"
,
masterSlaveRule
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getRuleConfigurations
().
iterator
().
next
(),
instanceOf
(
MasterSlaveRuleConfiguration
.
class
));
}
}
@Test
@Test
public
void
assertCreateSchemaNamesUpdatedEventForAdd
()
{
public
void
assertCreateSchemaNamesUpdatedEventForAdd
()
{
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db,encrypt_db,shadow_db"
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db,encrypt_db,shadow_db"
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getSchemaName
(),
is
(
"shadow_db"
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getSchemaName
(),
is
(
"shadow_db"
));
}
}
@Test
@Test
public
void
assertCreateSchemaNamesUpdatedEventForDelete
()
{
public
void
assertCreateSchemaNamesUpdatedEventForDelete
()
{
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db"
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db"
,
ChangedType
.
UPDATED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaDeletedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaDeletedEvent
)
actual
).
getSchemaName
(),
is
(
"encrypt_db"
));
assertThat
(((
SchemaDeletedEvent
)
actual
.
get
()
).
getSchemaName
(),
is
(
"encrypt_db"
));
}
}
@Test
@Test
public
void
assertCreateSchemaNamesUpdatedEventForIgnore
()
{
public
void
assertCreateSchemaNamesUpdatedEventForIgnore
()
{
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db,encrypt_db"
,
ChangedType
.
UPDATED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema"
,
"sharding_db,masterslave_db,encrypt_db"
,
ChangedType
.
UPDATED
);
OrchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertFalse
(
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
).
isPresent
());
assertThat
(
actual
,
instanceOf
(
IgnoredOrchestrationEvent
.
class
));
}
}
@Test
@Test
public
void
assertCreateSchemaNameAddEvent
()
{
public
void
assertCreateSchemaNameAddEvent
()
{
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/shadow_db"
,
""
,
ChangedType
.
ADDED
);
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/config/schema/shadow_db"
,
""
,
ChangedType
.
ADDED
);
O
rchestrationEvent
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
O
ptional
<
OrchestrationEvent
>
actual
=
schemaChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
);
assertT
hat
(
actual
,
instanceOf
(
SchemaAddedEvent
.
class
));
assertT
rue
(
actual
.
isPresent
(
));
assertThat
(((
SchemaAddedEvent
)
actual
).
getSchemaName
(),
is
(
"shadow_db"
));
assertThat
(((
SchemaAddedEvent
)
actual
.
get
()
).
getSchemaName
(),
is
(
"shadow_db"
));
}
}
@SneakyThrows
@SneakyThrows
...
...
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-metadata/src/main/java/org/apache/shardingsphere/orchestration/core/metadata/listener/MetaDataChangedListener.java
浏览文件 @
4311751a
...
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
...
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
org.apache.shardingsphere.infra.yaml.engine.YamlEngine
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Optional
;
/**
/**
* Meta data changed listener.
* Meta data changed listener.
...
@@ -43,8 +44,8 @@ public final class MetaDataChangedListener extends PostOrchestrationRepositoryEv
...
@@ -43,8 +44,8 @@ public final class MetaDataChangedListener extends PostOrchestrationRepositoryEv
}
}
@Override
@Override
protected
O
rchestrationEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
O
ptional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
RuleSchemaMetaData
ruleSchemaMetaData
=
new
RuleSchemaMetaDataYamlSwapper
().
swapToObject
(
YamlEngine
.
unmarshal
(
event
.
getValue
(),
YamlRuleSchemaMetaData
.
class
));
RuleSchemaMetaData
ruleSchemaMetaData
=
new
RuleSchemaMetaDataYamlSwapper
().
swapToObject
(
YamlEngine
.
unmarshal
(
event
.
getValue
(),
YamlRuleSchemaMetaData
.
class
));
return
new
MetaDataChangedEvent
(
schemaNames
,
ruleSchemaMetaData
);
return
Optional
.
of
(
new
MetaDataChangedEvent
(
schemaNames
,
ruleSchemaMetaData
)
);
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-metadata/src/test/java/org/apache/shardingsphere/orchestration/core/metadata/listener/MetaDataChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org.apache.shardingsphere.orchestration.core.metadata.listener
;
package
org.apache.shardingsphere.orchestration.core.metadata.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.metadata.MetaDataJson
;
import
org.apache.shardingsphere.orchestration.core.metadata.MetaDataJson
;
import
org.apache.shardingsphere.orchestration.core.metadata.event.MetaDataChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.metadata.event.MetaDataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository
;
...
@@ -27,10 +28,11 @@ import org.junit.Test;
...
@@ -27,10 +28,11 @@ import org.junit.Test;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
final
class
MetaDataChangedListenerTest
{
public
final
class
MetaDataChangedListenerTest
{
...
@@ -46,9 +48,8 @@ public final class MetaDataChangedListenerTest {
...
@@ -46,9 +48,8 @@ public final class MetaDataChangedListenerTest {
@Test
@Test
public
void
createOrchestrationEvent
()
{
public
void
createOrchestrationEvent
()
{
DataChangedEvent
event
=
new
DataChangedEvent
(
"/metadata/schema"
,
MetaDataJson
.
META_DATA
,
ChangedType
.
UPDATED
);
Optional
<
OrchestrationEvent
>
actual
=
metaDataChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/metadata/schema"
,
MetaDataJson
.
META_DATA
,
ChangedType
.
UPDATED
));
MetaDataChangedEvent
metaDataChangedEvent
=
(
MetaDataChangedEvent
)
metaDataChangedListener
.
createOrchestrationEvent
(
event
);
assertTrue
(
actual
.
isPresent
());
assertNotNull
(
metaDataChangedEvent
);
assertThat
(((
MetaDataChangedEvent
)
actual
.
get
()).
getSchemaNames
(),
is
(
Collections
.
singleton
(
"schema"
)));
assertThat
(
metaDataChangedEvent
.
getSchemaNames
(),
is
(
Collections
.
singleton
(
"schema"
)));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/listener/DataSourceStateChangedListener.java
浏览文件 @
4311751a
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNode
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNode
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
import
org.apache.shardingsphere.orchestration.core.registry.event.DisabledStateChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.registry.event.DisabledStateChangedEvent
;
...
@@ -24,9 +26,9 @@ import org.apache.shardingsphere.orchestration.core.registry.schema.Orchestratio
...
@@ -24,9 +26,9 @@ import org.apache.shardingsphere.orchestration.core.registry.schema.Orchestratio
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
/**
/**
* Data source state changed listener.
* Data source state changed listener.
...
@@ -41,8 +43,8 @@ public final class DataSourceStateChangedListener extends PostOrchestrationRepos
...
@@ -41,8 +43,8 @@ public final class DataSourceStateChangedListener extends PostOrchestrationRepos
}
}
@Override
@Override
protected
DisabledStateChangedEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
Optional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
new
DisabledStateChangedEvent
(
getShardingSchema
(
event
.
getKey
()),
isDataSourceDisabled
(
event
));
return
Optional
.
of
(
new
DisabledStateChangedEvent
(
getShardingSchema
(
event
.
getKey
()),
isDataSourceDisabled
(
event
)
));
}
}
private
OrchestrationSchema
getShardingSchema
(
final
String
dataSourceNodeFullPath
)
{
private
OrchestrationSchema
getShardingSchema
(
final
String
dataSourceNodeFullPath
)
{
...
...
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/listener/InstanceStateChangedListener.java
浏览文件 @
4311751a
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNode
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNode
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
...
@@ -26,6 +27,7 @@ import org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
...
@@ -26,6 +27,7 @@ import org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Optional
;
/**
/**
* Instance state changed listener.
* Instance state changed listener.
...
@@ -37,7 +39,7 @@ public final class InstanceStateChangedListener extends PostOrchestrationReposit
...
@@ -37,7 +39,7 @@ public final class InstanceStateChangedListener extends PostOrchestrationReposit
}
}
@Override
@Override
protected
CircuitStateChangedEvent
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
protected
Optional
<
OrchestrationEvent
>
createOrchestrationEvent
(
final
DataChangedEvent
event
)
{
return
new
CircuitStateChangedEvent
(
RegistryCenterNodeStatus
.
DISABLED
.
toString
().
equalsIgnoreCase
(
event
.
getValue
(
)));
return
Optional
.
of
(
new
CircuitStateChangedEvent
(
RegistryCenterNodeStatus
.
DISABLED
.
toString
().
equalsIgnoreCase
(
event
.
getValue
()
)));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/test/java/org/apache/shardingsphere/orchestration/core/registry/listener/DataSourceStateChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.registry.event.DisabledStateChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.registry.schema.OrchestrationSchema
;
import
org.apache.shardingsphere.orchestration.core.registry.schema.OrchestrationSchema
;
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
...
@@ -27,8 +29,11 @@ import org.junit.runner.RunWith;
...
@@ -27,8 +29,11 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.Optional
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
DataSourceStateChangedListenerTest
{
public
final
class
DataSourceStateChangedListenerTest
{
...
@@ -45,8 +50,9 @@ public final class DataSourceStateChangedListenerTest {
...
@@ -45,8 +50,9 @@ public final class DataSourceStateChangedListenerTest {
@Test
@Test
public
void
assertCreateOrchestrationEvent
()
{
public
void
assertCreateOrchestrationEvent
()
{
OrchestrationSchema
expected
=
new
OrchestrationSchema
(
"master_slave_db"
,
"slave_ds_0"
);
Optional
<
OrchestrationEvent
>
actual
=
dataSourceStateChangedListener
.
createOrchestrationEvent
(
DataChangedEvent
dataChangedEvent
=
new
DataChangedEvent
(
"/registry/datasources/master_slave_db.slave_ds_0"
,
"disabled"
,
ChangedType
.
UPDATED
);
new
DataChangedEvent
(
"/registry/datasources/master_slave_db.slave_ds_0"
,
"disabled"
,
ChangedType
.
UPDATED
));
assertThat
(
dataSourceStateChangedListener
.
createOrchestrationEvent
(
dataChangedEvent
).
getOrchestrationSchema
().
getSchemaName
(),
is
(
expected
.
getSchemaName
()));
assertTrue
(
actual
.
isPresent
());
assertThat
(((
DisabledStateChangedEvent
)
actual
.
get
()).
getOrchestrationSchema
().
getSchemaName
(),
is
(
new
OrchestrationSchema
(
"master_slave_db"
,
"slave_ds_0"
).
getSchemaName
()));
}
}
}
}
shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/test/java/org/apache/shardingsphere/orchestration/core/registry/listener/InstanceStateChangedListenerTest.java
浏览文件 @
4311751a
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
package
org.apache.shardingsphere.orchestration.core.registry.listener
;
import
org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
import
org.apache.shardingsphere.orchestration.core.registry.RegistryCenterNodeStatus
;
import
org.apache.shardingsphere.orchestration.core.registry.event.CircuitStateChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.RegistryRepository
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
import
org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType
;
...
@@ -27,6 +29,8 @@ import org.junit.runner.RunWith;
...
@@ -27,6 +29,8 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.Optional
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
@@ -45,12 +49,15 @@ public final class InstanceStateChangedListenerTest {
...
@@ -45,12 +49,15 @@ public final class InstanceStateChangedListenerTest {
@Test
@Test
public
void
assertCreateOrchestrationEventWhenEnabled
()
{
public
void
assertCreateOrchestrationEventWhenEnabled
()
{
assertFalse
(
instanceStateChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/test_ds"
,
""
,
ChangedType
.
UPDATED
)).
isCircuitBreak
());
Optional
<
OrchestrationEvent
>
actual
=
instanceStateChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/test_ds"
,
""
,
ChangedType
.
UPDATED
));
assertTrue
(
actual
.
isPresent
());
assertFalse
(((
CircuitStateChangedEvent
)
actual
.
get
()).
isCircuitBreak
());
}
}
@Test
@Test
public
void
assertCreateOrchestrationEventWhenDisabled
()
{
public
void
assertCreateOrchestrationEventWhenDisabled
()
{
assertTrue
(
instanceStateChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/test_ds"
,
Optional
<
OrchestrationEvent
>
actual
=
instanceStateChangedListener
.
createOrchestrationEvent
(
new
DataChangedEvent
(
"/test_ds"
,
RegistryCenterNodeStatus
.
DISABLED
.
name
(),
ChangedType
.
UPDATED
));
RegistryCenterNodeStatus
.
DISABLED
.
name
(),
ChangedType
.
UPDATED
)).
isCircuitBreak
());
assertTrue
(
actual
.
isPresent
());
assertTrue
(((
CircuitStateChangedEvent
)
actual
.
get
()).
isCircuitBreak
());
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录