-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate ArmeriaSettings.ip and add ArmeriaSettings.address #4598
Changes from 7 commits
22f354e
369b08f
d4af03d
d64553c
14f2149
fef7903
641077b
1609c08
e19e1e6
f4a6785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ | |||||
*/ | ||||||
package com.linecorp.armeria.spring; | ||||||
|
||||||
import java.net.InetAddress; | ||||||
import java.time.Duration; | ||||||
import java.util.ArrayList; | ||||||
import java.util.List; | ||||||
|
@@ -48,7 +49,7 @@ | |||||
* ports: | ||||||
* - port: 8080 | ||||||
* protocol: HTTP | ||||||
* - ip: 127.0.0.1 | ||||||
* - address: 127.0.0.1 | ||||||
* port: 8081 | ||||||
* protocol:HTTP | ||||||
* - port: 8443 | ||||||
|
@@ -82,10 +83,18 @@ public class ArmeriaSettings { | |||||
public static class Port { | ||||||
/** | ||||||
* IP address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}. | ||||||
* @deprecated Use {@link #address} instead. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a blank line between the doc and |
||||||
*/ | ||||||
@Deprecated | ||||||
@Nullable | ||||||
private String ip; | ||||||
|
||||||
/** | ||||||
* Network address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}. | ||||||
*/ | ||||||
@Nullable | ||||||
private InetAddress address; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit; do you mind also updating the example? armeria/spring/boot2-autoconfigure/src/main/java/com/linecorp/armeria/spring/ArmeriaSettings.java Line 51 in e376b8c
|
||||||
|
||||||
/** | ||||||
* Network interface to bind to. If not set, will bind to the first detected network interface. | ||||||
*/ | ||||||
|
@@ -105,20 +114,40 @@ public static class Port { | |||||
|
||||||
/** | ||||||
* Returns the IP address that the {@link Server} uses. | ||||||
* @deprecated Use {@link #getAddress()} instead. | ||||||
*/ | ||||||
@Deprecated | ||||||
@Nullable | ||||||
public String getIp() { | ||||||
return ip; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Registers an IP address that the {@link Server} uses. | ||||||
* @deprecated Use {@link #setAddress(InetAddress)} instead. | ||||||
*/ | ||||||
@Deprecated | ||||||
public Port setIp(String ip) { | ||||||
this.ip = ip; | ||||||
return this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns the Network address that the {@link Server} uses. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I guess we don't need to capitalize the word
Suggested change
|
||||||
*/ | ||||||
@Nullable | ||||||
public InetAddress getAddress() { | ||||||
return address; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Registers a Network address that the {@link Server} uses. | ||||||
*/ | ||||||
public Port setAddress(InetAddress address) { | ||||||
this.address = address; | ||||||
return this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns the network interface that the {@link Server} uses. | ||||||
*/ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy new year. 🎉 🎉 🎉 |
||
* | ||
* 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 {@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(); | ||
assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: are these values different depending on the OS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure, I just put 127.0.0.1 & 0.0.0.0 at yml, so keep test both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ha, if so how about branching it so that we can be sure what the test actually means? if ("127.0.0.1".equals(address.getHostAddress())) {
assertThat(...).isTrue();
} else {
// 0.0.0.0
assertThat(...).isTrue();
} |
||
} | ||
} | ||
} |
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(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||
armeria: | ||||||
ports: | ||||||
- ip: 127.0.0.1 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional; I'm unsure if this would also work in windows, but I think it would be cool if we can check that non-ip addresses are also accepted
Suggested change
|
||||||
port: 0 | ||||||
protocol: HTTP | ||||||
- ip: 0.0.0.0 | ||||||
port: 0 | ||||||
protocol: HTTP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
armeria: | ||
ports: | ||
- address: localhost | ||
port: 0 | ||
protocol: HTTP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we override
Port.toString()
to properly create the message?