use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class TcpTransportTest method shouldExhaustRetries.
@Test
public void shouldExhaustRetries() throws TransportException, IOException {
Sink sink = mock(Sink.class);
TcpTransport transport = new TcpTransport(sink, 4, 0);
TcpTransportBuffer transportBuffer = mock(TcpTransportBuffer.class);
Buffer buffer = new Buffer();
when(transportBuffer.getInternalBuffer()).thenReturn(buffer);
doThrow(new IOException()).when(sink).write(eq(buffer), eq(0L));
try {
transport.sendBatch(transportBuffer);
fail("Should exhaust retries");
} catch (TransportException ex) {
assertTrue(ex.getCause() instanceof RetriesExhaustedException);
}
verify(sink, times(5)).write(eq(buffer), eq(0L));
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class HttpTransport method sendBatchUncompressed.
protected HttpResponse sendBatchUncompressed(HttpPost httpPost, byte[] raw) throws TransportException {
HttpEntity entity = new ByteArrayEntity(raw, getUncompressedContentType());
httpPost.setEntity(entity);
/*
* Make call
*/
HttpResponse resp = null;
try {
resp = this.client.execute(httpPost);
} catch (IOException e) {
throw new TransportException("failed to make call", e);
}
return resp;
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class HttpTransport method sendBatchCompressed.
protected HttpResponse sendBatchCompressed(HttpPost httpPost, byte[] raw) throws TransportException {
/*
* Write gzip data to Entity and set content encoding to gzip
*/
ByteArrayEntity entity = new ByteArrayEntity(raw, ContentType.DEFAULT_BINARY);
entity.setContentEncoding("gzip");
httpPost.addHeader(new BasicHeader("Accept-Encoding", "gzip"));
httpPost.setEntity(entity);
/*
* Make call
*/
HttpResponse resp = null;
try {
resp = this.client.execute(httpPost);
} catch (IOException e) {
throw new TransportException("failed to make call", e);
}
return resp;
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class ElasticSearchTransport method checkResponse.
@Override
public void checkResponse(HttpResponse resp, String responseString) throws TransportException {
/*
* Check responses status code of the overall bulk call. The call can succeed but have
* individual failures which are checked later.
*/
if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new TransportException("es call failed because " + resp.getStatusLine().getReasonPhrase());
}
/*
* Short circuit deserializing the response by just looking if there are any errors
*/
if (responseString.contains("\"errors\":false")) {
return;
}
/*
* Convert response text to a POJO. Only tested with ES 2.4.x and 5.x.
*/
Gson gson = new GsonBuilder().create();
EsResponse esResp = null;
try {
esResp = gson.fromJson(responseString, EsResponse.class);
} catch (JsonSyntaxException e) {
throw new TransportException("es call failed because " + resp.getStatusLine().getReasonPhrase(), e);
}
/*
* Look for the errors per index request
*/
int failures = 0;
if (esResp.items == null) {
throw new TransportException("es call failed because " + resp.getStatusLine().getReasonPhrase());
}
HashSet<String> errorTypes = new HashSet<String>();
for (Item item : esResp.items) {
Index index = item.index;
if (index == null || index.error == null || index.error.reason == null) {
continue;
}
/*
* For now just allow 200's and 400's. Both are considered non-fatal errors from the lambda's
* perspective.
*/
switch(index.status) {
case HttpStatus.SC_OK:
case HttpStatus.SC_BAD_REQUEST:
continue;
default:
failures++;
if (index.error != null && index.error.reason != null && index.error.type != null) {
if (!errorTypes.contains(index.error.type)) {
logger.error("Indexing Error Reason: " + index.error.reason);
if (index.error.caused_by != null) {
logger.error("Indexing Error Cause: " + index.error.caused_by.reason);
}
errorTypes.add(index.error.type);
}
}
}
}
errorTypes.clear();
if (failures != 0) {
throw new TransportException("es index failure count is " + failures);
}
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class BaseHandlerTest method testTransportOnSendFailure.
@Test(expected = TransportException.class)
public void testTransportOnSendFailure() throws Throwable {
BaseHandler.CONFIG_FILE = "/config/handler_config.json";
List<DummyEvent> events = new ArrayList<DummyEvent>(2);
events.add(new DummyEvent("foo", 0));
events.add(new DummyEvent("bar", 0));
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
handler.init(context);
IpcSenderService spyIpc = spy(handler.getIpcService());
TransportFactory tf = spy(handler.getIpcService().getTransportFactory());
BufferedTransporter mockTransport = mock(BufferedTransporter.class);
doThrow(new TransportException("expected")).when(mockTransport).sendBatch(any());
when(tf.newInstance()).thenReturn(mockTransport);
spyIpc.setTransportFactory(tf);
handler.setIpcService(spyIpc);
try {
handler.handler(events, context);
} catch (Exception e) {
throw e.getCause().getCause();
}
}
Aggregations