Search in sources :

Example 81 with TTransportException

use of org.apache.thrift.transport.TTransportException in project commons by twitter.

the class ThriftTest method testAsyncRetrySelection.

@Test
public void testAsyncRetrySelection() throws Exception {
    // verify subclasses pass the retry filter
    class HopelesslyLost extends NotFoundException {
    }
    Capture<AsyncMethodCallback<Integer>> callbackCapture1 = new Capture<AsyncMethodCallback<Integer>>();
    expectAsyncServiceCall(true).calculateMass(eq("jake"), capture(callbackCapture1));
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
    Capture<AsyncMethodCallback<Integer>> callbackCapture2 = new Capture<AsyncMethodCallback<Integer>>();
    expectAsyncServiceRetry(true).calculateMass(eq("jake"), capture(callbackCapture2));
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
    // Verifies that our callback was called.
    TTransportException nonRetryableException = new TTransportException();
    callback.onError(nonRetryableException);
    Thrift<TestServiceAsync> thrift = createAsyncThrift(expectUnusedExecutorService());
    control.replay();
    TestServiceAsync testService = thrift.builder().withRetries(2).retryOn(NotFoundException.class).withConnectTimeout(ASYNC_CONNECT_TIMEOUT).create();
    testService.calculateMass("jake", callback);
    callbackCapture1.getValue().onError(new HopelesslyLost());
    callbackCapture2.getValue().onError(nonRetryableException);
    assertRequestsTotal(thrift, 1);
    assertErrorsTotal(thrift, 1);
    assertReconnectsTotal(thrift, 1);
    assertTimeoutsTotal(thrift, 0);
    control.verify();
}
Also used : AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) TTransportException(org.apache.thrift.transport.TTransportException) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 82 with TTransportException

use of org.apache.thrift.transport.TTransportException in project commons by twitter.

the class ThriftTest method testAsyncRetriesRecover.

@Test
public void testAsyncRetriesRecover() throws Exception {
    // Capture the callback that Thift has wrapped around our callback.
    Capture<AsyncMethodCallback<Integer>> callbackCapture = new Capture<AsyncMethodCallback<Integer>>();
    // 1st call
    expectAsyncServiceCall(true).calculateMass(eq("jake"), capture(callbackCapture));
    expectLastCall().andThrow(new TTransportException());
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
    // 1st retry recovers
    expectAsyncServiceRetry(false).calculateMass(eq("jake"), capture(callbackCapture));
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.SUCCESS), anyLong());
    // Verifies that our callback was called.
    callback.onComplete(42);
    Thrift<TestServiceAsync> thrift = createAsyncThrift(expectUnusedExecutorService());
    control.replay();
    thrift.builder().withRetries(1).withConnectTimeout(ASYNC_CONNECT_TIMEOUT).create().calculateMass("jake", callback);
    // Mimicks the async response from the server.
    callbackCapture.getValue().onComplete(42);
    assertRequestsTotal(thrift, 1);
    assertErrorsTotal(thrift, 0);
    assertReconnectsTotal(thrift, 0);
    assertTimeoutsTotal(thrift, 0);
    control.verify();
}
Also used : AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) TTransportException(org.apache.thrift.transport.TTransportException) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 83 with TTransportException

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();
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test)

Example 84 with TTransportException

use of org.apache.thrift.transport.TTransportException in project commons by twitter.

the class ThriftTest method testDoCallThriftException.

@Test
public void testDoCallThriftException() throws Exception {
    Capture<TTransport> transportCapture = new Capture<TTransport>();
    TestService testService = expectThriftError(transportCapture);
    TTransportException tException = new TTransportException();
    expect(testService.calculateMass("jake")).andThrow(tException);
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
    Thrift<TestService> thrift = createThrift(expectUnusedExecutorService());
    control.replay();
    try {
        thrift.builder().blocking().create().calculateMass("jake");
        fail("Expected thrift exception to bubble unmodified");
    } catch (TException e) {
        assertSame(tException, e);
    }
    assertRequestsTotal(thrift, 1);
    assertErrorsTotal(thrift, 1);
    assertReconnectsTotal(thrift, 1);
    assertTimeoutsTotal(thrift, 0);
    assertTrue(transportCapture.hasCaptured());
    assertFalse("Expected the transport to be forcibly closed when a thrift error is encountered", transportCapture.getValue().isOpen());
    control.verify();
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 85 with TTransportException

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);
    }
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)165 TTransport (org.apache.thrift.transport.TTransport)43 TException (org.apache.thrift.TException)42 Test (org.junit.Test)39 IOException (java.io.IOException)38 TSocket (org.apache.thrift.transport.TSocket)38 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TProtocol (org.apache.thrift.protocol.TProtocol)26 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)24 TServerSocket (org.apache.thrift.transport.TServerSocket)15 ArrayList (java.util.ArrayList)13 TFramedTransport (org.apache.thrift.transport.TFramedTransport)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 HostAndPort (org.apache.accumulo.core.util.HostAndPort)10 InetSocketAddress (java.net.InetSocketAddress)9 AccumuloException (org.apache.accumulo.core.client.AccumuloException)9 Function (org.apache.hadoop.hive.metastore.api.Function)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 Partition (org.apache.hadoop.hive.metastore.api.Partition)8