Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/sun/net/InetAddress/nameservice/B6442088.java
+++ new/test/sun/net/InetAddress/nameservice/simple/DefaultCaching.java
1 1 /*
2 2 * Copyright (c) 2006, 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.
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 *
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 6442088
26 26 * @summary Change default DNS caching behavior for code not running under
27 27 * security manager.
28 - *
29 - * @build B6442088 SimpleNameService SimpleNameServiceDescriptor
30 - * @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 -Dsun.net.spi.nameservice.provider.1=simple,sun B6442088
28 + * @compile -XDignore.symbol.file=true SimpleNameService.java
29 + * SimpleNameServiceDescriptor.java
30 + * @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 -Dsun.net.spi.nameservice.provider.1=simple,sun DefaultCaching
31 31 */
32 32 import java.net.InetAddress;
33 33 import java.net.UnknownHostException;
34 34 import java.security.Security;
35 35
36 -public class B6442088 {
36 +public class DefaultCaching {
37 37
38 38 public static void main(String args[]) throws Exception {
39 39
40 40 // name service needs to resolve this.
41 41 SimpleNameService.put("theclub", "129.156.220.219");
42 42
43 43 test ("theclub", "129.156.220.219", true); // lk: 1
44 44 test ("luster", "1.16.20.2", false); // lk: 2
45 45
46 46 // name service now needs to know about luster
47 47 SimpleNameService.put("luster", "10.5.18.21");
48 48
49 49 test ("luster", "1.16.20.2", false); // lk: 2
50 50 sleep (10+1);
51 51 test("luster", "10.5.18.21", true, 3); // lk: 3
52 52 sleep (5);
53 53
54 54 SimpleNameService.put("foo", "10.5.18.22");
55 55 SimpleNameService.put("theclub", "129.156.220.1");
56 56
57 57 test ("theclub", "129.156.220.219", true, 3);
58 58 test ("luster", "10.5.18.21", true, 3);
59 59 test ("bar", "10.5.18.22", false, 4);
60 60 test ("foo", "10.5.18.22", true, 5);
61 61
62 62 // now delay to see if theclub has expired
63 63 sleep (5);
64 64
65 65 test ("foo", "10.5.18.22", true, 5);
66 66 test ("theclub", "129.156.220.1", true, 6);
67 67
68 68 sleep (11);
69 69 // now see if luster has expired
70 70 test ("luster", "10.5.18.21", true, 7);
71 71 test ("theclub", "129.156.220.1", true, 7);
72 72
73 73 // now delay to see if 3rd has expired
74 74 sleep (10+6);
75 75
76 76 test ("theclub", "129.156.220.1", true, 8);
77 77 test ("luster", "10.5.18.21", true, 8);
78 78 test ("foo", "10.5.18.22", true, 9);
79 79 }
80 80
81 81 /* throws RuntimeException if it fails */
82 82
83 83 static void test (String host, String address,
84 84 boolean shouldSucceed, int count) {
85 85 test (host, address, shouldSucceed);
86 86 int got = SimpleNameService.lookupCalls();
87 87 if (got != count) {
88 88 throw new RuntimeException ("lookups exp/got: " + count+"/"+got);
89 89 }
90 90 }
91 91
92 92 static void sleep (int seconds) {
93 93 try {
94 94 Thread.sleep (seconds * 1000);
95 95 } catch (InterruptedException e) {}
96 96 }
97 97
98 98 static void test (String host, String address, boolean shouldSucceed) {
99 99 InetAddress addr = null;
100 100 try {
101 101 addr = InetAddress.getByName (host);
102 102 if (!shouldSucceed) {
103 103 throw new RuntimeException (host+":"+address+": should fail");
104 104
105 105 }
106 106 if (!address.equals(addr.getHostAddress())) {
107 107 throw new RuntimeException(host+":"+address+": compare failed");
108 108 }
109 109 } catch (UnknownHostException e) {
110 110 if (shouldSucceed) {
111 111 throw new RuntimeException(host+":"+address+": should succeed");
112 112 }
113 113 }
114 114 }
115 115
116 116 }
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX