Skip to content

Commit

Permalink
Merge pull request Netflix#787 from motortalk/reject-stream-servlet-r…
Browse files Browse the repository at this point in the history
…equest-when-destroyed

HystrixMetricsStreamServlet rejects requests after servlet shutdown (fixes Netflix#786)
  • Loading branch information
mattrjacobs committed May 5, 2015
2 parents dc06181 + 5c2375a commit 9002320
Show file tree
Hide file tree
Showing 3 changed files with 51 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,45 @@
/**
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 9002320

Please sign in to comment.