blob: 30cdd7acfe2024a0f19fa5eefc9a4243704be6a4 (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.client;
import com.ning.http.client.AsyncHandler;
import com.yahoo.jdisc.Metric;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.handler.ContentChannel;
import com.yahoo.jdisc.handler.ReadableContentChannel;
import com.yahoo.jdisc.handler.ResponseHandler;
import com.yahoo.jdisc.test.NonWorkingRequest;
import org.testng.annotations.Test;
import java.util.Map;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class AsyncResponseHandlerTestCase {
@Test(enabled = false)
public void requireThatOnThrowableAbortsHandler() throws Exception {
AsyncResponseHandler handler = new AsyncResponseHandler(NonWorkingRequest.newInstance("http://localhost/"),
new MyResponseHandler(), new MyMetric(),
new Metric.Context() { });
handler.onThrowable(new Throwable());
assertEquals(AsyncHandler.STATE.ABORT, handler.onStatusReceived(null));
assertEquals(AsyncHandler.STATE.ABORT, handler.onHeadersReceived(null));
assertEquals(AsyncHandler.STATE.ABORT, handler.onBodyPartReceived(null));
assertNull(handler.onCompleted());
}
private static class MyResponseHandler implements ResponseHandler {
@Override
public ContentChannel handleResponse(Response response) {
return new ReadableContentChannel();
}
}
private static class MyMetric implements Metric {
@Override
public void set(String key, Number val, Context ctx) {
}
@Override
public void add(String key, Number val, Context ctx) {
}
@Override
public Context createContext(Map<String, ?> properties) {
return null;
}
}
}
|