test/jdk/java/net/URLConnection/B5052093.java
author aeubanks
Tue, 16 Apr 2019 13:06:23 -0700
changeset 54770 62b6e7587b1f
parent 54681 edd709e64ea1
child 58365 73950479184b
permissions -rw-r--r--
8220673: Add test library support for determining platform IP support Reviewed-by: dfuchs, chegar Contributed-by: aeubanks@google.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54681
edd709e64ea1 8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 5052093
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14342
diff changeset
    27
 * @modules java.base/sun.net.www java.base/sun.net.www.protocol.file
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @library ../../../sun/net/www/httptest/
13788
3f38e525f30a 6354758: rename old test HttpServer classes
chegar
parents: 7668
diff changeset
    29
 * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main B5052093
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @summary URLConnection doesn't support large files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.net.www.protocol.file.FileURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class B5052093 implements HttpCallback {
13788
3f38e525f30a 6354758: rename old test HttpServer classes
chegar
parents: 7668
diff changeset
    38
    private static TestHttpServer server;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static long testSize = ((long) (Integer.MAX_VALUE)) + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public static class LargeFile extends File {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        public LargeFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            super("/dev/zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        public long length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            return testSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static class LargeFileURLConnection extends FileURLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        public LargeFileURLConnection(LargeFile f) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                super(new URL("file:///dev/zero"), f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public void request(HttpTransaction req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            req.setResponseHeader("content-length", Long.toString(testSize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            req.sendResponse(200, "OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static void main(String[] args) throws Exception {
54681
edd709e64ea1 8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents: 47216
diff changeset
    67
        InetAddress loopback = InetAddress.getLoopbackAddress();
edd709e64ea1 8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents: 47216
diff changeset
    68
        server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0);
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    69
        try {
54681
edd709e64ea1 8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents: 47216
diff changeset
    70
            URL url = new URL("http://" + server.getAuthority() + "/foo");
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    71
            URLConnection conn = url.openConnection();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    72
            int i = conn.getContentLength();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    73
            long l = conn.getContentLengthLong();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    74
            if (i != -1 || l != testSize) {
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    75
                System.out.println("conn.getContentLength = " + i);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    76
                System.out.println("conn.getContentLengthLong = " + l);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    77
                System.out.println("testSize = " + testSize);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    78
                throw new RuntimeException("Wrong content-length from http");
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    79
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    81
            URLConnection fu = new LargeFileURLConnection(new LargeFile());
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    82
            i = fu.getContentLength();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    83
            l = fu.getContentLengthLong();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    84
            if (i != -1 || l != testSize) {
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    85
                System.out.println("fu.getContentLength = " + i);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    86
                System.out.println("fu.getContentLengthLong = " + l);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    87
                System.out.println("testSize = " + testSize);
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    88
                throw new RuntimeException("Wrong content-length from file");
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    89
            }
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    90
        } finally {
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    91
            server.terminate();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
    92
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}