author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6115 | 7c523cf2bc8a |
child 13788 | 3f38e525f30a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 4333920 4994372 |
|
27 |
* @library ../../../../../sun/net/www/httptest/ |
|
28 |
* @build HttpCallback HttpServer ClosedChannelList HttpTransaction |
|
29 |
* @run main ChunkedEncodingWithProgressMonitorTest |
|
30 |
* @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem |
|
31 |
*/ |
|
32 |
||
33 |
import java.net.*; |
|
34 |
import java.util.BitSet; |
|
35 |
import sun.net.ProgressMeteringPolicy; |
|
36 |
import sun.net.ProgressMonitor; |
|
37 |
import sun.net.ProgressListener; |
|
38 |
import sun.net.ProgressEvent; |
|
39 |
||
40 |
public class ChunkedEncodingWithProgressMonitorTest { |
|
41 |
public static void main (String[] args) throws Exception { |
|
42 |
ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy()); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
43 |
ProgressListener listener = new MyProgressListener(); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
44 |
ProgressMonitor.getDefault().addProgressListener(listener); |
2 | 45 |
ChunkedEncodingTest.test(); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
46 |
ProgressMonitor.getDefault().removeProgressListener(listener); |
2 | 47 |
|
48 |
if (flag.cardinality() != 3) { |
|
49 |
throw new RuntimeException("All three methods in ProgressListener"+ |
|
50 |
" should be called. Yet the number of"+ |
|
51 |
" methods actually called are "+ |
|
52 |
flag.cardinality()); |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
static class MyProgressMeteringPolicy implements ProgressMeteringPolicy { |
|
57 |
/** |
|
58 |
* Return true if metering should be turned on for a particular network input stream. |
|
59 |
*/ |
|
60 |
public boolean shouldMeterInput(URL url, String method) { |
|
61 |
return true; |
|
62 |
} |
|
63 |
||
64 |
/** |
|
65 |
* Return update notification threshold. |
|
66 |
*/ |
|
67 |
public int getProgressUpdateThreshold() { |
|
68 |
return 8192; |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
static BitSet flag = new BitSet(3); |
|
73 |
||
74 |
static class MyProgressListener implements ProgressListener { |
|
75 |
/** |
|
76 |
* Start progress. |
|
77 |
*/ |
|
78 |
public void progressStart(ProgressEvent evt) { |
|
79 |
System.out.println("start: received progressevent "+evt); |
|
80 |
if (flag.nextSetBit(0) == -1) |
|
81 |
flag.set(0); |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Update progress. |
|
86 |
*/ |
|
87 |
public void progressUpdate(ProgressEvent evt) { |
|
88 |
System.out.println("update: received progressevent "+evt); |
|
89 |
if (flag.nextSetBit(1) == -1) |
|
90 |
flag.set(1); |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Finish progress. |
|
95 |
*/ |
|
96 |
public void progressFinish(ProgressEvent evt) { |
|
97 |
System.out.println("finish: received progressevent "+evt); |
|
98 |
if (flag.nextSetBit(2) == -1) |
|
99 |
flag.set(2); |
|
100 |
} |
|
101 |
} |
|
102 |
} |