Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touzizhuo03
Dubbo
提交
c910f8b2
D
Dubbo
项目概览
touzizhuo03
/
Dubbo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dubbo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c910f8b2
编写于
7月 10, 2012
作者:
oldratlee
🔥
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加 UT DUBBO-475 ReferenceConfig支持按group+interface+version缓存
上级
3c5d9e33
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
222 addition
and
4 deletion
+222
-4
dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/utils/ReferenceConfigCache.java
.../com/alibaba/dubbo/config/utils/ReferenceConfigCache.java
+4
-4
dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/utils/MockReferenceConfig.java
...a/com/alibaba/dubbo/config/utils/MockReferenceConfig.java
+56
-0
dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/utils/ReferenceConfigCacheTest.java
.../alibaba/dubbo/config/utils/ReferenceConfigCacheTest.java
+162
-0
未找到文件。
dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/utils/ReferenceConfigCache.java
浏览文件 @
c910f8b2
...
...
@@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentMap;
public
class
ReferenceConfigCache
{
public
static
final
String
DEFAULT_NAME
=
"_DEFAULT_"
;
private
static
final
ConcurrentMap
<
String
,
ReferenceConfigCache
>
cacheHolder
=
new
ConcurrentHashMap
<
String
,
ReferenceConfigCache
>();
static
final
ConcurrentMap
<
String
,
ReferenceConfigCache
>
cacheHolder
=
new
ConcurrentHashMap
<
String
,
ReferenceConfigCache
>();
/**
* Get the cache use default name and {@link #DEFAULT_KEY_GENERATOR} to generate cache key.
...
...
@@ -74,7 +74,7 @@ public class ReferenceConfigCache {
/**
* Create the key with the <b>Group</b>, <b>Interface</b> and <b>version</b> attribute of {@link ReferenceConfig}.
* <p>
*
eg
: <code>group1/com.alibaba.foo.FooService:1.0.0</code>.
*
key example
: <code>group1/com.alibaba.foo.FooService:1.0.0</code>.
*/
public
static
final
KeyGenerator
DEFAULT_KEY_GENERATOR
=
new
KeyGenerator
()
{
public
String
generateKey
(
ReferenceConfig
<?>
referenceConfig
)
{
...
...
@@ -102,7 +102,7 @@ public class ReferenceConfigCache {
private
final
String
name
;
private
final
KeyGenerator
generator
;
private
ConcurrentMap
<
String
,
ReferenceConfig
<?>>
cache
=
new
ConcurrentHashMap
<
String
,
ReferenceConfig
<?>>();
ConcurrentMap
<
String
,
ReferenceConfig
<?>>
cache
=
new
ConcurrentHashMap
<
String
,
ReferenceConfig
<?>>();
private
ReferenceConfigCache
(
String
name
,
KeyGenerator
generator
)
{
this
.
name
=
name
;
...
...
@@ -114,7 +114,7 @@ public class ReferenceConfigCache {
ReferenceConfig
<?>
config
=
cache
.
get
(
key
);
if
(
config
!=
null
)
{
return
referenceC
onfig
.
get
();
return
(
T
)
c
onfig
.
get
();
}
cache
.
putIfAbsent
(
key
,
referenceConfig
);
...
...
dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/utils/MockReferenceConfig.java
0 → 100644
浏览文件 @
c910f8b2
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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.
*/
package
com.alibaba.dubbo.config.utils
;
import
com.alibaba.dubbo.config.ReferenceConfig
;
import
java.util.concurrent.atomic.AtomicLong
;
/**
* @author ding.lid
*/
public
class
MockReferenceConfig
extends
ReferenceConfig
<
String
>
{
static
AtomicLong
counter
=
new
AtomicLong
();
String
value
;
public
boolean
isGetMethodRun
()
{
return
value
!=
null
;
}
boolean
destroyMethodRun
=
false
;
public
boolean
isDestroyMethodRun
()
{
return
destroyMethodRun
;
}
public
static
void
setCounter
(
long
c
)
{
counter
.
set
(
c
);
}
@Override
public
synchronized
String
get
()
{
if
(
value
!=
null
)
return
value
;
value
=
""
+
counter
.
getAndIncrement
();
return
value
;
}
@Override
public
synchronized
void
destroy
()
{
destroyMethodRun
=
true
;
}
}
dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/utils/ReferenceConfigCacheTest.java
0 → 100644
浏览文件 @
c910f8b2
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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.
*/
package
com.alibaba.dubbo.config.utils
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author ding.lid
*/
public
class
ReferenceConfigCacheTest
{
@Before
public
void
setUp
()
throws
Exception
{
MockReferenceConfig
.
setCounter
(
0
);
ReferenceConfigCache
.
cacheHolder
.
clear
();
}
@Test
public
void
testGetCache_SameReference
()
throws
Exception
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
();
{
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
config
);
assertTrue
(
config
.
isGetMethodRun
());
assertEquals
(
"0"
,
value
);
}
{
MockReferenceConfig
configCopy
=
new
MockReferenceConfig
();
configCopy
.
setInterface
(
"FooService"
);
configCopy
.
setGroup
(
"group1"
);
configCopy
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
configCopy
);
assertFalse
(
configCopy
.
isGetMethodRun
());
assertEquals
(
"0"
,
value
);
}
}
@Test
public
void
testGetCache_DiffReference
()
throws
Exception
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
();
{
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
config
);
assertTrue
(
config
.
isGetMethodRun
());
assertEquals
(
"0"
,
value
);
}
{
MockReferenceConfig
configCopy
=
new
MockReferenceConfig
();
configCopy
.
setInterface
(
"XxxService"
);
configCopy
.
setGroup
(
"group1"
);
configCopy
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
configCopy
);
assertTrue
(
configCopy
.
isGetMethodRun
());
assertEquals
(
"1"
,
value
);
}
}
@Test
public
void
testGetCache_DiffName
()
throws
Exception
{
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
();
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
config
);
assertTrue
(
config
.
isGetMethodRun
());
assertEquals
(
"0"
,
value
);
}
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
(
"foo"
);
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
String
value
=
cache
.
get
(
config
);
assertTrue
(
config
.
isGetMethodRun
());
// ͬCacheͬReferenceConfigҲInit
assertEquals
(
"1"
,
value
);
}
}
@Test
public
void
testDestroy
()
throws
Exception
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
();
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
cache
.
get
(
config
);
MockReferenceConfig
configCopy
=
new
MockReferenceConfig
();
configCopy
.
setInterface
(
"XxxService"
);
configCopy
.
setGroup
(
"group1"
);
configCopy
.
setVersion
(
"1.0.0"
);
cache
.
get
(
configCopy
);
assertEquals
(
2
,
cache
.
cache
.
size
());
cache
.
destroy
(
config
);
assertTrue
(
config
.
isDestroyMethodRun
());
assertEquals
(
1
,
cache
.
cache
.
size
());
cache
.
destroy
(
configCopy
);
assertTrue
(
configCopy
.
isDestroyMethodRun
());
assertEquals
(
0
,
cache
.
cache
.
size
());
}
@Test
public
void
testDestroyAll
()
throws
Exception
{
ReferenceConfigCache
cache
=
ReferenceConfigCache
.
getCache
();
MockReferenceConfig
config
=
new
MockReferenceConfig
();
config
.
setInterface
(
"FooService"
);
config
.
setGroup
(
"group1"
);
config
.
setVersion
(
"1.0.0"
);
cache
.
get
(
config
);
MockReferenceConfig
configCopy
=
new
MockReferenceConfig
();
configCopy
.
setInterface
(
"XxxService"
);
configCopy
.
setGroup
(
"group1"
);
configCopy
.
setVersion
(
"1.0.0"
);
cache
.
get
(
configCopy
);
assertEquals
(
2
,
cache
.
cache
.
size
());
cache
.
destroyAll
();
assertTrue
(
config
.
isDestroyMethodRun
());
assertTrue
(
configCopy
.
isDestroyMethodRun
());
assertEquals
(
0
,
cache
.
cache
.
size
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录