blob: bea16fbbdbc43380a6d2ce89e324d2fd7c4e7d64 (
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
|
package com.yahoo.search.handler;
import ai.vespa.cloud.ZoneInfo;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.container.core.ContainerHttpConfig;
import com.yahoo.container.handler.threadpool.ContainerThreadPool;
import com.yahoo.container.jdisc.ContentChannelOutputStream;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.jdisc.handler.ReadableContentChannel;
import com.yahoo.jdisc.test.MockMetric;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.searchchain.ExecutionFactory;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Tests filling hits as they are rendered to avoid having to keep all hits in memory.
*
* @author bratseth
*/
public class StreamedFillTest {
@Test
void testStreamedFill() {
var handler = new SearchHandler(new MockMetric(),
new SimpleContainerThreadpool(),
new CompiledQueryProfileRegistry(),
new ContainerHttpConfig.Builder().build(),
new ComponentRegistry(),
ExecutionFactory.empty(),
ZoneInfo.defaultInfo());
var request = HttpRequest.createTestRequest("?query=foo", com.yahoo.jdisc.http.HttpRequest.Method.GET);
var response = (HttpSearchResponse)handler.handle(request);
System.out.println(render(response));
}
private String render(HttpSearchResponse response) {
try {
var out = new ReadableContentChannel();
response.render(new ContentChannelOutputStream(out), out, null);
return new String(out.toStream().readAllBytes(), UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static class SimpleContainerThreadpool implements ContainerThreadPool {
private final Executor executor = Executors.newCachedThreadPool();
@Override public Executor executor() { return executor; }
}
}
|