use of org.apache.thrift.transport.TTransportException in project commons by twitter.
the class ThriftTest method testRetriesRecover.
@Test
public void testRetriesRecover() throws Exception {
// 1st call
expect(expectServiceCall(true).calculateMass("jake")).andThrow(new TTransportException());
requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
// 1st retry recovers
expect(expectServiceCall(false).calculateMass("jake")).andReturn(42);
requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.SUCCESS), anyLong());
Thrift<TestService> thrift = createThrift(expectUnusedExecutorService());
control.replay();
TestService testService = thrift.builder().blocking().withRetries(1).create();
assertEquals(42, testService.calculateMass("jake"));
assertRequestsTotal(thrift, 1);
assertErrorsTotal(thrift, 0);
assertReconnectsTotal(thrift, 0);
assertTimeoutsTotal(thrift, 0);
control.verify();
}
use of org.apache.thrift.transport.TTransportException in project commons by twitter.
the class TTextProtocol method writeSequenceBegin.
/**
* Helper shared by write{List/Set}Begin
*/
private void writeSequenceBegin(int size) throws TException {
getCurrentContext().write();
if (getCurrentContext().isMapKey()) {
throw new TException(SEQUENCE_AS_KEY_ILLEGAL);
}
pushContext(new SequenceContext(null));
try {
getCurrentWriter().beginArray();
} catch (IOException ex) {
throw new TTransportException(ex);
}
}
use of org.apache.thrift.transport.TTransportException in project metacat by Netflix.
the class HiveMetastoreClientFactory method createRawTransport.
protected TTransport createRawTransport(final String host, final int port) throws TTransportException {
if (socksProxy == null) {
final TTransport transport = new TSocket(host, port, timeoutMillis);
try {
transport.open();
return transport;
} catch (Throwable t) {
transport.close();
throw t;
}
}
final Socket socks = createSocksSocket(socksProxy);
try {
try {
socks.connect(InetSocketAddress.createUnresolved(host, port), timeoutMillis);
socks.setSoTimeout(timeoutMillis);
return new TSocket(socks);
} catch (Throwable t) {
closeQuietly(socks);
throw t;
}
} catch (IOException e) {
throw new TTransportException(e);
}
}
use of org.apache.thrift.transport.TTransportException in project alluxio by Alluxio.
the class ThriftClientPool method createNewResource.
/**
* Creates a thrift client instance.
*
* @return the thrift client created
* @throws IOException if it fails to create a thrift client
*/
@Override
protected T createNewResource() throws IOException {
TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
TProtocol binaryProtocol = new TBinaryProtocol(transport);
T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
TException exception;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
do {
LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
try {
if (!transport.isOpen()) {
transport.open();
}
if (transport.isOpen()) {
checkVersion(client);
}
LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
return client;
} catch (TTransportException e) {
if (e.getCause() instanceof java.net.SocketTimeoutException) {
// Do not retry if socket timeout.
String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
throw new IOException(message, e);
}
LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
exception = e;
}
} while (retryPolicy.attemptRetry());
LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
Preconditions.checkNotNull(exception);
throw new IOException(exception);
}
use of org.apache.thrift.transport.TTransportException in project voldemort by voldemort.
the class ThriftSerializer method toObject.
public T toObject(byte[] bytes) {
MemoryBuffer buffer = new MemoryBuffer();
try {
buffer.write(bytes);
} catch (TTransportException e) {
throw new SerializationException(e);
}
TProtocol protocol = createThriftProtocol(buffer);
T msg = null;
try {
msg = messageClass.newInstance();
msg.read(protocol);
} catch (InstantiationException e) {
throw new SerializationException(e);
} catch (IllegalAccessException e) {
throw new SerializationException(e);
} catch (TException e) {
throw new SerializationException(e);
}
return msg;
}
Aggregations