Skip to content

Commit

Permalink
Reject requests after servlet shutdown (fixes Netflix#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasse.voss committed May 5, 2015
1 parent dc06181 commit bc3e75f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions hystrix-contrib/hystrix-metrics-event-stream/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.5.2'
provided 'javax.servlet:servlet-api:2.5'
testCompile 'junit:junit-dep:4.10'
testCompile 'org.mockito:mockito-all:1.9.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public void init() throws ServletException {
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
handleRequest(request, response);
if (isDestroyed) {
response.sendError(503, "Service has been shut down.");
} else {
handleRequest(request, response);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.netflix.hystrix.contrib.metrics.eventstream;

import org.junit.Test;
import org.mockito.Mockito;

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

import java.io.IOException;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class HystrixMetricsStreamServletUnitTest {

@Test
public void shutdownServletShouldRejectRequests() throws ServletException, IOException {

final HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
servlet.shutdown();

final HttpServletResponse response = mock(HttpServletResponse.class);
servlet.doGet(mock(HttpServletRequest.class), response);

verify(response).sendError(503, "Service has been shut down.");

}

}

0 comments on commit bc3e75f

Please sign in to comment.