blob: f5300d75180eeff3403a71acaa1705feab1d5657 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch.rpc;
import com.yahoo.compress.CompressionType;
import com.yahoo.prelude.fastsearch.FastHit;
import com.yahoo.search.dispatch.rpc.Client.NodeConnection;
import com.yahoo.search.dispatch.rpc.Client.ResponseReceiver;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ovirtanen
*/
public class MockRpcResourcePoolBuilder {
private Map<Integer, NodeConnection> nodeConnections = new HashMap<>();
public MockRpcResourcePoolBuilder connection(int distKey) {
nodeConnections.put(distKey, new MockNodeConnection(distKey));
return this;
}
public RpcResourcePool build() {
return new RpcResourcePool(nodeConnections);
}
private static class MockNodeConnection implements NodeConnection {
private final int key;
public MockNodeConnection(int key) {
this.key = key;
}
@Override
public void request(String rpcMethod, CompressionType compression, int uncompressedLength, byte[] compressedPayload,
ResponseReceiver responseReceiver, double timeoutSeconds) {
responseReceiver.receive(Client.ResponseOrError.fromError("request('"+rpcMethod+"', ..) attempted for node " + key));
}
@Override
public void close() {
}
}
}
|