use of com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method testResponseStreamingAttachmentsForbidden.
@Test
public void testResponseStreamingAttachmentsForbidden() {
//This test verifies that the ParseqTraceDebugRequestHandler aborts any potential outgoing response attachments
//set by a resource method.
final URI uri = URI.create("http://host/abc/12/__debug/parseqtrace/raw");
ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
RestRequest request = requestBuilder.build();
RequestContext requestContext = new RequestContext();
final RequestExecutionCallback<RestResponse> callback = new RequestExecutionCallback<RestResponse>() {
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.fail("Request execution failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
}
};
final RestLiTestAttachmentDataSource testAttachmentDataSource = RestLiTestAttachmentDataSource.createWithRandomPayload("1");
final RestLiResponseAttachments responseAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(testAttachmentDataSource).build();
requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {
@Override
public void handleRequest(RestRequest request, RequestContext requestContext, RequestExecutionCallback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
//Provide some attachments that should be aborted.
callback.onSuccess(response, new RequestExecutionReportBuilder().build(), responseAttachments);
}
}, null, callback);
Assert.assertTrue(testAttachmentDataSource.dataSourceAborted());
}
use of com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource in project rest.li by linkedin.
the class TestRestClientRequestBuilder method generateRequestAttachments.
private List<Object> generateRequestAttachments() {
final List<Object> requestAttachments = new ArrayList<>();
requestAttachments.add(new RestLiTestAttachmentDataSource(FIRST_PART_ID, FIRST_PART_PAYLOAD));
requestAttachments.add(new RestLiTestAttachmentDataSource(SECOND_PART_ID, SECOND_PART_PAYLOAD));
return requestAttachments;
}
use of com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource in project rest.li by linkedin.
the class TestAttachmentUtils method testMultipleAttachments.
@Test
public void testMultipleAttachments() {
final MultiPartMIMEWriter.Builder builder = new MultiPartMIMEWriter.Builder();
final List<RestLiTestAttachmentDataSource> testAttachmentDataSources = generateTestDataSources();
final RestLiTestAttachmentDataSourceIterator dataSourceIterator = new RestLiTestAttachmentDataSourceIterator(testAttachmentDataSources, new IllegalArgumentException());
// Let each data source know its parent, so that when the data source is done, it can notify it's parent to call onNewDataSourceWriter()
for (final RestLiTestAttachmentDataSource dataSource : testAttachmentDataSources) {
dataSource.setParentDataSourceIterator(dataSourceIterator);
}
AttachmentUtils.appendMultipleAttachmentsToBuilder(builder, dataSourceIterator);
final StreamRequest streamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(URI.create("foo"), "related", builder.build());
final MultiPartMIMEReader streamRequestReader = MultiPartMIMEReader.createAndAcquireStream(streamRequest);
final CountDownLatch streamRequestReaderLatch = new CountDownLatch(1);
final MIMETestUtils.MultiPartMIMEFullReaderCallback streamRequestReaderCallback = new MIMETestUtils.MultiPartMIMEFullReaderCallback(streamRequestReaderLatch);
streamRequestReader.registerReaderCallback(streamRequestReaderCallback);
try {
streamRequestReaderLatch.await(3000, TimeUnit.MILLISECONDS);
} catch (InterruptedException interruptedException) {
Assert.fail();
}
verifyAttachments(streamRequestReaderCallback.getSinglePartMIMEReaderCallbacks(), testAttachmentDataSources);
}
use of com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource in project rest.li by linkedin.
the class TestAttachmentUtils method testMixtureOfAttachmentsAbort.
@Test
public void testMixtureOfAttachmentsAbort() {
final MultiPartMIMEWriter.Builder builder = new MultiPartMIMEWriter.Builder();
final List<RestLiTestAttachmentDataSource> iteratorDataSources = generateTestDataSources();
final RestLiTestAttachmentDataSourceIterator dataSourceIterator = new RestLiTestAttachmentDataSourceIterator(iteratorDataSources, new IllegalArgumentException());
// Let each data source know its parent, so that when the data source is done, it can notify it's parent to call onNewDataSourceWriter()
for (final RestLiTestAttachmentDataSource dataSource : iteratorDataSources) {
dataSource.setParentDataSourceIterator(dataSourceIterator);
}
// Now one at the beginning
final RestLiTestAttachmentDataSource dataSourceBeginning = RestLiTestAttachmentDataSource.createWithRandomPayload("BEG");
// And one at the end
final RestLiTestAttachmentDataSource dataSourceEnd = RestLiTestAttachmentDataSource.createWithRandomPayload("END");
AttachmentUtils.appendSingleAttachmentToBuilder(builder, dataSourceBeginning);
AttachmentUtils.appendMultipleAttachmentsToBuilder(builder, dataSourceIterator);
AttachmentUtils.appendSingleAttachmentToBuilder(builder, dataSourceEnd);
// Abort everything. We want to make sure that our process of wrapping the rest.li data sources into the multipart
// mime layer correctly propagates the abandon/aborts.
builder.build().abortAllDataSources(new IllegalStateException());
Assert.assertTrue(dataSourceIterator.dataSourceIteratorAbandoned());
Assert.assertTrue(dataSourceBeginning.dataSourceAborted());
Assert.assertTrue(dataSourceEnd.dataSourceAborted());
// that an abort has taken place.
for (final RestLiTestAttachmentDataSource dataSource : iteratorDataSources) {
Assert.assertTrue(dataSource.dataSourceAborted());
}
}
use of com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource in project rest.li by linkedin.
the class TestAttachmentUtils method generateTestDataSources.
private List<RestLiTestAttachmentDataSource> generateTestDataSources() {
final RestLiTestAttachmentDataSource dataSourceA = RestLiTestAttachmentDataSource.createWithRandomPayload("A");
final RestLiTestAttachmentDataSource dataSourceB = RestLiTestAttachmentDataSource.createWithRandomPayload("B");
final RestLiTestAttachmentDataSource dataSourceC = RestLiTestAttachmentDataSource.createWithRandomPayload("C");
final RestLiTestAttachmentDataSource emptyBodySource = new RestLiTestAttachmentDataSource("D", ByteString.empty());
return new ArrayList<>(Arrays.asList(dataSourceA, dataSourceB, dataSourceC, emptyBodySource));
}
Aggregations