blob: f91a853c52c7e4bf00988b2951fd1f2115e9d0ea (
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
61
62
63
64
65
66
67
68
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.core.communication;
import com.yahoo.vespa.http.client.config.Endpoint;
import com.yahoo.vespa.http.client.core.Document;
import com.yahoo.vespa.http.client.core.ErrorCode;
import com.yahoo.vespa.http.client.core.OperationStatus;
import com.yahoo.vespa.http.client.core.ServerResponseException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
/**
* Dummy implementation.
*
* @author dybis
*/
public class DryRunGatewayConnection implements GatewayConnection {
private final Endpoint endpoint;
private Instant connectionTime = null;
public DryRunGatewayConnection(Endpoint endpoint) {
this.endpoint = endpoint;
}
@Override
public InputStream writeOperations(List<Document> docs) throws ServerResponseException, IOException {
StringBuilder result = new StringBuilder();
for (Document doc : docs) {
OperationStatus operationStatus = new OperationStatus("ok", doc.getOperationId(), ErrorCode.OK, false, "");
result.append(operationStatus.render());
}
return new ByteArrayInputStream(result.toString().getBytes(StandardCharsets.UTF_8));
}
@Override
public InputStream drain() throws ServerResponseException, IOException {
return writeOperations(new ArrayList<Document>());
}
@Override
public boolean connect() {
connectionTime = Clock.systemUTC().instant();
return true;
}
@Override
public Instant connectionTime() { return connectionTime; }
@Override
public Endpoint getEndpoint() {
return endpoint;
}
@Override
public void handshake() throws ServerResponseException, IOException { }
@Override
public void close() { }
}
|