Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/sun/net/InetAddress/nameservice/CacheTest.java
+++ new/test/sun/net/InetAddress/nameservice/simple/CacheTest.java
1 1 /*
2 2 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 */
23 23
24 24 /* @test
25 25 * @bug 4292867
26 26 * @summary Check that InetAddress doesn't continue to throw UHE
27 27 * after the name service has recovered and the negative ttl
28 28 * on the initial lookup has expired.
29 - *
30 - * @build CacheTest SimpleNameService SimpleNameServiceDescriptor
29 + * @compile -XDignore.symbol.file=true SimpleNameService.java
30 + * SimpleNameServiceDescriptor.java
31 31 * @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun CacheTest
32 32 */
33 33 import java.net.InetAddress;
34 34 import java.net.UnknownHostException;
35 35 import java.security.Security;
36 36
37 37 public class CacheTest {
38 38
39 39
40 40 public static void main(String args[]) throws Exception {
41 41
42 42 /*
43 43 * First check the ttl on negative lookups is in the <15 second
44 44 * range. If the ttl is <=0 it means we cache forever or always
45 45 * consult the name service. For ttl > 15 the test would take
46 46 * too long so we skip it (need to coordinate jtreg timeout
47 47 * with negative ttl)
48 48 */
49 49 String ttlProp = "networkaddress.cache.negative.ttl";
50 50 int ttl = 0;
51 51 String policy = Security.getProperty(ttlProp);
52 52 if (policy != null) {
53 53 ttl = Integer.parseInt(policy);
54 54 }
55 55 if (ttl <= 0 || ttl > 15) {
56 56 System.err.println("Security property " + ttlProp + " needs to " +
57 57 " in 1-15 second range to execute this test");
58 58 return;
59 59
60 60 }
61 61
62 62 /*
63 63 * The following outlines how the test works :-
64 64 *
65 65 * 1. Do a lookup via InetAddress.getByName that it guaranteed
66 66 * to succeed. This forces at least one entry into the cache
67 67 * that will not expire.
68 68 *
69 69 * 2. Do a lookup via InetAddress.getByName that is guarnateed
70 70 * to fail. This results in a negative lookup cached for
71 71 * for a short period to time.
72 72 *
73 73 * 3. Wait for the cache entry to expire.
74 74 *
75 75 * 4. Do a lookup (which should consult the name service) and
76 76 * the lookup should succeed.
77 77 */
78 78
79 79 // name service needs to resolve this.
80 80 SimpleNameService.put("theclub", "129.156.220.219");
81 81
82 82 // this lookup will succeed
83 83 InetAddress.getByName("theclub");
84 84
85 85 // lookup "luster" - this should throw UHE as name service
86 86 // doesn't know anything about this host.
87 87
88 88 try {
89 89 InetAddress.getByName("luster");
90 90 throw new RuntimeException("Test internal error " +
91 91 " - luster is bring resolved by name service");
92 92 } catch (UnknownHostException x) {
93 93 }
94 94
95 95 // name service now needs to know about luster
96 96 SimpleNameService.put("luster", "10.5.18.21");
97 97
98 98 // wait for the cache entry to expire and lookup should
99 99 // succeed.
100 100 Thread.currentThread().sleep(ttl*1000 + 1000);
101 101 InetAddress.getByName("luster");
102 102 }
103 103
104 104 }
↓ open down ↓ |
64 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX