use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class FileTransport method sendBatch.
@Override
public void sendBatch(TransportBuffer buffer) throws TransportException {
FileTransportBuffer buf = (FileTransportBuffer) buffer;
FileOutputStream out = null;
try {
out = new FileOutputStream(new File(this.filename));
out.write(buf.getInternalBuffer().toByteArray());
} catch (IOException e) {
throw new TransportException("unable to write to file", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class ElasticSearchTransporterTest method testErrorsResponse.
@Test(expected = TransportException.class)
public void testErrorsResponse() throws TransportException, IOException {
byte[] respPayload = getResponse().getBytes(StandardCharsets.UTF_8);
HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_OK);
ElasticSearchTransport transport = new ElasticSearchTransport(client, false);
try {
transport.sendBatch("foo".getBytes());
} catch (Exception e) {
assertEquals("es index failure count is 1", e.getCause().getMessage());
throw e;
}
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class ElasticSearchTransporterTest method testGzipErrorsResponse.
@Test(expected = TransportException.class)
public void testGzipErrorsResponse() throws TransportException, IOException {
byte[] respPayload = getResponse().getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream os = new GZIPOutputStream(baos);
os.write(respPayload);
os.close();
byte[] compressedResponse = baos.toByteArray();
HttpClient client = getMockClientWithResponse(compressedResponse, ContentType.DEFAULT_BINARY, HttpStatus.SC_OK);
ElasticSearchTransport transport = new ElasticSearchTransport(client, true);
try {
transport.sendBatch("foo".getBytes());
} catch (Exception e) {
assertEquals("es call failed because expected failure", e.getCause().getMessage());
throw e;
}
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class S3TransporterTest method testAmazonClientException.
@Test(expected = TransportException.class)
public void testAmazonClientException() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requets, and replies
*/
AmazonS3Client mockClient = mock(AmazonS3Client.class);
UploadPartResult uploadResult = new UploadPartResult();
uploadResult.setETag("foo");
doThrow(new AmazonClientException("expected")).when(mockClient).uploadPart(any(UploadPartRequest.class));
InitiateMultipartUploadResult initUploadResult = new InitiateMultipartUploadResult();
initUploadResult.setUploadId("123");
doReturn(initUploadResult).when(mockClient).initiateMultipartUpload(any(InitiateMultipartUploadRequest.class));
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer = new S3TransportBuffer(1000, false, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").when(mockIevent).getSerialized();
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath", false, multiPartUploads);
/*
* Do actual test
*/
buffer.add(mockIevent);
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
try {
transport.sendBatch(buffer, partitions, new TestContext());
} catch (Exception e) {
assertEquals(e.getCause().getClass(), AmazonClientException.class);
throw e;
}
}
use of com.nextdoor.bender.ipc.TransportException in project bender by Nextdoor.
the class HttpTransportTest method testErrorsResponse.
@Test(expected = TransportException.class)
public void testErrorsResponse() throws TransportException, IOException {
byte[] respPayload = "resp".getBytes(StandardCharsets.UTF_8);
HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_INTERNAL_SERVER_ERROR, false);
HttpTransport transport = new HttpTransport(client, "", false, 1, 1);
try {
transport.sendBatch("foo".getBytes());
} catch (Exception e) {
assertEquals("http transport call failed because \"expected failure\" payload response \"resp\"", e.getCause().getMessage());
throw e;
}
}
Aggregations