-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related: #6056 Motivation: Users might want to use the metadata from the Eureka `InstanceInfo` but currently, there's no way to retrieve it. Modifications: - Remove helper class because users cannot access this class to retrieve `InstanceInfo`. - Move `com.linecorp.armeria.internal.common.eureka.InstanceInfo` to `com.linecorp.armeria.common.eureka.InstanceInfo`. - Move the methods to the `InstanceInfo` class. - Add a test to verify that users can retrieve the `InstanceInfo`. Result: - Closes #6056 - Now users can retrieve it.
- Loading branch information
1 parent
67e0c88
commit b99a0b0
Showing
10 changed files
with
158 additions
and
37 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
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
22 changes: 22 additions & 0 deletions
22
eureka/src/main/java/com/linecorp/armeria/common/eureka/package-info.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,22 @@ | ||
/* | ||
* Copyright 2020 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
/** | ||
* <a href="https://github.com/Netflix/eureka/">Eureka</a>-related common classes. | ||
*/ | ||
@NonNullByDefault | ||
package com.linecorp.armeria.common.eureka; | ||
|
||
import com.linecorp.armeria.common.annotation.NonNullByDefault; |
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
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
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
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
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
83 changes: 83 additions & 0 deletions
83
eureka/src/test/java/com/linecorp/armeria/common/eureka/InstanceInfoTest.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,83 @@ | ||
package com.linecorp.armeria.common.eureka; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.linecorp.armeria.client.Endpoint; | ||
import com.linecorp.armeria.common.eureka.InstanceInfo.InstanceStatus; | ||
import com.linecorp.armeria.common.eureka.InstanceInfo.PortWrapper; | ||
import com.linecorp.armeria.internal.common.eureka.DataCenterInfo; | ||
import com.linecorp.armeria.internal.common.eureka.LeaseInfo; | ||
|
||
class InstanceInfoTest { | ||
|
||
@Test | ||
void getShouldReturnAssociatedInstanceInfo() { | ||
|
||
final String instanceId = "123"; | ||
final String appName = "myApp"; | ||
final String appGroupName = "myGroup"; | ||
final String hostName = "myHost"; | ||
final String ipAddr = "192.168.1.1"; | ||
final String vipAddress = "10.0.0.1"; | ||
final String secureVipAddress = "10.0.0.2"; | ||
final PortWrapper port = new PortWrapper(true,80); | ||
final PortWrapper securePort = new PortWrapper(true,443); | ||
final InstanceInfo. InstanceStatus status = InstanceStatus.UP; | ||
final String homePageUrl = "https://example.com"; | ||
final String statusPageUrl = "https://status.example.com"; | ||
final String healthCheckUrl = "/health"; | ||
final String secureHealthCheckUrl = "/secure/health"; | ||
final DataCenterInfo dataCenterInfo = new DataCenterInfo("name",new HashMap<>()); | ||
final LeaseInfo leaseInfo = new LeaseInfo(30,90); | ||
final Map<String, String> metadata = new HashMap<>(); | ||
final InstanceInfo instanceInfo = new InstanceInfo( | ||
instanceId, | ||
appName, | ||
appGroupName, | ||
hostName, | ||
ipAddr, | ||
vipAddress, | ||
secureVipAddress, | ||
port, | ||
securePort, | ||
status, | ||
homePageUrl, | ||
statusPageUrl, | ||
healthCheckUrl, | ||
secureHealthCheckUrl, | ||
dataCenterInfo, | ||
leaseInfo, | ||
metadata | ||
); | ||
final Endpoint endpoint = Endpoint.parse("foo"); | ||
|
||
final Endpoint endpointWith = InstanceInfo.with(endpoint, instanceInfo); | ||
|
||
final InstanceInfo instanceInfoRetrieved = InstanceInfo.get(endpointWith); | ||
assertThat(instanceInfoRetrieved).isNotNull(); | ||
assertThat(instanceInfoRetrieved).isSameAs(instanceInfo); | ||
assertThat(instanceInfoRetrieved.getInstanceId()).isEqualTo(instanceId); | ||
assertThat(instanceInfoRetrieved.getAppName()).isEqualTo(appName); | ||
assertThat(instanceInfoRetrieved.getAppGroupName()).isEqualTo(appGroupName); | ||
assertThat(instanceInfoRetrieved.getHostName()).isEqualTo(hostName); | ||
assertThat(instanceInfoRetrieved.getIpAddr()).isEqualTo(ipAddr); | ||
assertThat(instanceInfoRetrieved.getVipAddress()).isEqualTo(vipAddress); | ||
assertThat(instanceInfoRetrieved.getSecureVipAddress()).isEqualTo(secureVipAddress); | ||
assertThat(instanceInfoRetrieved.getPort()).isEqualTo(port); | ||
assertThat(instanceInfoRetrieved.getSecurePort()).isEqualTo(securePort); | ||
assertThat(instanceInfoRetrieved.getStatus()).isEqualTo(status); | ||
assertThat(instanceInfoRetrieved.getHomePageUrl()).isEqualTo(homePageUrl); | ||
assertThat(instanceInfoRetrieved.getStatusPageUrl()).isEqualTo(statusPageUrl); | ||
assertThat(instanceInfoRetrieved.getHealthCheckUrl()).isEqualTo(healthCheckUrl); | ||
assertThat(instanceInfoRetrieved.getSecureHealthCheckUrl()).isEqualTo(secureHealthCheckUrl); | ||
assertThat(instanceInfoRetrieved.getDataCenterInfo()).isEqualTo(dataCenterInfo); | ||
assertThat(instanceInfoRetrieved.getLeaseInfo()).isEqualTo(leaseInfo); | ||
assertThat(instanceInfoRetrieved.getMetadata()).isEqualTo(metadata); | ||
|
||
} | ||
} |
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