Skip to content

Commit

Permalink
Bulletproof AbstractProxyServlet#destory() to make it easier to write
Browse files Browse the repository at this point in the history
unit tests for custom subclasses of AbstractProxyServlet
  • Loading branch information
garydgregory committed Jun 21, 2023
1 parent 9041527 commit f4986d3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ public void destroy()
{
try
{
_client.stop();
if (_client != null)
_client.stop();
}
catch (Exception x)
{
if (_log.isDebugEnabled())
if (_log == null)
x.printStackTrace();
else if (_log.isDebugEnabled())
_log.debug("Failed to stop client", x);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.proxy;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.client.api.Response.CompleteListener;
import org.junit.jupiter.api.Test;

public class AbstractProxyServletTest
{

@Test
public void testNewDestroy() throws Exception
{
new AbstractProxyServlet()
{
private static final long serialVersionUID = 1L;

@Override
protected CompleteListener newProxyResponseListener(HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
{
return null;
}
}.destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,18 @@ private void startClient() throws Exception
@AfterEach
public void dispose() throws Exception
{
client.stop();
proxy.stop();
server.stop();
if (client != null)
client.stop();
if (proxy != null)
proxy.stop();
if (server != null)
server.stop();
}

@Test
public void testNewDestroy() throws Exception
{
new AsyncMiddleManServlet().destroy();
}

@Test
Expand Down

0 comments on commit f4986d3

Please sign in to comment.