blob: 2fc3411251710a7cff290bb7cfc450bfe522c3a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.server;
import com.yahoo.container.handler.threadpool.ContainerThreadPool;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.jdisc.handler.OverloadException;
import com.yahoo.metrics.simple.MetricReceiver;
import org.junit.Test;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import static com.yahoo.vespa.http.server.FeedHandlerV3Test.createRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author bjorncs
*/
public class FeedHandlerTest {
@Test
public void response_has_status_code_429_when_throttling() {
FeedHandler handler = new FeedHandler(
new RejectingContainerThreadpool(),
new CollectingMetric(),
new DocumentTypeManager(new DocumentmanagerConfig.Builder().build()),
null /* session cache */,
MetricReceiver.nullImplementation);
var responseHandler = new RequestHandlerTestDriver.MockResponseHandler();
try {
handler.handleRequest(createRequest(100).getJDiscRequest(), responseHandler);
fail();
} catch (OverloadException e) {}
assertEquals(429, responseHandler.getStatus());
}
private static class RejectingContainerThreadpool implements ContainerThreadPool {
private final Executor executor = ignored -> { throw new RejectedExecutionException(); };
@Override public Executor executor() { return executor; }
}
}
|