Changeset 10302 in josm for trunk


Ignore:
Timestamp:
2016-05-30T09:24:08+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #12583 - fix unit tests by adding a new mode to HttpClient. Don't know if it's the best way to do it...

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/ProgressOutputStream.java

    r9669 r10302  
    1919    private final StreamProgressUpdater updater;
    2020    private final OutputStream out;
     21    private final boolean finishOnClose;
    2122
    2223    /**
     
    2627     * @param size the total size which will be sent
    2728     * @param progressMonitor the monitor to report to
     29     * @param finishOnClose whether to call {@link ProgressMonitor#finishTask} when this stream is closed
     30     * @since 10302
    2831     */
    29     public ProgressOutputStream(OutputStream out, long size, ProgressMonitor progressMonitor) {
    30         if (progressMonitor == null) {
    31             progressMonitor = NullProgressMonitor.INSTANCE;
    32         }
    33         this.updater = new StreamProgressUpdater(size, progressMonitor, tr("Uploading data ..."));
     32    public ProgressOutputStream(OutputStream out, long size, ProgressMonitor progressMonitor, boolean finishOnClose) {
     33        this.updater = new StreamProgressUpdater(size,
     34                progressMonitor != null ? progressMonitor : NullProgressMonitor.INSTANCE, tr("Uploading data ..."));
    3435        this.out = out;
     36        this.finishOnClose = finishOnClose;
    3537    }
    3638
     
    5254            out.close();
    5355        } finally {
    54             updater.finishTask();
     56            if (finishOnClose) {
     57                updater.finishTask();
     58            }
    5559        }
    5660    }
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r10300 r10302  
    5252    private HttpURLConnection connection; // to allow disconnecting before `response` is set
    5353    private Response response;
     54    private boolean finishOnCloseOutput = true;
    5455
    5556    static {
     
    111112            connection.setDoOutput(true);
    112113            try (OutputStream out = new BufferedOutputStream(
    113                     new ProgressOutputStream(connection.getOutputStream(), requestBody.length, progressMonitor))) {
     114                    new ProgressOutputStream(connection.getOutputStream(), requestBody.length, progressMonitor, finishOnCloseOutput))) {
    114115                out.write(requestBody);
    115116            }
     
    598599    }
    599600
     601    /**
     602     * Sets whether the progress monitor task will be finished when the output stream is closed. This is {@code true} by default.
     603     * @param finishOnCloseOutput whether the progress monitor task will be finished when the output stream is closed
     604     * @return {@code this}
     605     * @since 10302
     606     */
     607    public HttpClient setFinishOnCloseOutput(boolean finishOnCloseOutput) {
     608        this.finishOnCloseOutput = finishOnCloseOutput;
     609        return this;
     610    }
     611
    600612    private static boolean isRedirect(final int statusCode) {
    601613        switch (statusCode) {
  • trunk/test/config/functional-josm.home

    • Property svn:ignore
      •  

        old new  
        33preferences.xml_tmp
        44preferences.xml
         5validator
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r9807 r10302  
    101101                .setHeader("Content-Type", "text/plain")
    102102                .setRequestBody(text.getBytes(StandardCharsets.UTF_8))
     103                .setFinishOnCloseOutput(false) // to fix #12583, not sure if it's the best way to do it
    103104                .connect(progress);
    104105        assertThat(response.getResponseCode(), is(200));
     
    114115                .setHeader("Content-Type", "text/plain")
    115116                .setRequestBody("".getBytes(StandardCharsets.UTF_8))
     117                .setFinishOnCloseOutput(false) // to fix #12583, not sure if it's the best way to do it
    116118                .connect(progress);
    117119        assertThat(response.getResponseCode(), is(200));
Note: See TracChangeset for help on using the changeset viewer.