-
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.
Deprecate ArmeriaSettings.ip and add ArmeriaSettings.address (#4598)
Motivation: Spring allows Users to specify a hostname because Spring converts the input to an InetAddress. So we need to also allow users to specify a hostname. Modifications: - adding ArmeriaSettings.address whose type is InetAddress - deprecating ArmeriaSettings.ip Result: - Closes #4597
- Loading branch information
Showing
9 changed files
with
224 additions
and
22 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
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
66 changes: 66 additions & 0 deletions
66
spring/boot2-autoconfigure/src/test/java/com/linecorp/armeria/spring/DeprecatedIpTest.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,66 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
package com.linecorp.armeria.spring; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.InetAddress; | ||
import java.util.Collection; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.linecorp.armeria.server.Server; | ||
import com.linecorp.armeria.server.ServerPort; | ||
import com.linecorp.armeria.spring.ArmeriaSettings.Port; | ||
import com.linecorp.armeria.spring.DeprecatedIpTest.TestConfiguration; | ||
|
||
/** | ||
* Tests for keeping the behavior of deprecated {@link Port#getIp()}. | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = TestConfiguration.class) | ||
@ActiveProfiles({ "local", "deprecatedIpTest" }) | ||
@DirtiesContext | ||
public class DeprecatedIpTest { | ||
|
||
@SpringBootApplication | ||
static class TestConfiguration {} | ||
|
||
@Inject | ||
private Server server; | ||
|
||
@Test | ||
public void testIpCanBeUsed() { | ||
final Collection<ServerPort> serverPorts = server.activePorts().values(); | ||
for (ServerPort sp : serverPorts) { | ||
final InetAddress address = sp.localAddress().getAddress(); | ||
if ("127.0.0.1".equals(address.getHostAddress())) { | ||
assertThat(address.isLoopbackAddress()).isTrue(); | ||
} else { | ||
// Setting 0.0.0.0 at properties | ||
assertThat(address.isAnyLocalAddress()).isTrue(); | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...g/boot2-autoconfigure/src/test/java/com/linecorp/armeria/spring/LocalhostAddressTest.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,62 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
package com.linecorp.armeria.spring; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.InetAddress; | ||
import java.util.Collection; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.linecorp.armeria.server.Server; | ||
import com.linecorp.armeria.server.ServerPort; | ||
import com.linecorp.armeria.spring.ArmeriaSettings.Port; | ||
import com.linecorp.armeria.spring.LocalhostAddressTest.TestConfiguration; | ||
|
||
/** | ||
* Tests for keeping the behavior of {@link Port#getIp()}. | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = TestConfiguration.class) | ||
@ActiveProfiles({ "local", "localhostAddressTest" }) | ||
@DirtiesContext | ||
public class LocalhostAddressTest { | ||
|
||
@SpringBootApplication | ||
static class TestConfiguration {} | ||
|
||
@Inject | ||
private Server server; | ||
|
||
@Test | ||
public void testLocalhostAddressCanBeUsed() { | ||
final Collection<ServerPort> serverPorts = server.activePorts().values(); | ||
assertThat(serverPorts).hasSize(1); | ||
for (ServerPort sp : serverPorts) { | ||
final InetAddress address = sp.localAddress().getAddress(); | ||
assertThat(address.isLoopbackAddress()).isTrue(); | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
spring/boot2-autoconfigure/src/test/resources/config/application-deprecatedIpTest.yml
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,8 @@ | ||
armeria: | ||
ports: | ||
- ip: 127.0.0.1 | ||
port: 0 | ||
protocol: HTTP | ||
- ip: 0.0.0.0 | ||
port: 0 | ||
protocol: HTTP |
5 changes: 5 additions & 0 deletions
5
spring/boot2-autoconfigure/src/test/resources/config/application-localhostAddressTest.yml
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,5 @@ | ||
armeria: | ||
ports: | ||
- address: localhost | ||
port: 0 | ||
protocol: HTTP |