package com.yahoo.vespa.http.server;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

import com.yahoo.container.handler.threadpool.ContainerThreadPool;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
import com.yahoo.container.logging.AccessLog;
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(),
                AccessLog.voidAccessLog(),
                new DocumentmanagerConfig(new DocumentmanagerConfig.Builder().enablecompression(true)),
                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;  }
    }

}
@@ -1831,8 +1831,9 @@
     %7D%0A%0A%7D
+%0A

Add missing trailing newline