Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge fix to BufferedResponseHandlerTest to 9.4.x #6456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected interface BufferedInterceptor extends HttpOutput.Interceptor
{
}

private class ArrayBufferedInterceptor implements BufferedInterceptor
class ArrayBufferedInterceptor implements BufferedInterceptor
{
private final Interceptor _next;
private final HttpChannel _channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected BufferedInterceptor newBufferedInterceptor(HttpChannel httpChannel, In
return new FileBufferedInterceptor(httpChannel, interceptor);
}

private class FileBufferedInterceptor implements BufferedResponseHandler.BufferedInterceptor
class FileBufferedInterceptor implements BufferedResponseHandler.BufferedInterceptor
{
private static final int MAX_MAPPED_BUFFER_SIZE = Integer.MAX_VALUE / 2;

Expand Down Expand Up @@ -111,7 +111,7 @@ public void resetBuffer()
BufferedInterceptor.super.resetBuffer();
}

private void dispose()
protected void dispose()
{
IO.close(_fileOutputStream);
_fileOutputStream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ========================================================================
//

package org.eclipse.jetty.server;
package org.eclipse.jetty.server.handler;

import java.io.File;
import java.io.IOException;
Expand All @@ -30,6 +30,7 @@
import java.time.Duration;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletException;
Expand All @@ -39,9 +40,14 @@

import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.FileBufferedResponseHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.Callback;
Expand All @@ -63,6 +69,7 @@ public class FileBufferedResponseHandlerTest
{
private static final Logger LOG = Log.getLogger(FileBufferedResponseHandlerTest.class);

private final CountDownLatch _disposeLatch = new CountDownLatch(1);
private Server _server;
private LocalConnector _localConnector;
private ServerConnector _serverConnector;
Expand All @@ -86,7 +93,22 @@ public void before() throws Exception
_serverConnector = new ServerConnector(_server, new HttpConnectionFactory(config));
_server.addConnector(_serverConnector);

_bufferedHandler = new FileBufferedResponseHandler();
_bufferedHandler = new FileBufferedResponseHandler()
{
@Override
protected BufferedInterceptor newBufferedInterceptor(HttpChannel httpChannel, HttpOutput.Interceptor interceptor)
{
return new FileBufferedInterceptor(httpChannel, interceptor)
{
@Override
protected void dispose()
{
super.dispose();
_disposeLatch.countDown();
}
};
}
};
_bufferedHandler.setTempDir(_testDir);
_bufferedHandler.getPathIncludeExclude().include("/include/*");
_bufferedHandler.getPathIncludeExclude().exclude("*.exclude");
Expand Down Expand Up @@ -157,6 +179,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(responseContent, containsString("Committed: false"));
assertThat(responseContent, containsString("NumFiles: 1"));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -249,6 +273,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(responseContent, containsString("NumFilesBeforeFlush: 0"));
assertThat(responseContent, containsString("Committed: false"));
assertThat(responseContent, containsString("NumFiles: 1"));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -279,6 +305,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(responseContent, not(containsString("writtenAfterClose")));
assertThat(responseContent, containsString("NumFiles: 1"));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -339,6 +367,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
// The flush should not create the file unless there is content to write.
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(responseContent, containsString("NumFiles: 0"));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -378,6 +408,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(responseContent, containsString("NumFilesBeforeReset: 1"));
assertThat(responseContent, containsString("NumFilesAfterReset: 0"));
assertThat(responseContent, containsString("NumFilesAfterWrite: 1"));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -451,6 +483,8 @@ public boolean content(ByteBuffer ref)
assertThat(response.get("NumFiles"), is("1"));
assertThat(response.get("FileSize"), is(Long.toString(fileSize)));
assertThat(received.get(), is(fileSize));

assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -531,6 +565,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(error.getMessage(), containsString("intentionally throwing from interceptor"));

// All files were deleted.
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down Expand Up @@ -579,6 +614,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
assertThat(error, instanceOf(NoSuchFileException.class));

// No files were created.
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}

Expand Down