use of org.apache.nifi.stream.io.ByteArrayInputStream in project nifi by apache.
the class TestSocketClientTransaction method testSendZeroFlowFile.
@Test
public void testSendZeroFlowFile() throws IOException {
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
ByteArrayInputStream bis = new ByteArrayInputStream(serverResponseBos.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
SocketClientTransaction transaction = getClientTransaction(bis, bos, TransferDirection.SEND);
execSendZeroFlowFile(transaction);
// Verify what client has sent.
DataInputStream sentByClient = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
assertEquals(RequestType.SEND_FLOWFILES, RequestType.readRequestType(sentByClient));
assertEquals(-1, sentByClient.read());
}
use of org.apache.nifi.stream.io.ByteArrayInputStream in project nifi by apache.
the class TestSocketClientTransaction method testReceiveWithInvalidChecksum.
@Test
public void testReceiveWithInvalidChecksum() throws IOException {
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
DataOutputStream serverResponse = new DataOutputStream(serverResponseBos);
ResponseCode.MORE_DATA.writeResponse(serverResponse);
codec.encode(createDataPacket("contents on server 1"), serverResponse);
ResponseCode.CONTINUE_TRANSACTION.writeResponse(serverResponse);
codec.encode(createDataPacket("contents on server 2"), serverResponse);
ResponseCode.FINISH_TRANSACTION.writeResponse(serverResponse);
ResponseCode.BAD_CHECKSUM.writeResponse(serverResponse);
ByteArrayInputStream bis = new ByteArrayInputStream(serverResponseBos.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
SocketClientTransaction transaction = getClientTransaction(bis, bos, TransferDirection.RECEIVE);
execReceiveWithInvalidChecksum(transaction);
// Verify what client has sent.
DataInputStream sentByClient = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "2969091230", confirmResponse.getMessage());
assertEquals(-1, sentByClient.read());
}
use of org.apache.nifi.stream.io.ByteArrayInputStream in project nifi by apache.
the class TestSplitAvro method checkDataFileSplitSize.
private void checkDataFileSplitSize(List<MockFlowFile> flowFiles, int expectedRecordsPerSplit, boolean checkMetadata) throws IOException {
for (final MockFlowFile flowFile : flowFiles) {
try (final ByteArrayInputStream in = new ByteArrayInputStream(flowFile.toByteArray());
final DataFileStream<GenericRecord> reader = new DataFileStream<>(in, new GenericDatumReader<GenericRecord>())) {
int count = 0;
GenericRecord record = null;
while (reader.hasNext()) {
record = reader.next(record);
Assert.assertNotNull(record.get("name"));
Assert.assertNotNull(record.get("favorite_number"));
count++;
}
assertEquals(expectedRecordsPerSplit, count);
if (checkMetadata) {
assertEquals(META_VALUE1, reader.getMetaString(META_KEY1));
assertEquals(META_VALUE2, reader.getMetaLong(META_KEY2));
assertEquals(META_VALUE3, new String(reader.getMeta(META_KEY3), "UTF-8"));
}
}
}
}
use of org.apache.nifi.stream.io.ByteArrayInputStream in project apex-malhar by apache.
the class NiFiSinglePortInputOperatorTest method getDataPacket.
@NotNull
private DataPacket getDataPacket(final String id) {
Map<String, String> attrs = new HashMap<>();
attrs.put("keyA", "valA");
attrs.put("keyB", "valB");
attrs.put("key" + id, "val" + id);
byte[] content = ("content" + id).getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream in = new ByteArrayInputStream(content);
return new MockDataPacket(attrs, in, content.length);
}
Aggregations