-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from Knewton/fix-shuffleVirtualHostNameMap
Fix bug where shuffleVirtualHostNameMap isn't updated
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
eureka-client/src/test/java/com/netflix/discovery/shared/ApplicationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.netflix.discovery.shared; | ||
|
||
|
||
import com.google.common.collect.Iterables; | ||
import com.netflix.appinfo.DataCenterInfo; | ||
import com.netflix.appinfo.InstanceInfo; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static junit.framework.Assert.assertNull; | ||
import static junit.framework.Assert.assertTrue; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ApplicationsTest { | ||
|
||
/** | ||
* Test that instancesMap in Application and shuffleVirtualHostNameMap in Applications are | ||
* correctly updated when the last instance is removed from an application and shuffleInstances | ||
* has been run. | ||
*/ | ||
@Test | ||
public void shuffleVirtualHostNameMapLastInstanceTest() { | ||
DataCenterInfo myDCI = new DataCenterInfo(){ | ||
public DataCenterInfo.Name getName(){return DataCenterInfo.Name.MyOwn;} | ||
}; | ||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder() | ||
.setAppName("test") | ||
.setVIPAddress("test.testname:1") | ||
.setDataCenterInfo(myDCI) | ||
.setHostName("test.hostname").build(); | ||
|
||
Application application = new Application("TestApp"); | ||
application.addInstance(instanceInfo); | ||
Applications applications = new Applications(); | ||
applications.addApplication(application); | ||
applications.shuffleInstances(true); | ||
List<InstanceInfo> testApp = applications.getInstancesByVirtualHostName("test.testname:1"); | ||
|
||
assertEquals(Iterables.getOnlyElement(testApp), | ||
application.getByInstanceId("test.hostname")); | ||
|
||
application.removeInstance(instanceInfo); | ||
applications.shuffleInstances(true); | ||
testApp = applications.getInstancesByVirtualHostName("test.testname:1"); | ||
|
||
assertNull(application.getByInstanceId("test.hostname")); | ||
assertTrue(testApp.isEmpty()); | ||
} | ||
} |