8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/ jdk-12+4
authorxyin
Wed, 25 Jul 2018 11:03:07 +0800
changeset 51192 499b873761d8
parent 51191 96fae3a62612
child 51193 f4f5f961a81f
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/ Reviewed-by: vtewari, rriggs
test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsBase.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.dns
test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.java
test/jdk/com/sun/jndi/dns/AttributeTests/GetRRsBase.java
test/jdk/com/sun/jndi/dns/lib/DNSServer.java
test/jdk/com/sun/jndi/dns/lib/DNSTestBase.java
test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java
test/jdk/com/sun/jndi/dns/lib/DNSTracer.java
test/jdk/com/sun/jndi/dns/lib/Server.java
test/jdk/com/sun/jndi/dns/lib/TestBase.java
--- a/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java	Tue Jul 24 08:58:32 2018 -0700
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java	Wed Jul 25 11:03:07 2018 +0800
@@ -28,54 +28,33 @@
  *          qualifiers.
  * @modules java.base/sun.security.util
  * @library ../lib/
- * @build DNSTestUtils DNSServer DNSTracer
  * @run main GetAny
  */
 
 import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.util.Hashtable;
 
-public class GetAny {
-    private static final String KEY = "host1";
+public class GetAny extends GetAttrsBase {
 
-    private static final String[] MANDATORY = { "A", "MX", "HINFO", "TXT", "29"
-            // "LOC"
-    };
+    public static void main(String[] args) throws Exception {
+        new GetAny().run(args);
+    }
 
-    private static final String[] OPTIONAL = {};
-
-    public static void main(String argv[]) throws Exception {
-        // Create socket on localhost only to avoid possible noise packet
-        DatagramSocket socket = new DatagramSocket(0,
-                InetAddress.getLoopbackAddress());
+    @Override public Attributes getAttributes() {
+        return null;
+    }
 
-        // initialize test
-        Hashtable<Object, Object> env;
-
-        env = DNSTestUtils.initEnv(socket, GetAny.class.getName(), argv);
-
-        DirContext ctx = null;
-
-        try {
-            // connect to server
-            ctx = new InitialDirContext(env);
+    @Override public void runTest() throws Exception {
+        initContext();
 
-            // Any type from IN class
-            Attributes retAttrs = ctx.getAttributes(KEY, new String[] { "*" });
-            DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL);
-
-            retAttrs = ctx.getAttributes(KEY, new String[] { "* *" });
-            DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL);
+        // Any type from IN class
+        Attributes retAttrs = context()
+                .getAttributes(getKey(), new String[] { "*" });
+        verifyAttributes(retAttrs);
 
-            retAttrs = ctx.getAttributes(KEY, new String[] { "IN *" });
-            DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL);
+        retAttrs = context().getAttributes(getKey(), new String[] { "* *" });
+        verifyAttributes(retAttrs);
 
-        } finally {
-            DNSTestUtils.cleanup(ctx);
-        }
+        retAttrs = context().getAttributes(getKey(), new String[] { "IN *" });
+        verifyAttributes(retAttrs);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrs.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrs application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 2F EA 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  /............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF                                           ...
+
+
+# DNS Response
+
+0000: 2F EA 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  /............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry.
+ *          Use getAttributes form that has no attrIds parameter.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrs
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetAttrs extends GetAttrsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrs().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry.
+     * Use getAttributes form that has no attrIds parameter.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsBase.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
+public abstract class GetAttrsBase extends DNSTestBase {
+    private String key;
+    private String[] mandatoryAttrs;
+
+    public GetAttrsBase() {
+        // set default test data
+        setKey("host1");
+        setMandatoryAttrs("A", "MX", "HINFO", "TXT", "29");
+    }
+
+    private static final String[] OPTIONAL_ATTRIBUTES = {};
+
+    public void initContext() throws Exception {
+        setContext(new InitialDirContext(env()));
+    }
+
+    public abstract Attributes getAttributes() throws Exception;
+
+    public void verifyAttributes(Attributes retAttrs) {
+        if (retAttrs != null) {
+            DNSTestUtils.verifySchema(retAttrs, mandatoryAttrs,
+                    OPTIONAL_ATTRIBUTES);
+        } else {
+            throw new RuntimeException("Attributes to be verified is null");
+        }
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String[] getMandatoryAttrs() {
+        return mandatoryAttrs;
+    }
+
+    public void setMandatoryAttrs(String... mandatoryAttrs) {
+        this.mandatoryAttrs = mandatoryAttrs;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsEmptyAttrIds.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsEmptyAttrIds application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: BC 12 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: BC 12 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry.
+ *          Specify that no attributes are to be returned.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrsEmptyAttrIds
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetAttrsEmptyAttrIds extends GetAttrsBase {
+
+    public GetAttrsEmptyAttrIds() {
+        // set new test data instead of default value
+        setMandatoryAttrs(new String[] {});
+    }
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsEmptyAttrIds().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry.
+     * Specify that no attributes are to be returned.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey(), new String[] {});
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsNonExistentAttrIds.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsNonExistentAttrIds application program against
+#       a real DNS server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: FC 9A 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: FC 9A 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry.
+ *          Supply at least one nonexistent attribute name in attrIds
+ *          (should be ignored).
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrsNonExistentAttrIds
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetAttrsNonExistentAttrIds extends GetAttrsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsNonExistentAttrIds().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry.
+     * Supply at least one nonexistent attribute name in attrIds
+     * (should be ignored).
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        String[] attrIds = new String[getMandatoryAttrs().length + 1];
+        attrIds[0] = "SOA";
+        System.arraycopy(getMandatoryAttrs(), 0, attrIds, 1,
+                getMandatoryAttrs().length);
+
+        return context().getAttributes(getKey(), attrIds);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsNotFound.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsNotFound application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 56 B1 01 00 00 01 00 00   00 00 00 00 08 6E 6F 74  V............not
+0010: 66 6F 75 6E 64 07 64 6F   6D 61 69 6E 31 03 63 6F  found.domain1.co
+0020: 6D 00 00 FF 00 FF                                  m.....
+
+
+# DNS Response
+
+0000: 56 B1 85 83 00 01 00 00   00 01 00 00 08 6E 6F 74  V............not
+0010: 66 6F 75 6E 64 07 64 6F   6D 61 69 6E 31 03 63 6F  found.domain1.co
+0020: 6D 00 00 FF 00 FF C0 15   00 06 00 01 00 00 8C A0  m...............
+0030: 00 26 02 6E 73 C0 15 0A   70 6F 73 74 6D 61 73 74  .&.ns...postmast
+0040: 65 72 C0 15 00 00 00 01   00 00 1C 20 00 00 0E 10  er......... ....
+0050: 00 06 97 80 00 01 51 80                            ......Q.
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that get attributes of a missing child entry results
+ *          in NameNotFoundException.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrsNotFound
+ */
+
+import javax.naming.NameNotFoundException;
+import javax.naming.directory.Attributes;
+
+public class GetAttrsNotFound extends GetAttrsBase {
+
+    public GetAttrsNotFound() {
+        // set new test data instead of default value
+        setKey("notfound");
+    }
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsNotFound().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        DNSTestUtils.debug(retAttrs);
+        throw new RuntimeException(
+                "Failed: getAttributes succeeded unexpectedly");
+    }
+
+    /*
+     * Tests that get attributes of a missing child entry results
+     * in NameNotFoundException.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey());
+    }
+
+    @Override public boolean handleException(Exception e) {
+        if (e instanceof NameNotFoundException) {
+            System.out.println("Got exception as expected : " + e);
+            return true;
+        }
+
+        return super.handleException(e);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsNullAttrIds.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsNullAttrIds application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 60 3C 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  `<...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF                                           ...
+
+
+# DNS Response
+
+0000: 60 3C 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  `<...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry.
+ *          Use getAttributes form that accepts an attrIds parameter
+ *          and supply null for it.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrsNullAttrIds
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetAttrsNullAttrIds extends GetAttrsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsNullAttrIds().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry.
+     * Use getAttributes form that accepts an attrIds parameter
+     * and supply null for it.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey(), null);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsSomeAttrIds.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsSomeAttrIds application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 20 34 01 00 00 01 00 00   00 00 00 00 05 68 6F 73   4...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 20 34 85 80 00 01 00 06   00 01 00 01 05 68 6F 73   4...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry.
+ *          Specify a subset of the attributes to be returned.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetAttrsSomeAttrIds
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetAttrsSomeAttrIds extends GetAttrsBase {
+
+    public GetAttrsSomeAttrIds() {
+        // set new test data instead of default value
+        setMandatoryAttrs("A", "MX", "TXT");
+    }
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsSomeAttrIds().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry.
+     * Specify a subset of the attributes to be returned.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey(), getMandatoryAttrs());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetNonstandard.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetNonstandard application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 43 D5 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  C............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 1D 00 01                                           ...
+
+
+# DNS Response
+
+0000: 43 D5 85 80 00 01 00 01   00 01 00 01 05 68 6F 73  C............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 1D 00 01 C0 0C 00 1D 00   01 00 00 8C A0 00 10 00  ................
+0030: 12 16 13 88 97 1A 35 69   68 41 38 00 9B 16 58 C0  ......5ihA8...X.
+0040: 12 00 02 00 01 00 00 8C   A0 00 05 02 6E 73 C0 12  ............ns..
+0050: C0 4B 00 01 00 01 00 00   8C A0 00 04 7F 00 00 01  .K..............
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get an attribute that has a nonstandard name from
+ *          a DNS entry.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetNonstandard
+ */
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import java.util.Arrays;
+
+public class GetNonstandard extends GetAttrsBase {
+    // "40 2 0.373 N 105 17 23.528 W 1638m"
+    private static final byte[] EXPECTED_VALUE = { (byte) 0,    // version
+            (byte) 18,    // size
+            (byte) 22,    // horiz pre
+            (byte) 19,    // vert pre
+            (byte) -120,    // latitude 1
+            (byte) -105,    // latitude 2
+            (byte) 26,    // longitude 1
+            (byte) 53,    // longitude 2
+            (byte) 105,    // altitude 1
+            (byte) 104,    // altitude 2
+            (byte) 65, (byte) 56, (byte) 0, (byte) -101, (byte) 22,
+            (byte) 88, };
+
+    public GetNonstandard() {
+        // set new test data instead of default value
+        setMandatoryAttrs("29");
+    }
+
+    public static void main(String[] args) throws Exception {
+        new GetNonstandard().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+        verifyLoc(retAttrs);
+    }
+
+    /*
+     * Tests that we can get an attribute that has a nonstandard name from
+     * a DNS entry.
+     */
+    @Override public Attributes getAttributes() throws Exception {
+        return context().getAttributes(getKey(), getMandatoryAttrs());
+    }
+
+    private void verifyLoc(Attributes retAttrs) throws NamingException {
+        Attribute loc = retAttrs.get(getMandatoryAttrs()[0]);
+        byte[] val = (byte[]) loc.get(0);
+
+        String expected = Arrays.toString(EXPECTED_VALUE);
+        String actual = Arrays.toString(val);
+        DNSTestUtils.debug("Expected: " + expected);
+        DNSTestUtils.debug("Actual:   " + actual);
+
+        if (!Arrays.equals(val, EXPECTED_VALUE)) {
+            throw new RuntimeException(String.format(
+                    "Failed: values not match, expected: %s, actual: %s",
+                    expected, actual));
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,148 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetNumericIRRs.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetNumericIRRs application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: D6 36 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .6...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: D6 36 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .6...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
+# DNS Request
+
+0000: 3F B9 01 00 00 01 00 00   00 00 00 00 07 64 6F 6D  ?............dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01           ain1.com.....
+
+
+# DNS Response
+
+0000: 3F B9 85 80 00 01 00 03   00 00 00 01 07 64 6F 6D  ?............dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01 C0 0C 00  ain1.com........
+0020: 06 00 01 00 00 8C A0 00   26 02 6E 73 C0 0C 0A 70  ........&.ns...p
+0030: 6F 73 74 6D 61 73 74 65   72 C0 0C 00 00 00 01 00  ostmaster.......
+0040: 00 1C 20 00 00 0E 10 00   06 97 80 00 01 51 80 C0  .. ..........Q..
+0050: 0C 00 02 00 01 00 00 8C   A0 00 02 C0 29 C0 0C 00  ............)...
+0060: 10 00 01 00 00 8C A0 00   0C 0B 54 65 73 74 20 64  ..........Test d
+0070: 6F 6D 61 69 6E C0 29 00   01 00 01 00 00 8C A0 00  omain.).........
+0080: 04 7F 00 00 01                                     .....
+
+
+# DNS Request
+
+0000: F2 5D 01 00 00 01 00 00   00 00 00 00 04 69 70 76  .]...........ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01                                              ..
+
+
+# DNS Response
+
+0000: F2 5D 85 80 00 01 00 01   00 01 00 01 04 69 70 76  .]...........ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01 C0 0C 00 1C 00 01   00 00 8C A0 00 10 00 0A  ................
+0030: 00 0B 00 0C 00 0D 00 0E   00 01 00 02 00 03 C0 11  ................
+0040: 00 02 00 01 00 00 8C A0   00 05 02 6E 73 C0 11 C0  ...........ns...
+0050: 4A 00 01 00 01 00 00 8C   A0 00 04 7F 00 00 01     J..............
+
+
+# DNS Request
+
+0000: 4E 2D 01 00 00 01 00 00   00 00 00 00 03 73 75 6E  N-...........sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01                                                 .
+
+
+# DNS Response
+
+0000: 4E 2D 85 80 00 01 00 01   00 01 00 01 03 73 75 6E  N-...........sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01 C0 0C 00 05 00 01 00   00 8C A0 00 08 05 68 6F  ..............ho
+0030: 73 74 31 C0 10 C0 10 00   02 00 01 00 00 8C A0 00  st1.............
+0040: 05 02 6E 73 C0 10 C0 41   00 01 00 01 00 00 8C A0  ..ns...A........
+0050: 00 04 7F 00 00 01                                  ......
+
+
+# DNS Request
+
+0000: 9D 9B 01 00 00 01 00 00   00 00 00 00 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01                               om..!..
+
+
+# DNS Response
+
+0000: 9D 9B 85 80 00 01 00 01   00 01 00 02 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01 C0   0C 00 21 00 01 00 00 8C  om..!.....!.....
+0030: A0 00 19 00 01 00 00 00   15 05 68 6F 73 74 34 07  ..........host4.
+0040: 64 6F 6D 61 69 6E 31 03   63 6F 6D 00 C0 3F 00 02  domain1.com..?..
+0050: 00 01 00 00 8C A0 00 05   02 6E 73 C0 3F C0 39 00  .........ns.?.9.
+0060: 01 00 01 00 01 51 80 00   04 01 02 04 04 C0 58 00  .....Q........X.
+0070: 01 00 01 00 00 8C A0 00   04 7F 00 00 01           .............
+
+
+# DNS Request
+
+0000: 77 5B 01 00 00 01 00 00   00 00 00 00 01 31 01 34  w[...........1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01                                  a.....
+
+
+# DNS Response
+
+0000: 77 5B 85 80 00 01 00 01   00 01 00 01 01 31 01 34  w[...........1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01 C0 0C   00 0C 00 01 00 00 8C A0  a...............
+0030: 00 13 05 68 6F 73 74 31   07 64 6F 6D 61 69 6E 31  ...host1.domain1
+0040: 03 63 6F 6D 00 C0 0E 00   02 00 01 00 00 8C A0 00  .com............
+0050: 05 02 6E 73 C0 38 C0 51   00 01 00 01 00 00 8C A0  ..ns.8.Q........
+0060: 00 04 7F 00 00 01                                  ......
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry by naming
+ *          specific RRs by their type codes and "IN" for internet class.
+ *          Omit NAPTR for now because bind doesn't support it.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetNumericIRRs
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetNumericIRRs extends GetRRsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetNumericIRRs().run(args);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry by naming
+     * specific RRs by their type codes and "IN" for internet class.
+     * Omit NAPTR for now because bind doesn't support it.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        for (int i = 0; i < ROOT_LIMIT; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getNumAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+
+        switchToRootUrl();
+
+        for (int i = ROOT_LIMIT; i < getKeys().length; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getNumAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,148 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetNumericRRs.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetNumericRRs application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 7C 4B 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .K...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 7C 4B 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .K...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
+# DNS Request
+
+0000: 60 6F 01 00 00 01 00 00   00 00 00 00 07 64 6F 6D  `o...........dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01           ain1.com.....
+
+
+# DNS Response
+
+0000: 60 6F 85 80 00 01 00 03   00 00 00 01 07 64 6F 6D  `o...........dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01 C0 0C 00  ain1.com........
+0020: 06 00 01 00 00 8C A0 00   26 02 6E 73 C0 0C 0A 70  ........&.ns...p
+0030: 6F 73 74 6D 61 73 74 65   72 C0 0C 00 00 00 01 00  ostmaster.......
+0040: 00 1C 20 00 00 0E 10 00   06 97 80 00 01 51 80 C0  .. ..........Q..
+0050: 0C 00 02 00 01 00 00 8C   A0 00 02 C0 29 C0 0C 00  ............)...
+0060: 10 00 01 00 00 8C A0 00   0C 0B 54 65 73 74 20 64  ..........Test d
+0070: 6F 6D 61 69 6E C0 29 00   01 00 01 00 00 8C A0 00  omain.).........
+0080: 04 7F 00 00 01                                     .....
+
+
+# DNS Request
+
+0000: 97 B5 01 00 00 01 00 00   00 00 00 00 04 69 70 76  .............ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01                                              ..
+
+
+# DNS Response
+
+0000: 97 B5 85 80 00 01 00 01   00 01 00 01 04 69 70 76  .............ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01 C0 0C 00 1C 00 01   00 00 8C A0 00 10 00 0A  ................
+0030: 00 0B 00 0C 00 0D 00 0E   00 01 00 02 00 03 C0 11  ................
+0040: 00 02 00 01 00 00 8C A0   00 05 02 6E 73 C0 11 C0  ...........ns...
+0050: 4A 00 01 00 01 00 00 8C   A0 00 04 7F 00 00 01     J..............
+
+
+# DNS Request
+
+0000: 61 7E 01 00 00 01 00 00   00 00 00 00 03 73 75 6E  a............sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01                                                 .
+
+
+# DNS Response
+
+0000: 61 7E 85 80 00 01 00 01   00 01 00 01 03 73 75 6E  a............sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01 C0 0C 00 05 00 01 00   00 8C A0 00 08 05 68 6F  ..............ho
+0030: 73 74 31 C0 10 C0 10 00   02 00 01 00 00 8C A0 00  st1.............
+0040: 05 02 6E 73 C0 10 C0 41   00 01 00 01 00 00 8C A0  ..ns...A........
+0050: 00 04 7F 00 00 01                                  ......
+
+
+# DNS Request
+
+0000: 7D 9A 01 00 00 01 00 00   00 00 00 00 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01                               om..!..
+
+
+# DNS Response
+
+0000: 7D 9A 85 80 00 01 00 01   00 01 00 02 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01 C0   0C 00 21 00 01 00 00 8C  om..!.....!.....
+0030: A0 00 19 00 01 00 00 00   15 05 68 6F 73 74 34 07  ..........host4.
+0040: 64 6F 6D 61 69 6E 31 03   63 6F 6D 00 C0 3F 00 02  domain1.com..?..
+0050: 00 01 00 00 8C A0 00 05   02 6E 73 C0 3F C0 39 00  .........ns.?.9.
+0060: 01 00 01 00 01 51 80 00   04 01 02 04 04 C0 58 00  .....Q........X.
+0070: 01 00 01 00 00 8C A0 00   04 7F 00 00 01           .............
+
+
+# DNS Request
+
+0000: B2 B9 01 00 00 01 00 00   00 00 00 00 01 31 01 34  .............1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01                                  a.....
+
+
+# DNS Response
+
+0000: B2 B9 85 80 00 01 00 01   00 01 00 01 01 31 01 34  .............1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01 C0 0C   00 0C 00 01 00 00 8C A0  a...............
+0030: 00 13 05 68 6F 73 74 31   07 64 6F 6D 61 69 6E 31  ...host1.domain1
+0040: 03 63 6F 6D 00 C0 0E 00   02 00 01 00 00 8C A0 00  .com............
+0050: 05 02 6E 73 C0 38 C0 51   00 01 00 01 00 00 8C A0  ..ns.8.Q........
+0060: 00 04 7F 00 00 01                                  ......
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry by naming
+ *          specific RRs by their type codes. Omit NAPTR for now because
+ *          bind doesn't support it.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetNumericRRs
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetNumericRRs extends GetRRsBase {
+
+    public GetNumericRRs() {
+        // set new test data instead of default value
+        setNumAttrs(new String[][] { { "1", "15", "13", "16" }, { "2", "6" },
+                { "28" }, { "5" }, { "33" }, { "12" }, });
+    }
+
+    public static void main(String[] args) throws Exception {
+        new GetNumericRRs().run(args);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry by naming
+     * specific RRs by their type codes. Omit NAPTR for now because
+     * bind doesn't support it.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        for (int i = 0; i < ROOT_LIMIT; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getNumAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+
+        switchToRootUrl();
+
+        for (int i = ROOT_LIMIT; i < getKeys().length; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getNumAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.dns	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,148 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetRRs.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetRRs application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 91 E0 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 91 E0 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
+# DNS Request
+
+0000: 07 37 01 00 00 01 00 00   00 00 00 00 07 64 6F 6D  .7...........dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01           ain1.com.....
+
+
+# DNS Response
+
+0000: 07 37 85 80 00 01 00 03   00 00 00 01 07 64 6F 6D  .7...........dom
+0010: 61 69 6E 31 03 63 6F 6D   00 00 FF 00 01 C0 0C 00  ain1.com........
+0020: 06 00 01 00 00 8C A0 00   26 02 6E 73 C0 0C 0A 70  ........&.ns...p
+0030: 6F 73 74 6D 61 73 74 65   72 C0 0C 00 00 00 01 00  ostmaster.......
+0040: 00 1C 20 00 00 0E 10 00   06 97 80 00 01 51 80 C0  .. ..........Q..
+0050: 0C 00 02 00 01 00 00 8C   A0 00 02 C0 29 C0 0C 00  ............)...
+0060: 10 00 01 00 00 8C A0 00   0C 0B 54 65 73 74 20 64  ..........Test d
+0070: 6F 6D 61 69 6E C0 29 00   01 00 01 00 00 8C A0 00  omain.).........
+0080: 04 7F 00 00 01                                     .....
+
+
+# DNS Request
+
+0000: FF 0E 01 00 00 01 00 00   00 00 00 00 04 69 70 76  .............ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01                                              ..
+
+
+# DNS Response
+
+0000: FF 0E 85 80 00 01 00 01   00 01 00 01 04 69 70 76  .............ipv
+0010: 36 07 64 6F 6D 61 69 6E   31 03 63 6F 6D 00 00 1C  6.domain1.com...
+0020: 00 01 C0 0C 00 1C 00 01   00 00 8C A0 00 10 00 0A  ................
+0030: 00 0B 00 0C 00 0D 00 0E   00 01 00 02 00 03 C0 11  ................
+0040: 00 02 00 01 00 00 8C A0   00 05 02 6E 73 C0 11 C0  ...........ns...
+0050: 4A 00 01 00 01 00 00 8C   A0 00 04 7F 00 00 01     J..............
+
+
+# DNS Request
+
+0000: 41 94 01 00 00 01 00 00   00 00 00 00 03 73 75 6E  A............sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01                                                 .
+
+
+# DNS Response
+
+0000: 41 94 85 80 00 01 00 01   00 01 00 01 03 73 75 6E  A............sun
+0010: 07 64 6F 6D 61 69 6E 31   03 63 6F 6D 00 00 05 00  .domain1.com....
+0020: 01 C0 0C 00 05 00 01 00   00 8C A0 00 08 05 68 6F  ..............ho
+0030: 73 74 31 C0 10 C0 10 00   02 00 01 00 00 8C A0 00  st1.............
+0040: 05 02 6E 73 C0 10 C0 41   00 01 00 01 00 00 8C A0  ..ns...A........
+0050: 00 04 7F 00 00 01                                  ......
+
+
+# DNS Request
+
+0000: 8B D6 01 00 00 01 00 00   00 00 00 00 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01                               om..!..
+
+
+# DNS Response
+
+0000: 8B D6 85 80 00 01 00 01   00 01 00 02 04 5F 66 74  ............._ft
+0010: 70 04 5F 54 63 70 07 64   6F 6D 61 69 6E 31 03 63  p._Tcp.domain1.c
+0020: 6F 6D 00 00 21 00 01 C0   0C 00 21 00 01 00 00 8C  om..!.....!.....
+0030: A0 00 19 00 01 00 00 00   15 05 68 6F 73 74 34 07  ..........host4.
+0040: 64 6F 6D 61 69 6E 31 03   63 6F 6D 00 C0 3F 00 02  domain1.com..?..
+0050: 00 01 00 00 8C A0 00 05   02 6E 73 C0 3F C0 39 00  .........ns.?.9.
+0060: 01 00 01 00 01 51 80 00   04 01 02 04 04 C0 58 00  .....Q........X.
+0070: 01 00 01 00 00 8C A0 00   04 7F 00 00 01           .............
+
+
+# DNS Request
+
+0000: D9 CF 01 00 00 01 00 00   00 00 00 00 01 31 01 34  .............1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01                                  a.....
+
+
+# DNS Response
+
+0000: D9 CF 85 80 00 01 00 01   00 01 00 01 01 31 01 34  .............1.4
+0010: 01 32 01 31 07 69 6E 2D   61 64 64 72 04 61 72 70  .2.1.in-addr.arp
+0020: 61 00 00 0C 00 01 C0 0C   00 0C 00 01 00 00 8C A0  a...............
+0030: 00 13 05 68 6F 73 74 31   07 64 6F 6D 61 69 6E 31  ...host1.domain1
+0040: 03 63 6F 6D 00 C0 0E 00   02 00 01 00 00 8C A0 00  .com............
+0050: 05 02 6E 73 C0 38 C0 51   00 01 00 01 00 00 8C A0  ..ns.8.Q........
+0060: 00 04 7F 00 00 01                                  ......
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8198882
+ * @summary Tests that we can get the attributes of a DNS entry by naming
+ *          specific RRs by name. Omit NAPTR for now because bind doesn't
+ *          support it.
+ * @modules java.base/sun.security.util
+ * @library ../lib/
+ * @run main GetRRs
+ */
+
+import javax.naming.directory.Attributes;
+
+public class GetRRs extends GetRRsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetRRs().run(args);
+    }
+
+    /*
+     * Tests that we can get the attributes of a DNS entry by naming
+     * specific RRs by name. Omit NAPTR for now because bind doesn't
+     * support it.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        for (int i = 0; i < ROOT_LIMIT; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+
+        switchToRootUrl();
+
+        for (int i = ROOT_LIMIT; i < getKeys().length; i++) {
+            Attributes retAttrs = getAttributes(getKeys()[i], getAttrs()[i]);
+            verifyAttributes(retAttrs, getAttrs()[i]);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRsBase.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
+public abstract class GetRRsBase extends DNSTestBase {
+    public static final int ROOT_LIMIT = 5; // point at which to use root ctx
+    private String[] keys;
+    private String[][] numAttrs;
+    private String[][] attrs;
+
+    public GetRRsBase() {
+        // set default test data
+        setKeys(new String[] { "host1", "", "ipv6", "sun", "_ftp._Tcp",
+                "1.4.2.1.in-addr.arpa", });
+        setNumAttrs(new String[][] { { "IN 1", "IN 15", "IN 13", "IN 16" },
+                { "IN 2", "IN 6" }, { "IN 28" }, { "IN 5" }, { "IN 33" },
+                { "IN 12" }, });
+        setAttrs(
+                new String[][] { { "A", "MX", "HINFO", "TXT" }, { "NS", "SOA" },
+                        { "AAAA" }, { "CNAME" }, { "SRV" }, { "PTR" }, });
+    }
+
+    public void initContext() throws Exception {
+        setContext(new InitialDirContext(env()));
+    }
+
+    public void switchToRootUrl() throws NamingException {
+        DNSTestUtils.cleanup(context());
+        env().put(Context.PROVIDER_URL, DNSTestUtils.getRootUrl(env()));
+        setContext(new InitialDirContext(env()));
+    }
+
+    public void verifyAttributes(Attributes attrs, String[] mandatory) {
+        DNSTestUtils.verifySchema(attrs, mandatory, new String[] {});
+    }
+
+    public Attributes getAttributes(String name, String[] attrIds)
+            throws Exception {
+        return context().getAttributes(name, attrIds);
+    }
+
+    public void setKeys(String[] keys) {
+        this.keys = keys;
+    }
+
+    public String[] getKeys() {
+        return keys;
+    }
+
+    public void setNumAttrs(String[][] numAttrs) {
+        this.numAttrs = numAttrs;
+    }
+
+    public String[][] getNumAttrs() {
+        return numAttrs;
+    }
+
+    public void setAttrs(String[][] attrs) {
+        this.attrs = attrs;
+    }
+
+    public String[][] getAttrs() {
+        return attrs;
+    }
+}
--- a/test/jdk/com/sun/jndi/dns/lib/DNSServer.java	Tue Jul 24 08:58:32 2018 -0700
+++ b/test/jdk/com/sun/jndi/dns/lib/DNSServer.java	Wed Jul 25 11:03:07 2018 +0800
@@ -26,6 +26,8 @@
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
 import java.nio.ByteBuffer;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -49,7 +51,7 @@
  * Typically, DNS protocol exchange is generated by DNSTracer who captures
  * communication messages between DNS application program and real DNS server
  */
-public class DNSServer implements Runnable {
+public class DNSServer extends Thread implements Server {
 
     public class Pair<F, S> {
         private F first;
@@ -87,19 +89,21 @@
     private boolean loop;
     private final List<Pair<byte[], byte[]>> cache = new ArrayList<>();
     private ByteBuffer reqBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE);
+    private volatile boolean isRunning;
 
-    public DNSServer(DatagramSocket socket, String filename) {
-        this(socket, filename, false);
+    public DNSServer(String filename) throws SocketException {
+        this(filename, false);
     }
 
-    public DNSServer(DatagramSocket socket, String filename, boolean loop) {
-        this.socket = socket;
+    public DNSServer(String filename, boolean loop) throws SocketException {
+        this.socket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
         this.filename = filename;
         this.loop = loop;
     }
 
     public void run() {
         try {
+            isRunning = true;
             System.out.println(
                     "DNSServer: Loading DNS cache data from : " + filename);
             loadCaptureFile(filename);
@@ -112,30 +116,25 @@
             int playbackIndex = 0;
 
             while (playbackIndex < cache.size()) {
-                DatagramPacket reqPacket = new DatagramPacket(reqBuffer.array(),
-                        reqBuffer.array().length);
-                socket.receive(reqPacket);
-
-                System.out.println(
-                        "DNSServer: received query message from " + reqPacket
-                                .getSocketAddress());
+                DatagramPacket reqPacket = receiveQuery();
 
                 if (!verifyRequestMsg(reqPacket, playbackIndex)) {
-                    throw new RuntimeException(
-                            "DNSServer: Error: Failed to verify DNS request. "
-                                    + "Not identical request message : \n"
-                                    + encoder.encodeBuffer(
-                                    Arrays.copyOf(reqPacket.getData(),
-                                            reqPacket.getLength())));
+                    if (playbackIndex > 0 && verifyRequestMsg(reqPacket,
+                            playbackIndex - 1)) {
+                        System.out.println(
+                                "DNSServer: received retry query, resend");
+                        playbackIndex--;
+                    } else {
+                        throw new RuntimeException(
+                                "DNSServer: Error: Failed to verify DNS request. "
+                                        + "Not identical request message : \n"
+                                        + encoder.encodeBuffer(
+                                        Arrays.copyOf(reqPacket.getData(),
+                                                reqPacket.getLength())));
+                    }
                 }
 
-                byte[] payload = generateResponsePayload(reqPacket,
-                        playbackIndex);
-                socket.send(new DatagramPacket(payload, payload.length,
-                        reqPacket.getSocketAddress()));
-                System.out.println(
-                        "DNSServer: send response message to " + reqPacket
-                                .getSocketAddress());
+                sendResponse(reqPacket, playbackIndex);
 
                 playbackIndex++;
                 if (loop && playbackIndex >= cache.size()) {
@@ -145,11 +144,54 @@
 
             System.out.println(
                     "DNSServer: Done for all cached messages playback");
+
+            System.out.println(
+                    "DNSServer: Still listening for possible retry query");
+            while (true) {
+                DatagramPacket reqPacket = receiveQuery();
+
+                // here we only handle the retry query for last one
+                if (!verifyRequestMsg(reqPacket, playbackIndex - 1)) {
+                    throw new RuntimeException(
+                            "DNSServer: Error: Failed to verify DNS request. "
+                                    + "Not identical request message : \n"
+                                    + encoder.encodeBuffer(
+                                    Arrays.copyOf(reqPacket.getData(),
+                                            reqPacket.getLength())));
+                }
+
+                sendResponse(reqPacket, playbackIndex - 1);
+            }
         } catch (Exception e) {
-            System.err.println("DNSServer: Error: " + e);
+            if (isRunning) {
+                System.err.println("DNSServer: Error: " + e);
+                e.printStackTrace();
+            } else {
+                System.out.println("DNSServer: Exit");
+            }
         }
     }
 
+    private DatagramPacket receiveQuery() throws IOException {
+        DatagramPacket reqPacket = new DatagramPacket(reqBuffer.array(),
+                reqBuffer.array().length);
+        socket.receive(reqPacket);
+
+        System.out.println("DNSServer: received query message from " + reqPacket
+                .getSocketAddress());
+
+        return reqPacket;
+    }
+
+    private void sendResponse(DatagramPacket reqPacket, int playbackIndex)
+            throws IOException {
+        byte[] payload = generateResponsePayload(reqPacket, playbackIndex);
+        socket.send(new DatagramPacket(payload, payload.length,
+                reqPacket.getSocketAddress()));
+        System.out.println("DNSServer: send response message to " + reqPacket
+                .getSocketAddress());
+    }
+
     /*
      * Load a capture file containing an DNS protocol exchange in the
      * hexadecimal dump format emitted by sun.misc.HexDumpEncoder:
@@ -299,4 +341,23 @@
         }
         return -1;
     }
+
+    @Override public void stopServer() {
+        isRunning = false;
+        if (socket != null) {
+            try {
+                socket.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+
+    @Override public int getPort() {
+        if (socket != null) {
+            return socket.getLocalPort();
+        } else {
+            return -1;
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/lib/DNSTestBase.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.directory.DirContext;
+import java.util.Hashtable;
+
+/**
+ * The test base class for DNS related tests, extends TestBase.
+ *
+ * This class override some methods of supper class to provide DNS tests shared
+ * base logic.
+ *
+ * @see TestBase
+ */
+public abstract class DNSTestBase extends TestBase {
+    private Hashtable<Object, Object> env;
+    private DirContext ctx;
+    private boolean localServer;
+
+    public DNSTestBase() {
+        // set default, we will run with local server playback by default
+        setLocalServer(true);
+    }
+
+    @Override public void initTest(String[] args) {
+        // init env which will used later to initial dir context
+        env = DNSTestUtils
+                .initEnv(localServer, this.getClass().getName(), args);
+    }
+
+    @Override public void cleanupTest() {
+        // cleanup dir context
+        DNSTestUtils.cleanup(ctx);
+        // stop local server if there is
+        Server server = (Server) env.get(DNSTestUtils.TEST_DNS_SERVER_THREAD);
+        if (server != null) {
+            server.stopServer();
+        }
+    }
+
+    public Hashtable<Object, Object> env() {
+        if (env == null) {
+            throw new RuntimeException("Test had not been initialized");
+        }
+
+        return env;
+    }
+
+    public DirContext context() {
+        if (ctx == null) {
+            throw new RuntimeException("Context had not been initialized");
+        }
+
+        return ctx;
+    }
+
+    public void setContext(DirContext context) {
+        ctx = context;
+    }
+
+    public void setLocalServer(boolean isRequired) {
+        this.localServer = isRequired;
+    }
+}
--- a/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java	Tue Jul 24 08:58:32 2018 -0700
+++ b/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java	Wed Jul 25 11:03:07 2018 +0800
@@ -25,12 +25,17 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import java.io.PrintStream;
-import java.net.DatagramSocket;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Hashtable;
 
+/**
+ * This is utility class for DNS test, it contains many helper methods to
+ * support test construction.
+ *
+ * For basic test sequence see TestBase and DNSTestBase.
+ */
 public class DNSTestUtils {
     public static final String TEST_DNS_SERVER_THREAD = "test.dns.server.thread";
     public static final String TEST_DNS_ROOT_URL = "test.dns.root.url";
@@ -38,9 +43,14 @@
 
     protected static boolean debug = true;
 
-    /*
-     * Check that attrs contains the mandatory attributes and the right
-     * objectclass attribute
+    /**
+     * Check that attributes contains the mandatory attributes and the right
+     * objectclass attribute.
+     *
+     * @param attrs     given attributes to verify
+     * @param mandatory given mandatory for verification
+     * @param optional  given optional for verification
+     * @return <tt>true</tt>  if check ok
      */
     public static boolean checkSchema(Attributes attrs, String[] mandatory,
             String[] optional) {
@@ -70,10 +80,18 @@
         return true;
     }
 
-    /*
-     * Process command line arguments and init env
+    /**
+     * Process command line arguments and init env.
+     * This method will prepare default environments which to be used to initial
+     * DirContext.
+     *
+     * @param localServer <tt>true</tt> if this test will run against with local
+     *                    server against dump message playback
+     * @param testname    test case name to identify playback file
+     * @param args        additional arguments for env preparation
+     * @return prepared env which will be used later to initial DirContext
      */
-    public static Hashtable<Object, Object> initEnv(DatagramSocket socket,
+    public static Hashtable<Object, Object> initEnv(boolean localServer,
             String testname, String[] args) {
 
         Hashtable<Object, Object> env = new Hashtable<>();
@@ -89,14 +107,12 @@
 
         boolean traceEnable = false;
         boolean loopPlayback = false;
-        for (int i = 0; i < args.length; i++) {
-            if ((args[i].equals("-D")) && (args.length > i + 1)) {
-                extractProperty(args[++i], env);
-            } else if (args[i].startsWith("-D")) {
-                extractProperty(args[i].substring(2), env);
-            } else if (args[i].equalsIgnoreCase("-trace")) {
+        for (String arg : args) {
+            if (arg.startsWith("-D")) {
+                extractProperty(arg.substring(2), env);
+            } else if (arg.equalsIgnoreCase("-trace")) {
                 traceEnable = true;
-            } else if (args[i].equalsIgnoreCase("-loop")) {
+            } else if (arg.equalsIgnoreCase("-loop")) {
                 loopPlayback = true;
             }
         }
@@ -111,23 +127,25 @@
             env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN"));
         }
 
-        Runnable inst = null;
+        Thread inst = null;
         if (traceEnable) {
-            inst = createDNSTracer(socket, testname, env);
+            // if trace is enabled, create DNSTracer to dump those message
+            inst = createDNSTracer(testname, env);
         } else {
-            if (socket != null) {
-                inst = createDNSServer(socket, testname, loopPlayback);
+            if (localServer) {
+                // if use local server, create local DNSServer for playback
+                inst = createDNSServer(testname, loopPlayback);
             } else {
                 // for tests which run against remote server
                 // or no server required
-                debug("Skip local DNS Server creation "
-                        + "since DatagramSocket is null");
+                debug("Skip local DNS Server creation ");
             }
         }
 
         if (inst != null) {
-            env.put(TEST_DNS_SERVER_THREAD, startServer(inst));
-            String url = "dns://localhost:" + socket.getLocalPort();
+            inst.start();
+            env.put(TEST_DNS_SERVER_THREAD, inst);
+            String url = "dns://localhost:" + ((Server) inst).getPort();
 
             env.put(TEST_DNS_ROOT_URL, url);
             env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN"));
@@ -136,8 +154,10 @@
         return env;
     }
 
-    /*
-     * Clean-up the directory context.
+    /**
+     * Clean-up the given directory context.
+     *
+     * @param ctx given context object
      */
     public static void cleanup(Context ctx) {
         if (ctx != null) {
@@ -162,17 +182,19 @@
         }
     }
 
-    public static DNSTracer createDNSTracer(DatagramSocket socket,
-            String testname, Hashtable<Object, Object> env) {
-        if (socket == null) {
-            throw new RuntimeException("Error: failed to create DNSTracer "
-                    + "since DatagramSocket is null");
-        }
-
+    /**
+     * Return new created DNS tracer.
+     *
+     * @param testname test case name to identify playback file
+     * @param env      given env for initialization
+     * @return created DNS tracer
+     * @see DNSTracer
+     */
+    public static DNSTracer createDNSTracer(String testname,
+            Hashtable<Object, Object> env) {
         try {
             PrintStream outStream = new PrintStream(getCaptureFile(testname));
-            return new DNSTracer(socket, outStream,
-                    (String) env.get("DNS_SERVER"),
+            return new DNSTracer(outStream, (String) env.get("DNS_SERVER"),
                     Integer.parseInt((String) env.get("DNS_PORT")));
         } catch (Exception e) {
             throw new RuntimeException(
@@ -180,16 +202,24 @@
         }
     }
 
-    public static DNSServer createDNSServer(DatagramSocket socket,
-            String testname, boolean loop) {
-        if (socket == null) {
-            throw new RuntimeException("Error: failed to create DNSServer "
-                    + "since DatagramSocket is null");
-        }
-
+    /**
+     * Return new created local DNS Server.
+     *
+     * @param testname test case name to identify playback file
+     * @param loop     <tt>true</tt> if DNS server required playback message in loop
+     * @return created local DNS Server
+     * @see DNSServer
+     */
+    public static DNSServer createDNSServer(String testname, boolean loop) {
         String path = getCaptureFile(testname);
         if (Files.exists(Paths.get(path))) {
-            return new DNSServer(socket, path, loop);
+            try {
+                return new DNSServer(path, loop);
+            } catch (Exception e) {
+                throw new RuntimeException(
+                        "Error: failed to create DNSServer : " + e.getMessage(),
+                        e);
+            }
         } else {
             throw new RuntimeException(
                     "Error: failed to create DNSServer, not found dns "
@@ -197,22 +227,32 @@
         }
     }
 
-    public static Thread startServer(Runnable runnable) {
-        Thread thread = new Thread(runnable);
-        thread.start();
-        return thread;
-    }
-
+    /**
+     * Return dns message capture file path.
+     *
+     * @param testname test case name to identify playback file
+     * @return capture file path
+     */
     public static String getCaptureFile(String testname) {
         return Paths.get(System.getProperty("test.src"))
                 .resolve(testname + ".dns").toString();
     }
 
+    /**
+     * Enable hosts file.
+     *
+     * @param hostsFile given hosts file
+     */
     public static void enableHostsFile(String hostsFile) {
         System.out.println("Enable jdk.net.hosts.file = " + hostsFile);
         System.setProperty("jdk.net.hosts.file", hostsFile);
     }
 
+    /**
+     * Enable hosts file by given searching depth.
+     *
+     * @param depth given depth for searching hosts file
+     */
     public static void enableHostsFile(int depth) {
         Path path = Paths.get(System.getProperty("test.src", "."))
                 .toAbsolutePath();
@@ -230,12 +270,25 @@
         }
     }
 
+    /**
+     * Print given object if debug enabled.
+     *
+     * @param object given object to print
+     */
     public static void debug(Object object) {
         if (debug) {
             System.out.println(object);
         }
     }
 
+    /**
+     * Verify attributes contains the mandatory attributes and the right
+     * objectclass attribute, will throw RuntimeException if verify failed.
+     *
+     * @param attrs     given attributes to verify
+     * @param mandatory given mandatory for verification
+     * @param optional  given optional for verification
+     */
     public static void verifySchema(Attributes attrs, String[] mandatory,
             String[] optional) {
         debug(attrs);
@@ -243,4 +296,32 @@
             throw new RuntimeException("Check schema failed.");
         }
     }
+
+    /**
+     * Return dns root url.
+     *
+     * @param env given env
+     * @return dns root url
+     */
+    public static String getRootUrl(Hashtable<Object, Object> env) {
+        return (String) env.get(TEST_DNS_ROOT_URL);
+    }
+
+    /**
+     * Assemble a fully-qualified domain name from the base component and the
+     * domain name.
+     *
+     * @param base    given base component
+     * @param env     given env
+     * @param primary <tt>true</tt> if primary domain
+     * @return assembled fully-qualified domain name
+     */
+    public static String buildFqdn(String base, Hashtable<Object, Object> env,
+            boolean primary) {
+        String domain = (String) (primary ?
+                env.get("DNS_DOMAIN") :
+                env.get("FOREIGN_DOMAIN"));
+
+        return base + "." + domain;
+    }
 }
--- a/test/jdk/com/sun/jndi/dns/lib/DNSTracer.java	Tue Jul 24 08:58:32 2018 -0700
+++ b/test/jdk/com/sun/jndi/dns/lib/DNSTracer.java	Wed Jul 25 11:03:07 2018 +0800
@@ -26,6 +26,7 @@
 import java.io.PrintStream;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.net.SocketException;
@@ -46,7 +47,7 @@
  *
  * Typically, the capture file data will be used by DNSServer for playback
  */
-public class DNSTracer implements Runnable {
+public class DNSTracer extends Thread implements Server {
     public static final int DNS_DEFAULT_PORT = 53;
     public static final int DNS_PACKET_SIZE = 512;
     static HexDumpEncoder encoder = new HexDumpEncoder();
@@ -56,28 +57,30 @@
     private ByteBuffer reqBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE);
     private ByteBuffer resBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE);
     private PrintStream out = null;
+    private volatile boolean isRunning;
 
-    public DNSTracer(DatagramSocket socket, String dnsHostname) {
-        this(socket, dnsHostname, DNS_DEFAULT_PORT);
+    public DNSTracer(String dnsHostname) throws SocketException {
+        this(dnsHostname, DNS_DEFAULT_PORT);
     }
 
-    public DNSTracer(DatagramSocket socket, PrintStream outStream,
-            String dnsHostname) {
-        this(socket, outStream, dnsHostname, DNS_DEFAULT_PORT);
+    public DNSTracer(PrintStream outStream, String dnsHostname)
+            throws SocketException {
+        this(outStream, dnsHostname, DNS_DEFAULT_PORT);
     }
 
-    public DNSTracer(DatagramSocket socket, String dnsHostname, int dnsPort) {
-        this(socket, System.out, dnsHostname, dnsPort);
+    public DNSTracer(String dnsHostname, int dnsPort) throws SocketException {
+        this(System.out, dnsHostname, dnsPort);
     }
 
-    public DNSTracer(DatagramSocket socket, PrintStream outStream,
-            String dnsHostname, int dnsPort) {
-        inSocket = socket;
+    public DNSTracer(PrintStream outStream, String dnsHostname, int dnsPort)
+            throws SocketException {
+        inSocket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
         out = outStream;
         dnsServerAddress = new InetSocketAddress(dnsHostname, dnsPort);
     }
 
     public void run() {
+        isRunning = true;
         System.out.println(
                 "DNSTracer: listening on port " + inSocket.getLocalPort());
 
@@ -116,7 +119,7 @@
                         resPacket.getLength(), reqPacket.getSocketAddress()));
             }
         } catch (SocketException se) {
-            if (inSocket.isClosed()) {
+            if (!isRunning) {
                 out.flush();
                 System.out.println("DNSTracer: Exit");
             } else {
@@ -127,4 +130,22 @@
         }
     }
 
+    @Override public void stopServer() {
+        isRunning = false;
+        if (inSocket != null) {
+            try {
+                inSocket.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+
+    @Override public int getPort() {
+        if (inSocket != null) {
+            return inSocket.getLocalPort();
+        } else {
+            return -1;
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/lib/Server.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * The interface of Server.
+ */
+public interface Server {
+    /**
+     * Stop server.
+     */
+    void stopServer();
+
+    /**
+     * Return local port which server is listening.
+     *
+     * @return port which server is listening
+     */
+    int getPort();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/lib/TestBase.java	Wed Jul 25 11:03:07 2018 +0800
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * The test base class for JNDI related tests.
+ *
+ * run() will be the entry to launch whole tests, base test sequence is
+ * initRes(), initTest(), setupTest() and launch().
+ *
+ * launch() will call real test logic runTest() which required to be implemented
+ * in test class.
+ *
+ * exception handling logic should be placed in handleException().
+ *
+ * cleanup related should be placed in cleanupTest which been called in finally
+ * block.
+ */
+public abstract class TestBase {
+
+    /**
+     * The entry to the test.
+     *
+     * @param args given input arguments
+     * @throws Exception if any exception
+     */
+    public void run(String[] args) throws Exception {
+        initRes();
+        initTest(args);
+        setupTest();
+        launch();
+    }
+
+    /**
+     * Initial local resources, such as socket.
+     *
+     * @throws Exception if any exception
+     */
+    public void initRes() throws Exception {
+    }
+
+    /**
+     * Initial test with given arguments.
+     *
+     * @param args given arguments
+     */
+    public void initTest(String[] args) {
+    }
+
+    /**
+     * Setup test.
+     */
+    public void setupTest() {
+    }
+
+    /**
+     * Launch test.
+     *
+     * @throws Exception if any exception
+     */
+    public void launch() throws Exception {
+        try {
+            runTest();
+        } catch (Exception e) {
+            if (!handleException(e)) {
+                throw e;
+            }
+        } finally {
+            cleanupTest();
+        }
+    }
+
+    /**
+     * The real test logic to run, this required to be implemented in test class.
+     *
+     * @throws Exception if any exception
+     */
+    public abstract void runTest() throws Exception;
+
+    /**
+     * Handle test exception.
+     *
+     * @param e exception which been thrown during test runTest()
+     * @return <tt>true</tt> if given exception is expected
+     */
+    public boolean handleException(Exception e) {
+        return false;
+    }
+
+    /**
+     * Cleanup test.
+     */
+    public abstract void cleanupTest();
+}