Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
864b095d
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,发现更多精彩内容 >>
提交
864b095d
编写于
11月 28, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ConfigurationOrchestrationListenerManager & StateOrchestrationListenerManager
上级
51a8ee72
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
361 addition
and
95 deletion
+361
-95
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/RegistryCenterLoader.java
...ngsphere/orchestration/internal/RegistryCenterLoader.java
+2
-2
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/listener/ConfigurationOrchestrationListenerManager.java
...g/listener/ConfigurationOrchestrationListenerManager.java
+66
-0
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListener.java
...rchestration/internal/listener/OrchestrationListener.java
+1
-1
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListenerManager.java
...ation/internal/listener/OrchestrationListenerManager.java
+10
-51
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/state/listener/StateOrchestrationListenerManager.java
...nal/state/listener/StateOrchestrationListenerManager.java
+45
-0
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/yaml/YamlOrchestrationConfiguration.java
...tration/internal/yaml/YamlOrchestrationConfiguration.java
+1
-1
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/AllInternalTests.java
...ardingsphere/orchestration/internal/AllInternalTests.java
+3
-1
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/OrchestrationFacadeTest.java
...phere/orchestration/internal/OrchestrationFacadeTest.java
+13
-29
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/config/AllConfigTests.java
...gsphere/orchestration/internal/config/AllConfigTests.java
+13
-3
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/config/listener/ConfigurationOrchestrationListenerManagerTest.java
...stener/ConfigurationOrchestrationListenerManagerTest.java
+81
-0
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/listener/AllListenerTests.java
...ere/orchestration/internal/listener/AllListenerTests.java
+2
-5
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListenerManagerTest.java
...n/internal/listener/OrchestrationListenerManagerTest.java
+60
-0
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/state/AllStateTests.java
...ingsphere/orchestration/internal/state/AllStateTests.java
+6
-2
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/state/listener/StateOrchestrationListenerManagerTest.java
...state/listener/StateOrchestrationListenerManagerTest.java
+57
-0
sharding-orchestration/sharding-orchestration-core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
...esources/mockito-extensions/org.mockito.plugins.MockMaker
+1
-0
未找到文件。
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/RegistryCenterLoader.java
浏览文件 @
864b095d
...
...
@@ -46,9 +46,9 @@ public final class RegistryCenterLoader {
result
=
each
;
count
++;
}
Preconditions
.
checkNotNull
(
result
,
"Cannot load implementation class for registry center"
);
Preconditions
.
checkNotNull
(
result
,
"Cannot load implementation class for registry center
.
"
);
if
(
1
!=
count
)
{
log
.
warn
(
"Find more than one registry center implementation class, use `{}` now"
,
result
.
getClass
().
getName
());
log
.
warn
(
"Find more than one registry center implementation class, use `{}` now
.
"
,
result
.
getClass
().
getName
());
}
result
.
init
(
regCenterConfig
);
return
result
;
...
...
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/listener/ConfigurationOrchestrationListenerManager.java
0 → 100644
浏览文件 @
864b095d
/*
* 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.orchestration.internal.config.listener
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
java.util.Collection
;
import
java.util.LinkedList
;
/**
* Configuration orchestration listener manager.
*
* @author zhangliang
*/
public
final
class
ConfigurationOrchestrationListenerManager
{
private
final
Collection
<
RuleOrchestrationListener
>
ruleListenerManagers
=
new
LinkedList
<>();
private
final
Collection
<
DataSourceOrchestrationListener
>
dataSourceListenerManagers
=
new
LinkedList
<>();
private
final
PropertiesOrchestrationListener
propertiesListenerManager
;
private
final
AuthenticationOrchestrationListener
authenticationListenerManager
;
private
final
ConfigMapOrchestrationListener
configMapListenerManager
;
public
ConfigurationOrchestrationListenerManager
(
final
String
name
,
final
RegistryCenter
regCenter
,
final
Collection
<
String
>
shardingSchemaNames
)
{
for
(
String
each
:
shardingSchemaNames
)
{
ruleListenerManagers
.
add
(
new
RuleOrchestrationListener
(
name
,
regCenter
,
each
));
dataSourceListenerManagers
.
add
(
new
DataSourceOrchestrationListener
(
name
,
regCenter
,
each
));
}
propertiesListenerManager
=
new
PropertiesOrchestrationListener
(
name
,
regCenter
);
authenticationListenerManager
=
new
AuthenticationOrchestrationListener
(
name
,
regCenter
);
configMapListenerManager
=
new
ConfigMapOrchestrationListener
(
name
,
regCenter
);
}
/**
* Initialize all configuration orchestration listeners.
*/
public
void
initListeners
()
{
for
(
RuleOrchestrationListener
each
:
ruleListenerManagers
)
{
each
.
watch
();
}
for
(
DataSourceOrchestrationListener
each
:
dataSourceListenerManagers
)
{
each
.
watch
();
}
propertiesListenerManager
.
watch
();
authenticationListenerManager
.
watch
();
configMapListenerManager
.
watch
();
}
}
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListener.java
浏览文件 @
864b095d
...
...
@@ -18,7 +18,7 @@
package
io.shardingsphere.orchestration.internal.listener
;
/**
*
Registry center's listener manag
er.
*
Orchestration listen
er.
*
* @author caohao
* @author panjuan
...
...
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListenerManager.java
浏览文件 @
864b095d
...
...
@@ -17,75 +17,34 @@
package
io.shardingsphere.orchestration.internal.listener
;
import
io.shardingsphere.orchestration.internal.config.listener.AuthenticationOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigMapOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.RuleOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.DataSourceOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.PropertiesOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.state.listener.DataSourceStateOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.state.listener.InstanceStateOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigurationOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.internal.state.listener.StateOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
java.util.Collection
;
import
java.util.LinkedList
;
/**
*
Registry center's
listener manager.
*
Orchestration
listener manager.
*
* @author caohao
* @author panjuan
*/
public
final
class
OrchestrationListenerManager
{
private
final
Co
llection
<
RuleOrchestrationListener
>
ruleListenerManagers
=
new
LinkedList
<>()
;
private
final
Co
nfigurationOrchestrationListenerManager
configOrchestrationListenerManager
;
private
final
Collection
<
DataSourceOrchestrationListener
>
dataSourceListenerManagers
=
new
LinkedList
<>();
private
final
PropertiesOrchestrationListener
propertiesListenerManager
;
private
final
AuthenticationOrchestrationListener
authenticationListenerManager
;
private
final
ConfigMapOrchestrationListener
configMapListenerManager
;
private
final
InstanceStateOrchestrationListener
instanceStateListenerManager
;
private
final
DataSourceStateOrchestrationListener
dataSourceStateListenerManager
;
private
final
StateOrchestrationListenerManager
stateOrchestrationListenerManager
;
public
OrchestrationListenerManager
(
final
String
name
,
final
RegistryCenter
regCenter
,
final
Collection
<
String
>
shardingSchemaNames
)
{
for
(
String
each
:
shardingSchemaNames
)
{
dataSourceListenerManagers
.
add
(
new
DataSourceOrchestrationListener
(
name
,
regCenter
,
each
));
ruleListenerManagers
.
add
(
new
RuleOrchestrationListener
(
name
,
regCenter
,
each
));
}
propertiesListenerManager
=
new
PropertiesOrchestrationListener
(
name
,
regCenter
);
authenticationListenerManager
=
new
AuthenticationOrchestrationListener
(
name
,
regCenter
);
instanceStateListenerManager
=
new
InstanceStateOrchestrationListener
(
name
,
regCenter
);
configMapListenerManager
=
new
ConfigMapOrchestrationListener
(
name
,
regCenter
);
dataSourceStateListenerManager
=
new
DataSourceStateOrchestrationListener
(
name
,
regCenter
);
configOrchestrationListenerManager
=
new
ConfigurationOrchestrationListenerManager
(
name
,
regCenter
,
shardingSchemaNames
);
stateOrchestrationListenerManager
=
new
StateOrchestrationListenerManager
(
name
,
regCenter
);
}
/**
* Initialize listeners.
*
* Initialize all orchestration listeners.
*/
public
void
initListeners
()
{
initRuleListenerManagers
();
initDataSourceListenerManagers
();
propertiesListenerManager
.
watch
();
authenticationListenerManager
.
watch
();
instanceStateListenerManager
.
watch
();
dataSourceStateListenerManager
.
watch
();
configMapListenerManager
.
watch
();
}
private
void
initDataSourceListenerManagers
()
{
for
(
DataSourceOrchestrationListener
each
:
dataSourceListenerManagers
)
{
each
.
watch
();
}
}
private
void
initRuleListenerManagers
()
{
for
(
RuleOrchestrationListener
each
:
ruleListenerManagers
)
{
each
.
watch
();
}
configOrchestrationListenerManager
.
initListeners
();
stateOrchestrationListenerManager
.
initListeners
();
}
}
sharding-orchestration/sharding-orchestration-core/src/
test/java/io/shardingsphere/orchestration/internal/config/listener/AllListenerTests
.java
→
sharding-orchestration/sharding-orchestration-core/src/
main/java/io/shardingsphere/orchestration/internal/state/listener/StateOrchestrationListenerManager
.java
浏览文件 @
864b095d
...
...
@@ -15,19 +15,31 @@
* </p>
*/
package
io.shardingsphere.orchestration.internal.
config
.listener
;
package
io.shardingsphere.orchestration.internal.
state
.listener
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AuthenticationOrchestrationListenerTest
.
class
,
ConfigMapOrchestrationListenerTest
.
class
,
DataSourceOrchestrationListenerTest
.
class
,
PropertiesOrchestrationListenerTest
.
class
,
RuleOrchestrationListenerTest
.
class
})
public
final
class
AllListenerTests
{
/**
* State orchestration listener manager.
*
* @author zhangliang
*/
public
final
class
StateOrchestrationListenerManager
{
private
final
InstanceStateOrchestrationListener
instanceStateListenerManager
;
private
final
DataSourceStateOrchestrationListener
dataSourceStateListenerManager
;
public
StateOrchestrationListenerManager
(
final
String
name
,
final
RegistryCenter
regCenter
)
{
instanceStateListenerManager
=
new
InstanceStateOrchestrationListener
(
name
,
regCenter
);
dataSourceStateListenerManager
=
new
DataSourceStateOrchestrationListener
(
name
,
regCenter
);
}
/**
* Initialize all state orchestration listeners.
*/
public
void
initListeners
()
{
instanceStateListenerManager
.
watch
();
dataSourceStateListenerManager
.
watch
();
}
}
sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/yaml/YamlOrchestrationConfiguration.java
浏览文件 @
864b095d
...
...
@@ -45,7 +45,7 @@ public class YamlOrchestrationConfiguration {
* @return orchestration configuration from yaml
*/
public
OrchestrationConfiguration
getOrchestrationConfiguration
()
{
Preconditions
.
checkNotNull
(
registry
,
"Registry center must be required
!
"
);
Preconditions
.
checkNotNull
(
registry
,
"Registry center must be required
.
"
);
return
new
OrchestrationConfiguration
(
name
,
registry
,
overwrite
);
}
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/AllInternalTests.java
浏览文件 @
864b095d
...
...
@@ -18,6 +18,7 @@
package
io.shardingsphere.orchestration.internal
;
import
io.shardingsphere.orchestration.internal.config.AllConfigTests
;
import
io.shardingsphere.orchestration.internal.listener.AllListenerTests
;
import
io.shardingsphere.orchestration.internal.rule.AllRuleTests
;
import
io.shardingsphere.orchestration.internal.state.AllStateTests
;
import
io.shardingsphere.orchestration.internal.yaml.AllYamlTests
;
...
...
@@ -28,9 +29,10 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AllYamlTests
.
class
,
AllRuleTests
.
class
,
AllConfigTests
.
class
,
AllStateTests
.
class
,
All
Rule
Tests
.
class
All
Listener
Tests
.
class
})
public
final
class
AllInternalTests
{
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/OrchestrationFacadeTest.java
浏览文件 @
864b095d
...
...
@@ -29,9 +29,9 @@ import io.shardingsphere.core.config.DataSourceConfiguration;
import
io.shardingsphere.core.constant.properties.ShardingPropertiesConstant
;
import
io.shardingsphere.core.rule.Authentication
;
import
io.shardingsphere.orchestration.config.OrchestrationConfiguration
;
import
io.shardingsphere.orchestration.internal.config.listener.DataSourceOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.RuleOrchestrationListener
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigurationOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.internal.listener.OrchestrationListenerManager
;
import
io.shardingsphere.orchestration.internal.state.listener.StateOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration
;
import
io.shardingsphere.orchestration.reg.listener.EventListener
;
...
...
@@ -84,33 +84,11 @@ public final class OrchestrationFacadeTest {
Field
file
=
orchestrationFacade
.
getClass
().
getDeclaredField
(
"listenerManager"
);
file
.
setAccessible
(
true
);
OrchestrationListenerManager
listenerManager
=
(
OrchestrationListenerManager
)
file
.
get
(
orchestrationFacade
);
setRegistry
(
listenerManager
.
getClass
().
getDeclaredField
(
"propertiesListenerManager"
),
listenerManager
);
setRegistry
(
listenerManager
.
getClass
().
getDeclaredField
(
"authenticationListenerManager"
),
listenerManager
);
setRegistry
(
listenerManager
.
getClass
().
getDeclaredField
(
"configMapListenerManager"
),
listenerManager
);
setRegistry
(
listenerManager
.
getClass
().
getDeclaredField
(
"instanceStateListenerManager"
),
listenerManager
);
setRegistry
(
listenerManager
.
getClass
().
getDeclaredField
(
"dataSourceStateListenerManager"
),
listenerManager
);
setRegistryForDataSourceListenerManagers
(
listenerManager
);
setRegistryForRuleListenerManagers
(
listenerManager
);
}
@SuppressWarnings
(
"unchecked"
)
private
void
setRegistryForDataSourceListenerManagers
(
final
OrchestrationListenerManager
listenerManager
)
throws
ReflectiveOperationException
{
Field
childField
=
listenerManager
.
getClass
().
getDeclaredField
(
"dataSourceListenerManagers"
);
childField
.
setAccessible
(
true
);
Collection
<
DataSourceOrchestrationListener
>
dataSourceListenerManagers
=
(
Collection
<
DataSourceOrchestrationListener
>)
childField
.
get
(
listenerManager
);
for
(
DataSourceOrchestrationListener
each
:
dataSourceListenerManagers
)
{
setRegistry
(
each
);
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
setRegistryForRuleListenerManagers
(
final
OrchestrationListenerManager
listenerManager
)
throws
ReflectiveOperationException
{
Field
childField
=
listenerManager
.
getClass
().
getDeclaredField
(
"ruleListenerManagers"
);
childField
.
setAccessible
(
true
);
Collection
<
RuleOrchestrationListener
>
ruleListenerManagers
=
(
Collection
<
RuleOrchestrationListener
>)
childField
.
get
(
listenerManager
);
for
(
RuleOrchestrationListener
each
:
ruleListenerManagers
)
{
setRegistry
(
each
);
}
ConfigurationOrchestrationListenerManager
configOrchestrationListenerManager
=
new
ConfigurationOrchestrationListenerManager
(
"test"
,
regCenter
,
Arrays
.
asList
(
"sharding_db"
,
"masterslave_db"
));
StateOrchestrationListenerManager
stateOrchestrationListenerManager
=
new
StateOrchestrationListenerManager
(
"test"
,
regCenter
);
setField
(
listenerManager
,
"configOrchestrationListenerManager"
,
configOrchestrationListenerManager
);
setField
(
listenerManager
,
"stateOrchestrationListenerManager"
,
stateOrchestrationListenerManager
);
}
private
void
setRegistry
(
final
Field
field
,
final
Object
target
)
throws
ReflectiveOperationException
{
...
...
@@ -124,6 +102,12 @@ public final class OrchestrationFacadeTest {
field
.
set
(
target
,
regCenter
);
}
private
void
setField
(
final
Object
target
,
final
String
fieldName
,
final
Object
fieldValue
)
throws
ReflectiveOperationException
{
Field
field
=
target
.
getClass
().
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
field
.
set
(
target
,
fieldValue
);
}
@Test
public
void
assertInitWithParameters
()
{
orchestrationFacade
.
init
(
Collections
.
singletonMap
(
"sharding_db"
,
...
...
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/config/AllConfigTests.java
浏览文件 @
864b095d
...
...
@@ -17,7 +17,12 @@
package
io.shardingsphere.orchestration.internal.config
;
import
io.shardingsphere.orchestration.internal.config.listener.AllListenerTests
;
import
io.shardingsphere.orchestration.internal.config.listener.AuthenticationOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigMapOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigurationOrchestrationListenerManagerTest
;
import
io.shardingsphere.orchestration.internal.config.listener.DataSourceOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.config.listener.PropertiesOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.config.listener.RuleOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.config.node.ConfigurationNodeTest
;
import
io.shardingsphere.orchestration.internal.config.service.ConfigurationServiceTest
;
import
org.junit.runner.RunWith
;
...
...
@@ -26,9 +31,14 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigurationNodeTest
.
class
,
ConfigurationNodeTest
.
class
,
ConfigurationServiceTest
.
class
,
AllListenerTests
.
class
ConfigurationOrchestrationListenerManagerTest
.
class
,
RuleOrchestrationListenerTest
.
class
,
DataSourceOrchestrationListenerTest
.
class
,
PropertiesOrchestrationListenerTest
.
class
,
AuthenticationOrchestrationListenerTest
.
class
,
ConfigMapOrchestrationListenerTest
.
class
})
public
final
class
AllConfigTests
{
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/config/listener/ConfigurationOrchestrationListenerManagerTest.java
0 → 100644
浏览文件 @
864b095d
/*
* 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.orchestration.internal.config.listener
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.lang.reflect.Field
;
import
java.util.Arrays
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
ConfigurationOrchestrationListenerManagerTest
{
@Mock
private
RegistryCenter
regCenter
;
@Mock
private
RuleOrchestrationListener
ruleOrchestrationListener0
;
@Mock
private
RuleOrchestrationListener
ruleOrchestrationListener1
;
@Mock
private
DataSourceOrchestrationListener
dataSourceOrchestrationListener0
;
@Mock
private
DataSourceOrchestrationListener
dataSourceOrchestrationListener1
;
@Mock
private
PropertiesOrchestrationListener
propertiesListenerManager
;
@Mock
private
AuthenticationOrchestrationListener
authenticationListenerManager
;
@Mock
private
ConfigMapOrchestrationListener
configMapListenerManager
;
@Test
public
void
assertInitListeners
()
throws
ReflectiveOperationException
{
ConfigurationOrchestrationListenerManager
actual
=
new
ConfigurationOrchestrationListenerManager
(
"test"
,
regCenter
,
Arrays
.
asList
(
"sharding_db"
,
"masterslave_db"
));
setField
(
actual
,
"ruleListenerManagers"
,
Arrays
.
asList
(
ruleOrchestrationListener0
,
ruleOrchestrationListener1
));
setField
(
actual
,
"dataSourceListenerManagers"
,
Arrays
.
asList
(
dataSourceOrchestrationListener0
,
dataSourceOrchestrationListener1
));
setField
(
actual
,
"propertiesListenerManager"
,
propertiesListenerManager
);
setField
(
actual
,
"authenticationListenerManager"
,
authenticationListenerManager
);
setField
(
actual
,
"configMapListenerManager"
,
configMapListenerManager
);
actual
.
initListeners
();
verify
(
ruleOrchestrationListener0
).
watch
();
verify
(
ruleOrchestrationListener1
).
watch
();
verify
(
dataSourceOrchestrationListener0
).
watch
();
verify
(
dataSourceOrchestrationListener1
).
watch
();
verify
(
propertiesListenerManager
).
watch
();
verify
(
authenticationListenerManager
).
watch
();
verify
(
configMapListenerManager
).
watch
();
}
private
void
setField
(
final
Object
target
,
final
String
fieldName
,
final
Object
fieldValue
)
throws
ReflectiveOperationException
{
Field
field
=
ConfigurationOrchestrationListenerManager
.
class
.
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
field
.
set
(
target
,
fieldValue
);
}
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/
state/
listener/AllListenerTests.java
→
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/listener/AllListenerTests.java
浏览文件 @
864b095d
...
...
@@ -15,16 +15,13 @@
* </p>
*/
package
io.shardingsphere.orchestration.internal.
state.
listener
;
package
io.shardingsphere.orchestration.internal.listener
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
DataSourceStateOrchestrationListenerTest
.
class
,
InstanceStateOrchestrationListenerTest
.
class
})
@SuiteClasses
(
OrchestrationListenerManagerTest
.
class
)
public
final
class
AllListenerTests
{
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/listener/OrchestrationListenerManagerTest.java
0 → 100644
浏览文件 @
864b095d
/*
* 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.orchestration.internal.listener
;
import
io.shardingsphere.orchestration.internal.config.listener.ConfigurationOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.internal.state.listener.StateOrchestrationListenerManager
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.lang.reflect.Field
;
import
java.util.Collections
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
OrchestrationListenerManagerTest
{
@Mock
private
RegistryCenter
regCenter
;
@Mock
private
ConfigurationOrchestrationListenerManager
configOrchestrationListenerManager
;
@Mock
private
StateOrchestrationListenerManager
stateOrchestrationListenerManager
;
@Test
public
void
assertInitListeners
()
throws
ReflectiveOperationException
{
OrchestrationListenerManager
actual
=
new
OrchestrationListenerManager
(
"test"
,
regCenter
,
Collections
.<
String
>
emptyList
());
setField
(
actual
,
"configOrchestrationListenerManager"
,
configOrchestrationListenerManager
);
setField
(
actual
,
"stateOrchestrationListenerManager"
,
stateOrchestrationListenerManager
);
actual
.
initListeners
();
verify
(
configOrchestrationListenerManager
).
initListeners
();
verify
(
stateOrchestrationListenerManager
).
initListeners
();
}
private
void
setField
(
final
Object
target
,
final
String
fieldName
,
final
Object
fieldValue
)
throws
ReflectiveOperationException
{
Field
field
=
OrchestrationListenerManager
.
class
.
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
field
.
set
(
target
,
fieldValue
);
}
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/state/AllStateTests.java
浏览文件 @
864b095d
...
...
@@ -17,7 +17,9 @@
package
io.shardingsphere.orchestration.internal.state
;
import
io.shardingsphere.orchestration.internal.state.listener.AllListenerTests
;
import
io.shardingsphere.orchestration.internal.state.listener.DataSourceStateOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.state.listener.InstanceStateOrchestrationListenerTest
;
import
io.shardingsphere.orchestration.internal.state.listener.StateOrchestrationListenerManagerTest
;
import
io.shardingsphere.orchestration.internal.state.node.StateNodeTest
;
import
io.shardingsphere.orchestration.internal.state.service.DataSourceServiceTest
;
import
io.shardingsphere.orchestration.internal.state.service.InstanceStateServiceTest
;
...
...
@@ -30,7 +32,9 @@ import org.junit.runners.Suite.SuiteClasses;
StateNodeTest
.
class
,
InstanceStateServiceTest
.
class
,
DataSourceServiceTest
.
class
,
AllListenerTests
.
class
StateOrchestrationListenerManagerTest
.
class
,
DataSourceStateOrchestrationListenerTest
.
class
,
InstanceStateOrchestrationListenerTest
.
class
})
public
final
class
AllStateTests
{
}
sharding-orchestration/sharding-orchestration-core/src/test/java/io/shardingsphere/orchestration/internal/state/listener/StateOrchestrationListenerManagerTest.java
0 → 100644
浏览文件 @
864b095d
/*
* 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.orchestration.internal.state.listener
;
import
io.shardingsphere.orchestration.reg.api.RegistryCenter
;
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
StateOrchestrationListenerManagerTest
{
@Mock
private
RegistryCenter
regCenter
;
@Mock
private
InstanceStateOrchestrationListener
instanceStateListenerManager
;
@Mock
private
DataSourceStateOrchestrationListener
dataSourceStateListenerManager
;
@Test
public
void
assertInitListeners
()
throws
ReflectiveOperationException
{
StateOrchestrationListenerManager
actual
=
new
StateOrchestrationListenerManager
(
"test"
,
regCenter
);
setField
(
actual
,
"instanceStateListenerManager"
,
instanceStateListenerManager
);
setField
(
actual
,
"dataSourceStateListenerManager"
,
dataSourceStateListenerManager
);
actual
.
initListeners
();
verify
(
instanceStateListenerManager
).
watch
();
verify
(
dataSourceStateListenerManager
).
watch
();
}
private
void
setField
(
final
Object
target
,
final
String
fieldName
,
final
Object
fieldValue
)
throws
ReflectiveOperationException
{
Field
field
=
StateOrchestrationListenerManager
.
class
.
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
field
.
set
(
target
,
fieldValue
);
}
}
sharding-orchestration/sharding-orchestration-core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
0 → 100644
浏览文件 @
864b095d
mock-maker-inline
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录