Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
openSource
spring-cloud-netflix
Commits
98cd592f
Commit
98cd592f
authored
Jan 09, 2017
by
Biju Kunjummen
Committed by
Spencer Gibb
Jan 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix null instanceinfo on EurekaInstanceRenewedEvent (#1574)
Fixes gh-1546
parent
64b81ff5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
25 deletions
+35
-25
InstanceRegistry.java
...amework/cloud/netflix/eureka/server/InstanceRegistry.java
+1
-1
InstanceRegistryTest.java
...ork/cloud/netflix/eureka/server/InstanceRegistryTest.java
+34
-24
No files found.
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java
View file @
98cd592f
...
...
@@ -106,7 +106,7 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
if
(
input
.
getName
().
equals
(
appName
))
{
InstanceInfo
instance
=
null
;
for
(
InstanceInfo
info
:
input
.
getInstances
())
{
if
(
info
.
get
HostName
().
equals
(
serverId
))
{
if
(
info
.
get
Id
().
equals
(
serverId
))
{
instance
=
info
;
break
;
}
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistryTest.java
View file @
98cd592f
...
...
@@ -6,10 +6,10 @@ import static org.mockito.Mockito.doAnswer;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.List
;
import
com.netflix.discovery.shared.Application
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -31,6 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.appinfo.LeaseInfo
;
import
com.netflix.discovery.shared.Application
;
import
com.netflix.eureka.registry.PeerAwareInstanceRegistry
;
/**
...
...
@@ -38,14 +39,16 @@ import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
TestApplication
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=eureka"
,
"logging.level.org.springframework."
+
"cloud.netflix.eureka.server.InstanceRegistry=DEBUG"
})
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=eureka"
,
"logging.level.org.springframework."
+
"cloud.netflix.eureka.server.InstanceRegistry=DEBUG"
})
public
class
InstanceRegistryTest
{
private
final
List
<
ApplicationEvent
>
applicationEvents
=
new
LinkedList
<>();
private
static
final
String
APP_NAME
=
"MY-APP-NAME"
;
private
static
final
String
HOST_NAME
=
"my-host-name"
;
private
static
final
String
INSTANCE_ID
=
"my-host-name:8008"
;
private
static
final
int
PORT
=
8008
;
@SpyBean
(
PeerAwareInstanceRegistry
.
class
)
private
InstanceRegistry
instanceRegistry
;
...
...
@@ -78,7 +81,7 @@ public class InstanceRegistryTest {
public
void
testRegister
()
throws
Exception
{
// creating instance info
final
LeaseInfo
leaseInfo
=
getLeaseInfo
();
final
InstanceInfo
instanceInfo
=
getInstanceInfo
(
leaseInfo
);
final
InstanceInfo
instanceInfo
=
getInstanceInfo
(
APP_NAME
,
HOST_NAME
,
INSTANCE_ID
,
PORT
,
leaseInfo
);
// calling tested method
instanceRegistry
.
register
(
instanceInfo
,
false
);
// event of proper type is registered
...
...
@@ -96,7 +99,7 @@ public class InstanceRegistryTest {
@Test
public
void
testDefaultLeaseDurationRegisterEvent
()
throws
Exception
{
// creating instance info
final
InstanceInfo
instanceInfo
=
getInstanceInfo
(
null
);
final
InstanceInfo
instanceInfo
=
getInstanceInfo
(
APP_NAME
,
HOST_NAME
,
INSTANCE_ID
,
PORT
,
null
);
// calling tested method
instanceRegistry
.
register
(
instanceInfo
,
false
);
// instance info duration is set to default
...
...
@@ -124,29 +127,34 @@ public class InstanceRegistryTest {
@Test
public
void
testRenew
()
throws
Exception
{
// creating application list
final
LeaseInfo
leaseInfo
=
getLeaseInfo
();
final
InstanceInfo
instanceInfo
=
getInstanceInfo
(
leaseInfo
);
final
List
<
InstanceInfo
>
instances
=
new
ArrayList
<>();
instances
.
add
(
instanceInfo
);
final
Application
application
=
new
Application
(
APP_NAME
,
instances
);
//Creating two instances of the app
final
InstanceInfo
instanceInfo1
=
getInstanceInfo
(
APP_NAME
,
HOST_NAME
,
INSTANCE_ID
,
PORT
,
null
);
final
InstanceInfo
instanceInfo2
=
getInstanceInfo
(
APP_NAME
,
HOST_NAME
,
"my-host-name:8009"
,
8009
,
null
);
// creating application list with an app having two instances
final
Application
application
=
new
Application
(
APP_NAME
,
Arrays
.
asList
(
instanceInfo1
,
instanceInfo2
));
final
List
<
Application
>
applications
=
new
ArrayList
<>();
applications
.
add
(
application
);
// stubbing applications list
doReturn
(
applications
).
when
(
instanceRegistry
).
getSortedApplications
();
// calling tested method
instanceRegistry
.
renew
(
APP_NAME
,
HOST_NAME
,
false
);
instanceRegistry
.
renew
(
APP_NAME
,
INSTANCE_ID
,
false
);
instanceRegistry
.
renew
(
APP_NAME
,
"my-host-name:8009"
,
false
);
// event of proper type is registered
assertEquals
(
1
,
applicationEvents
.
size
());
assertEquals
(
2
,
applicationEvents
.
size
());
assertTrue
(
applicationEvents
.
get
(
0
)
instanceof
EurekaInstanceRenewedEvent
);
assertTrue
(
applicationEvents
.
get
(
1
)
instanceof
EurekaInstanceRenewedEvent
);
// event details are correct
final
EurekaInstanceRenewedEvent
registeredEvent
=
(
EurekaInstanceRenewedEvent
)
final
EurekaInstanceRenewedEvent
event1
=
(
EurekaInstanceRenewedEvent
)
(
applicationEvents
.
get
(
0
));
assertEquals
(
APP_NAME
,
registeredEvent
.
getAppName
());
assertEquals
(
HOST_NAME
,
registeredEvent
.
getServerId
());
assertEquals
(
instanceRegistry
,
registeredEvent
.
getSource
());
assertEquals
(
instanceInfo
,
registeredEvent
.
getInstanceInfo
());
assertFalse
(
registeredEvent
.
isReplication
());
assertEquals
(
APP_NAME
,
event1
.
getAppName
());
assertEquals
(
INSTANCE_ID
,
event1
.
getServerId
());
assertEquals
(
instanceRegistry
,
event1
.
getSource
());
assertEquals
(
instanceInfo1
,
event1
.
getInstanceInfo
());
assertFalse
(
event1
.
isReplication
());
final
EurekaInstanceRenewedEvent
event2
=
(
EurekaInstanceRenewedEvent
)
(
applicationEvents
.
get
(
1
));
assertEquals
(
instanceInfo2
,
event2
.
getInstanceInfo
());
}
@Configuration
...
...
@@ -165,11 +173,13 @@ public class InstanceRegistryTest {
return
leaseBuilder
.
build
();
}
private
InstanceInfo
getInstanceInfo
(
LeaseInfo
leaseInfo
)
{
private
InstanceInfo
getInstanceInfo
(
String
appName
,
String
hostName
,
String
instanceId
,
int
port
,
LeaseInfo
leaseInfo
)
{
InstanceInfo
.
Builder
builder
=
InstanceInfo
.
Builder
.
newBuilder
();
builder
.
setAppName
(
APP_NAME
);
builder
.
setHostName
(
HOST_NAME
);
builder
.
setPort
(
8008
);
builder
.
setAppName
(
appName
);
builder
.
setHostName
(
hostName
);
builder
.
setInstanceId
(
instanceId
);
builder
.
setPort
(
port
);
builder
.
setLeaseInfo
(
leaseInfo
);
return
builder
.
build
();
}
...
...
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