Enfore upper limit for minTtl when using DefaultCacheEntry. (#7920)
Motivation:
a598c3b69b
added a upper limit for ttl but missed to also do the same for minTtl.
Modifications:
- Add upper limit for minTtl
- Add testcase.
Result:
No more IllegalArgumentException possible.
This commit is contained in:
parent
a0ed6ec06c
commit
f01a590154
@ -65,8 +65,8 @@ public class DefaultDnsCache implements DnsCache {
|
|||||||
* @param negativeTtl the TTL for failed queries
|
* @param negativeTtl the TTL for failed queries
|
||||||
*/
|
*/
|
||||||
public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl) {
|
public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl) {
|
||||||
this.minTtl = checkPositiveOrZero(minTtl, "minTtl");
|
this.minTtl = Math.min(MAX_SUPPORTED_TTL_SECS, checkPositiveOrZero(minTtl, "minTtl"));
|
||||||
this.maxTtl = checkPositiveOrZero(maxTtl, "maxTtl");
|
this.maxTtl = Math.min(MAX_SUPPORTED_TTL_SECS, checkPositiveOrZero(maxTtl, "maxTtl"));
|
||||||
if (minTtl > maxTtl) {
|
if (minTtl > maxTtl) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"minTtl: " + minTtl + ", maxTtl: " + maxTtl + " (expected: 0 <= minTtl <= maxTtl)");
|
"minTtl: " + minTtl + ", maxTtl: " + maxTtl + " (expected: 0 <= minTtl <= maxTtl)");
|
||||||
|
@ -86,6 +86,19 @@ public class DefaultDnsCacheTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExpireWithToBigMinTTL() {
|
||||||
|
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
EventLoop loop = group.next();
|
||||||
|
final DefaultDnsCache cache = new DefaultDnsCache(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||||
|
assertNotNull(cache.cache("netty.io", null, NetUtil.LOCALHOST, 100, loop));
|
||||||
|
} finally {
|
||||||
|
group.shutdownGracefully();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddMultipleAddressesForSameHostname() throws Exception {
|
public void testAddMultipleAddressesForSameHostname() throws Exception {
|
||||||
InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 });
|
InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 });
|
||||||
|
Loading…
Reference in New Issue
Block a user