Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java
38867 views
/*1* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4333920 499437226* @run main ChunkedEncodingWithProgressMonitorTest27* @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem28*/2930import java.net.*;31import java.util.BitSet;32import sun.net.ProgressMeteringPolicy;33import sun.net.ProgressMonitor;34import sun.net.ProgressListener;35import sun.net.ProgressEvent;3637public class ChunkedEncodingWithProgressMonitorTest {38public static void main (String[] args) throws Exception {39ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy());40ProgressListener listener = new MyProgressListener();41ProgressMonitor.getDefault().addProgressListener(listener);42ChunkedEncodingTest.test();43ProgressMonitor.getDefault().removeProgressListener(listener);4445if (flag.cardinality() != 3) {46throw new RuntimeException("All three methods in ProgressListener"+47" should be called. Yet the number of"+48" methods actually called are "+49flag.cardinality());50}51}5253static class MyProgressMeteringPolicy implements ProgressMeteringPolicy {54/**55* Return true if metering should be turned on for a particular network input stream.56*/57public boolean shouldMeterInput(URL url, String method) {58return true;59}6061/**62* Return update notification threshold.63*/64public int getProgressUpdateThreshold() {65return 8192;66}67}6869static BitSet flag = new BitSet(3);7071static class MyProgressListener implements ProgressListener {72/**73* Start progress.74*/75public void progressStart(ProgressEvent evt) {76System.out.println("start: received progressevent "+evt);77if (flag.nextSetBit(0) == -1)78flag.set(0);79}8081/**82* Update progress.83*/84public void progressUpdate(ProgressEvent evt) {85System.out.println("update: received progressevent "+evt);86if (flag.nextSetBit(1) == -1)87flag.set(1);88}8990/**91* Finish progress.92*/93public void progressFinish(ProgressEvent evt) {94System.out.println("finish: received progressevent "+evt);95if (flag.nextSetBit(2) == -1)96flag.set(2);97}98}99}100101102