aboutsummaryrefslogtreecommitdiffstats
path: root/application/src/test/java/com/yahoo/application/container/MockClient.java
blob: 95811b67b708756d27754dc3a0f3322d54eeb303 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container;

import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.handler.CompletionHandler;
import com.yahoo.jdisc.handler.ContentChannel;
import com.yahoo.jdisc.handler.ResponseHandler;
import com.yahoo.jdisc.service.AbstractClientProvider;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Christian Andersen
 */
public class MockClient extends AbstractClientProvider {

    private final AtomicInteger counter = new AtomicInteger();

    @Override
    public ContentChannel handleRequest(Request request, ResponseHandler handler) {
        counter.incrementAndGet();
        final ContentChannel responseContentChannel = handler.handleResponse(new Response(200));
        responseContentChannel.close(NOOP_COMPLETION_HANDLER);
        return null;
    }

    public int getCounter() {
        return counter.get();
    }

    private static final CompletionHandler NOOP_COMPLETION_HANDLER = new CompletionHandler() {
        @Override
        public void completed() {
            // Ignored
        }

        @Override
        public void failed(Throwable t) {
            // Ignored
        }
    };

}