Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
04781220
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
04781220
编写于
5月 16, 2020
作者:
F
figroc
提交者:
GitHub
5月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow repeatable deletions and enhance thread safety (#3069)
上级
4d56835c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
88 addition
and
7 deletion
+88
-7
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
...com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
+7
-6
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/ApolloMockServerApiTest.java
.../framework/apollo/mockserver/ApolloMockServerApiTest.java
+77
-1
apollo-mockserver/src/test/resources/mockdata-anotherNamespace.properties
...r/src/test/resources/mockdata-anotherNamespace.properties
+4
-0
未找到文件。
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
浏览文件 @
04781220
...
...
@@ -5,14 +5,13 @@ import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import
com.ctrip.framework.apollo.core.dto.ApolloConfigNotification
;
import
com.ctrip.framework.apollo.core.utils.ResourceUtils
;
import
com.ctrip.framework.apollo.internals.ConfigServiceLocator
;
import
com.google.common.collect.ImmutableSet
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -38,8 +37,8 @@ public class EmbeddedApollo extends ExternalResource {
private
static
ConfigServiceLocator
CONFIG_SERVICE_LOCATOR
;
private
final
Gson
gson
=
new
Gson
();
private
final
Map
<
String
,
Map
<
String
,
String
>>
addedOrModifiedPropertiesOfNamespace
=
new
HashMap
<>
();
private
final
Map
<
String
,
Set
<
String
>>
deletedKeysOfNamespace
=
new
HashMap
<>
();
private
final
Map
<
String
,
Map
<
String
,
String
>>
addedOrModifiedPropertiesOfNamespace
=
Maps
.
newConcurrentMap
();
private
final
Map
<
String
,
Set
<
String
>>
deletedKeysOfNamespace
=
Maps
.
newConcurrentMap
();
private
MockWebServer
server
;
...
...
@@ -151,7 +150,7 @@ public class EmbeddedApollo extends ExternalResource {
if
(
addedOrModifiedPropertiesOfNamespace
.
containsKey
(
namespace
))
{
addedOrModifiedPropertiesOfNamespace
.
get
(
namespace
).
put
(
someKey
,
someValue
);
}
else
{
Map
<
String
,
String
>
m
=
new
HashMap
<>
();
Map
<
String
,
String
>
m
=
Maps
.
newConcurrentMap
();
m
.
put
(
someKey
,
someValue
);
addedOrModifiedPropertiesOfNamespace
.
put
(
namespace
,
m
);
}
...
...
@@ -164,7 +163,9 @@ public class EmbeddedApollo extends ExternalResource {
if
(
deletedKeysOfNamespace
.
containsKey
(
namespace
))
{
deletedKeysOfNamespace
.
get
(
namespace
).
add
(
someKey
);
}
else
{
deletedKeysOfNamespace
.
put
(
namespace
,
ImmutableSet
.
of
(
someKey
));
Set
<
String
>
m
=
Sets
.
newConcurrentHashSet
();
m
.
add
(
someKey
);
deletedKeysOfNamespace
.
put
(
namespace
,
m
);
}
}
...
...
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/ApolloMockServerApiTest.java
浏览文件 @
04781220
package
com.ctrip.framework.apollo.mockserver
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
com.ctrip.framework.apollo.Config
;
...
...
@@ -8,7 +9,10 @@ import com.ctrip.framework.apollo.ConfigChangeListener;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.google.common.util.concurrent.SettableFuture
;
import
java.util.concurrent.Semaphore
;
import
java.util.concurrent.TimeUnit
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
...
...
@@ -51,7 +55,79 @@ public class ApolloMockServerApiTest {
assertEquals
(
someNewValue
,
otherConfig
.
getProperty
(
"key1"
,
null
));
assertEquals
(
"otherValue2"
,
otherConfig
.
getProperty
(
"key2"
,
null
));
assertTrue
(
changeEvent
.
isChanged
(
"key1"
));
}
@Test
public
void
testUpdateSamePropertyTwice
()
throws
Exception
{
String
someNewValue
=
"someNewValue"
;
Config
otherConfig
=
ConfigService
.
getConfig
(
anotherNamespace
);
final
Semaphore
changes
=
new
Semaphore
(
0
);
otherConfig
.
addChangeListener
(
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
changes
.
release
();
}
});
assertEquals
(
"otherValue3"
,
otherConfig
.
getProperty
(
"key3"
,
null
));
embeddedApollo
.
addOrModifyProperty
(
anotherNamespace
,
"key3"
,
someNewValue
);
embeddedApollo
.
addOrModifyProperty
(
anotherNamespace
,
"key3"
,
someNewValue
);
assertTrue
(
changes
.
tryAcquire
(
5
,
TimeUnit
.
SECONDS
));
assertEquals
(
someNewValue
,
otherConfig
.
getProperty
(
"key3"
,
null
));
assertEquals
(
0
,
changes
.
availablePermits
());
}
@Test
public
void
testDeleteProperties
()
throws
Exception
{
Config
otherConfig
=
ConfigService
.
getConfig
(
anotherNamespace
);
final
SettableFuture
<
ConfigChangeEvent
>
future
=
SettableFuture
.
create
();
otherConfig
.
addChangeListener
(
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
future
.
set
(
changeEvent
);
}
});
assertEquals
(
"otherValue4"
,
otherConfig
.
getProperty
(
"key4"
,
null
));
assertEquals
(
"otherValue5"
,
otherConfig
.
getProperty
(
"key5"
,
null
));
embeddedApollo
.
deleteProperty
(
anotherNamespace
,
"key4"
);
ConfigChangeEvent
changeEvent
=
future
.
get
(
5
,
TimeUnit
.
SECONDS
);
assertNull
(
otherConfig
.
getProperty
(
"key4"
,
null
));
assertEquals
(
"otherValue5"
,
otherConfig
.
getProperty
(
"key5"
,
null
));
assertTrue
(
changeEvent
.
isChanged
(
"key4"
));
}
@Test
public
void
testDeleteSamePropertyTwice
()
throws
Exception
{
Config
otherConfig
=
ConfigService
.
getConfig
(
anotherNamespace
);
final
Semaphore
changes
=
new
Semaphore
(
0
);
otherConfig
.
addChangeListener
(
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
changes
.
release
();
}
});
assertEquals
(
"otherValue6"
,
otherConfig
.
getProperty
(
"key6"
,
null
));
embeddedApollo
.
deleteProperty
(
anotherNamespace
,
"key6"
);
embeddedApollo
.
deleteProperty
(
anotherNamespace
,
"key6"
);
assertTrue
(
changes
.
tryAcquire
(
5
,
TimeUnit
.
SECONDS
));
assertNull
(
otherConfig
.
getProperty
(
"key6"
,
null
));
assertEquals
(
0
,
changes
.
availablePermits
());
}
}
apollo-mockserver/src/test/resources/mockdata-anotherNamespace.properties
浏览文件 @
04781220
key1
=
otherValue1
key2
=
otherValue2
key3
=
otherValue3
key4
=
otherValue4
key5
=
otherValue5
key6
=
otherValue6
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录