Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
bf52eeca
Commit
bf52eeca
authored
Aug 23, 2018
by
zhangzheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
2c4800f4
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
97 deletions
+54
-97
apollo-mockserver/pom.xml
apollo-mockserver/pom.xml
+1
-1
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
...com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
+4
-2
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/MockedMetaServerProvider.java
...framework/apollo/mockserver/MockedMetaServerProvider.java
+27
-0
apollo-mockserver/src/main/resources/META-INF/services/com.ctrip.framework.apollo.core.spi.MetaServerProvider
...es/com.ctrip.framework.apollo.core.spi.MetaServerProvider
+1
-0
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/ApolloMockServerTest.java
...rip/framework/apollo/mockserver/ApolloMockServerTest.java
+0
-91
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/SpringIntegrationTest.java
...ip/framework/apollo/mockserver/SpringIntegrationTest.java
+20
-3
pom.xml
pom.xml
+1
-0
No files found.
apollo-mockserver/pom.xml
View file @
bf52eeca
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<version>
1.1.
5
-SNAPSHOT
</version>
<version>
1.1.
0
-SNAPSHOT
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/EmbeddedApollo.java
View file @
bf52eeca
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
import
com.ctrip.framework.apollo.core.MetaDomainConsts
;
import
com.ctrip.framework.apollo.core.dto.ApolloConfig
;
import
com.ctrip.framework.apollo.core.dto.ApolloConfig
;
import
com.ctrip.framework.apollo.core.dto.ApolloConfigNotification
;
import
com.ctrip.framework.apollo.core.dto.ApolloConfigNotification
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
com.ctrip.framework.apollo.core.spi.MetaServerProvider
;
import
com.ctrip.framework.apollo.core.utils.ResourceUtils
;
import
com.ctrip.framework.apollo.core.utils.ResourceUtils
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableSet
;
import
com.google.common.collect.ImmutableSet
;
...
@@ -71,8 +73,8 @@ public class EmbeddedApollo extends ExternalResource {
...
@@ -71,8 +73,8 @@ public class EmbeddedApollo extends ExternalResource {
//指定apollo的metaserver地址为localhost
//指定apollo的metaserver地址为localhost
int
port
=
server
.
getPort
();
int
port
=
server
.
getPort
();
this
.
listenningUrl
=
"http://localhost:"
+
port
;
this
.
listenningUrl
=
"http://localhost:"
+
port
;
System
.
setProperty
(
"apollo.env"
,
"mock"
);
System
.
setProperty
(
"mock_meta"
,
listenningUrl
);
MockedMetaServerProvider
.
setAddress
(
listenningUrl
);
System
.
setProperty
(
"apollo.longPollingInitialDelayInMills"
,
"1"
);
System
.
setProperty
(
"apollo.longPollingInitialDelayInMills"
,
"1"
);
...
...
apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/MockedMetaServerProvider.java
0 → 100644
View file @
bf52eeca
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.spi.MetaServerProvider
;
/**
* Create by zhangzheng on 8/23/18
* Email:zhangzheng@youzan.com
*/
public
class
MockedMetaServerProvider
implements
MetaServerProvider
{
private
static
String
address
;
public
static
void
setAddress
(
String
addr
){
address
=
addr
;
}
@Override
public
String
getMetaServerAddress
(
Env
targetEnv
)
{
return
address
;
}
@Override
public
int
getOrder
()
{
return
HIGHEST_PRECEDENCE
;
}
}
apollo-mockserver/src/main/resources/META-INF/services/com.ctrip.framework.apollo.core.spi.MetaServerProvider
0 → 100644
View file @
bf52eeca
com.ctrip.framework.apollo.mockserver.MockedMetaServerProvider
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/ApolloMockServerTest.java
deleted
100644 → 0
View file @
2c4800f4
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.enums.PropertyChangeType
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.google.common.util.concurrent.SettableFuture
;
import
java.io.IOException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.springframework.boot.test.WebIntegrationTest
;
/**
* Create by zhangzheng on 8/10/18
* Email:zhangzheng@youzan.com
*/
public
class
ApolloMockServerTest
{
@ClassRule
public
static
EmbeddedApollo
embeddedApollo
=
new
EmbeddedApollo
();
@Test
public
void
testPropertyInject
()
{
String
namespace
=
"application"
;
Config
config
=
ConfigService
.
getConfig
(
namespace
);
assertEquals
(
"value1"
,
config
.
getProperty
(
"key1"
,
""
));
assertEquals
(
"value2"
,
config
.
getProperty
(
"key2"
,
""
));
String
otherNamespace
=
"othernamespace"
;
config
=
ConfigService
.
getConfig
(
otherNamespace
);
assertEquals
(
"othervalue1"
,
config
.
getProperty
(
"key1"
,
""
));
assertEquals
(
"othervalue2"
,
config
.
getProperty
(
"key2"
,
""
));
}
@Test
public
void
testListennerTriggeredByAdd
()
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
System
.
setProperty
(
"apollo.longPollingInitialDelayInMills"
,
"1"
);
String
someNamespace
=
"application"
;
Config
config
=
ConfigService
.
getConfig
(
someNamespace
);
SettableFuture
<
Boolean
>
changed
=
SettableFuture
.
create
();
String
someKey
=
"someKey"
;
String
someValue
=
"someValue"
;
config
.
addChangeListener
(
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
assertEquals
(
true
,
changeEvent
.
isChanged
(
someKey
));
assertEquals
(
someValue
,
changeEvent
.
getChange
(
someKey
).
getNewValue
());
changed
.
set
(
true
);
}
});
embeddedApollo
.
addOrModifyPropery
(
someNamespace
,
someKey
,
someValue
);
assertEquals
(
true
,
changed
.
get
(
1000
,
TimeUnit
.
MILLISECONDS
));
}
@Test
public
void
testListennerTriggeredByDel
()
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
String
someNamespace
=
"application"
;
Config
config
=
ConfigService
.
getConfig
(
someNamespace
);
SettableFuture
<
Boolean
>
changed
=
SettableFuture
.
create
();
String
someKey
=
"key1"
;
config
.
addChangeListener
(
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
assertEquals
(
true
,
changeEvent
.
isChanged
(
someKey
));
assertEquals
(
PropertyChangeType
.
DELETED
,
changeEvent
.
getChange
(
someKey
).
getChangeType
());
changed
.
set
(
true
);
}
});
embeddedApollo
.
delete
(
someNamespace
,
someKey
);
assertEquals
(
true
,
changed
.
get
(
1000
,
TimeUnit
.
MILLISECONDS
));
}
}
apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/SpringIntegrationTest.java
View file @
bf52eeca
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
package
com
.
ctrip
.
framework
.
apollo
.
mockserver
;
import
com.ctrip.framework.apollo.enums.PropertyChangeType
;
import
com.ctrip.framework.apollo.mockserver.SpringIntegrationTest.TestConfiguration
;
import
com.ctrip.framework.apollo.mockserver.SpringIntegrationTest.TestConfiguration
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener
;
...
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
/**
...
@@ -33,12 +35,16 @@ public class SpringIntegrationTest {
...
@@ -33,12 +35,16 @@ public class SpringIntegrationTest {
@ClassRule
@ClassRule
public
static
EmbeddedApollo
embeddedApollo
=
new
EmbeddedApollo
();
public
static
EmbeddedApollo
embeddedApollo
=
new
EmbeddedApollo
();
@Test
@Test
public
void
testPropertyInjectAndListener
()
@DirtiesContext
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
public
void
testPropertyInject
()
{
assertEquals
(
"value1"
,
testBean
.
key1
);
assertEquals
(
"value1"
,
testBean
.
key1
);
assertEquals
(
"value2"
,
testBean
.
key2
);
assertEquals
(
"value2"
,
testBean
.
key2
);
}
@Test
@DirtiesContext
public
void
testListenerTriggeredByAdd
()
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
String
otherNamespace
=
"othernamespace"
;
String
otherNamespace
=
"othernamespace"
;
embeddedApollo
.
addOrModifyPropery
(
otherNamespace
,
"someKey"
,
"someValue"
);
embeddedApollo
.
addOrModifyPropery
(
otherNamespace
,
"someKey"
,
"someValue"
);
ConfigChangeEvent
changeEvent
=
testBean
.
futureData
.
get
(
5000
,
TimeUnit
.
MILLISECONDS
);
ConfigChangeEvent
changeEvent
=
testBean
.
futureData
.
get
(
5000
,
TimeUnit
.
MILLISECONDS
);
...
@@ -46,6 +52,17 @@ public class SpringIntegrationTest {
...
@@ -46,6 +52,17 @@ public class SpringIntegrationTest {
assertEquals
(
"someValue"
,
changeEvent
.
getChange
(
"someKey"
).
getNewValue
());
assertEquals
(
"someValue"
,
changeEvent
.
getChange
(
"someKey"
).
getNewValue
());
}
}
@Test
@DirtiesContext
public
void
testListenerTriggeredByDel
()
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
String
otherNamespace
=
"othernamespace"
;
embeddedApollo
.
delete
(
otherNamespace
,
"key1"
);
ConfigChangeEvent
changeEvent
=
testBean
.
futureData
.
get
(
5000
,
TimeUnit
.
MILLISECONDS
);
assertEquals
(
otherNamespace
,
changeEvent
.
getNamespace
());
assertEquals
(
PropertyChangeType
.
DELETED
,
changeEvent
.
getChange
(
"key1"
).
getChangeType
());
}
...
...
pom.xml
View file @
bf52eeca
...
@@ -103,6 +103,7 @@
...
@@ -103,6 +103,7 @@
<module>
apollo-portal
</module>
<module>
apollo-portal
</module>
<module>
apollo-assembly
</module>
<module>
apollo-assembly
</module>
<module>
apollo-demo
</module>
<module>
apollo-demo
</module>
<module>
apollo-mockserver
</module>
</modules>
</modules>
<dependencyManagement>
<dependencyManagement>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment