|
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Map; |
25 | 25 |
|
| 26 | +import com.netflix.appinfo.AmazonInfo; |
26 | 27 | import com.netflix.appinfo.ApplicationInfoManager; |
27 | 28 | import com.netflix.appinfo.DataCenterInfo; |
28 | 29 | import com.netflix.appinfo.InstanceInfo; |
@@ -117,11 +118,45 @@ void testStatus() { |
117 | 118 | assertThat((Boolean) instance.get("isHref")).as("isHref was wrong").isFalse(); |
118 | 119 | } |
119 | 120 |
|
| 121 | + @Test |
| 122 | + void statusUsesDefaultAmiForAmazonInstancesWithoutAmiMetadata() { |
| 123 | + AmazonInfo amazonInfo = new AmazonInfo(null, new HashMap<>()); |
| 124 | + Application app = new Application("myapp"); |
| 125 | + app.addInstance(InstanceInfo.Builder.newBuilder() |
| 126 | + .setAppName("myapp") |
| 127 | + .setDataCenterInfo(amazonInfo) |
| 128 | + .setInstanceId("myapp:1") |
| 129 | + .build()); |
| 130 | + |
| 131 | + when(getServerContext().getRegistry().getSortedApplications()).thenReturn(Collections.singletonList(app)); |
| 132 | + |
| 133 | + Map<String, Object> model = new HashMap<>(); |
| 134 | + EurekaController controller = new EurekaController(infoManager, new EurekaProperties()); |
| 135 | + |
| 136 | + controller.status(new MockHttpServletRequest("GET", "/"), model); |
| 137 | + |
| 138 | + Map<String, Object> appData = getFirst(model, "apps"); |
| 139 | + Map.Entry<String, Integer> amiCount = getFirstEntry(appData, "amiCounts"); |
| 140 | + assertThat(amiCount.getKey()).isEqualTo("n/a"); |
| 141 | + assertThat(amiCount.getValue()).isEqualTo(1); |
| 142 | + } |
| 143 | + |
| 144 | + private EurekaServerContext getServerContext() { |
| 145 | + return EurekaServerContextHolder.getInstance().getServerContext(); |
| 146 | + } |
| 147 | + |
120 | 148 | @SuppressWarnings("unchecked") |
121 | 149 | Map<String, Object> getFirst(Map<String, Object> model, String key) { |
122 | 150 | List<Map<String, Object>> apps = (List<Map<String, Object>>) model.get(key); |
123 | 151 | assertThat(apps).as(key + " was wrong size").hasSize(1); |
124 | 152 | return apps.get(0); |
125 | 153 | } |
126 | 154 |
|
| 155 | + @SuppressWarnings("unchecked") |
| 156 | + Map.Entry<String, Integer> getFirstEntry(Map<String, Object> model, String key) { |
| 157 | + Iterable<Map.Entry<String, Integer>> entries = (Iterable<Map.Entry<String, Integer>>) model.get(key); |
| 158 | + assertThat(entries).as(key + " was wrong size").hasSize(1); |
| 159 | + return entries.iterator().next(); |
| 160 | + } |
| 161 | + |
127 | 162 | } |
0 commit comments