use of org.apache.thrift.protocol.TCompactProtocol in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method testAppend.
@Test
public void testAppend() throws Exception {
// find size of the initial span
Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2);
process.write(new TCompactProtocol(memoryTransport));
int processSize = memoryTransport.getPos();
memoryTransport.reset();
span.write(new TCompactProtocol((memoryTransport)));
int spanSize = memoryTransport.getPos();
// create a sender thats a multiple of the span size (accounting for span overhead)
// this allows us to test the boundary conditions of writing spans.
int expectedNumSpans = 11;
int maxPacketSize = (spanSize * expectedNumSpans) + sender.EMIT_BATCH_OVERHEAD + processSize;
int maxPacketSizeLeft = maxPacketSize - sender.EMIT_BATCH_OVERHEAD - processSize;
// add enough spans to be under buffer limit
sender = new UdpSender(destHost, destPort, maxPacketSize);
while (spanSize < maxPacketSizeLeft) {
sender.append(jaegerSpan);
maxPacketSizeLeft -= spanSize;
}
// add a span that overflows the limit to hit the last branch
int result = sender.append(jaegerSpan);
assertEquals(expectedNumSpans, result);
}
use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.
the class CarbonUtil method getByteArray.
/**
* Below method will be used to convert the thrift object to byte array.
*/
public static byte[] getByteArray(TBase t) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte[] thriftByteArray = null;
TProtocol binaryOut = new TCompactProtocol(new TIOStreamTransport(stream));
try {
t.write(binaryOut);
stream.flush();
thriftByteArray = stream.toByteArray();
} catch (TException | IOException e) {
LOGGER.error("Error while converting to byte array from thrift object: " + e.getMessage());
closeStreams(stream);
} finally {
closeStreams(stream);
}
return thriftByteArray;
}
use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.
the class CarbonUtil method readDataChunk3.
public static DataChunk3 readDataChunk3(InputStream stream) throws IOException {
TBaseCreator creator = new ThriftReader.TBaseCreator() {
@Override
public TBase create() {
return new DataChunk3();
}
};
TProtocol binaryIn = new TCompactProtocol(new TIOStreamTransport(stream));
TBase t = creator.create();
try {
t.read(binaryIn);
} catch (TException e) {
throw new IOException(e);
}
return (DataChunk3) t;
}
use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.
the class ThriftWriter method open.
/**
* Open the file for writing.
*/
public void open() throws IOException {
FileFactory.FileType fileType = FileFactory.getFileType(fileName);
dataOutputStream = FileFactory.getDataOutputStream(fileName, fileType, bufferSize, append);
binaryOut = new TCompactProtocol(new TIOStreamTransport(dataOutputStream));
}
use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.
the class ThriftWriter method open.
/**
* Method for opening file writing for atomic operations
*
* @param fileWriteOperation
* @throws IOException
*/
public void open(FileWriteOperation fileWriteOperation) throws IOException {
FileFactory.FileType fileType = FileFactory.getFileType(fileName);
atomicFileOperationsWriter = new AtomicFileOperationsImpl(fileName, fileType);
dataOutputStream = atomicFileOperationsWriter.openForWrite(fileWriteOperation);
binaryOut = new TCompactProtocol(new TIOStreamTransport(dataOutputStream));
}
Aggregations