Example usage for org.apache.thrift TException TException

List of usage examples for org.apache.thrift TException TException

Introduction

In this page you can find the example usage for org.apache.thrift TException TException.

Prototype

public TException() 

Source Link

Usage

From source file:com.bendb.thrifty.testing.ThriftTestHandler.java

License:Apache License

@Override
public void testException(String arg) throws Xception, TException {
    out.printf("testException(%s)\n", arg);
    if ("TException".equals(arg)) {
        throw new TException();
    } else if ("Xception".equals(arg)) {
        throw new Xception(1001, "Xception");
    }//from  w  ww.  j a  v a  2 s . c  om
}

From source file:com.facebook.hiveio.common.FaultyThriftHiveMetastore.java

License:Apache License

@Override
public Table get_table(String s, String s2) throws MetaException, NoSuchObjectException, TException {
    numCalls++;// w w w. ja va 2 s.co  m
    if (numCalls <= numFailures) {
        throw new TException();
    } else {
        return null;
    }
}

From source file:com.pinterest.rocksplicator.controller.tasks.AddHostTaskTest.java

License:Apache License

@Test
public void testFail() throws Exception {
    doThrow(new TException()).when(client).ping();

    AddHostTask task = new AddHostTask("127.0.0.1", 8093, "us-east-1a", "/hdfs", 100);
    injector.injectMembers(task);//from  www  . j a v a2  s .  com

    FIFOTaskQueue taskQueue = new FIFOTaskQueue(10);
    Context ctx = new Context(123, CLUSTER, taskQueue, null);
    task.process(ctx);

    Assert.assertEquals(taskQueue.getResult(123), "Host to add is not alive!");
}

From source file:com.pinterest.rocksplicator.controller.tasks.HealthCheckTaskTest.java

License:Apache License

@Test
public void testFail() throws Exception {
    doThrow(new TException()).when(client).ping();
    when(clientFactory.getClient(any())).thenReturn(client);

    HealthCheckTask t = new HealthCheckTask(new HealthCheckTask.Param().setNumReplicas(3));
    injector.injectMembers(t);/*from   www .ja  v  a2s .  c  om*/

    FIFOTaskQueue taskQueue = new FIFOTaskQueue(10);
    Context ctx = new Context(123, CLUSTER, taskQueue, null);
    t.process(ctx);

    Assert.assertTrue(taskQueue.getResult(123).startsWith("Unable to ping hosts"));
    Assert.assertTrue(taskQueue.getResult(123).contains("127.0.0.1:8090"));
    Assert.assertTrue(taskQueue.getResult(123).contains("127.0.0.1:8091"));
    Assert.assertTrue(taskQueue.getResult(123).contains("127.0.0.1:8092"));
}

From source file:com.pinterest.rocksplicator.controller.tasks.RemoveHostTaskTest.java

License:Apache License

@Test
public void testSuccessful() throws Exception {
    doThrow(new TException()).when(client).ping();

    RemoveHostTask task = new RemoveHostTask(new HostBean().setIp("127.0.0.1").setPort(8090));
    injector.injectMembers(task);/*w ww .  j a  v  a  2s  .  c  o  m*/

    FIFOTaskQueue taskQueue = new FIFOTaskQueue(10);
    Context ctx = new Context(123, CLUSTER, taskQueue, null);
    task.process(ctx);

    Assert.assertEquals(taskQueue.getResult(123), "Successfully removed host 127.0.0.1:8090");

    ClusterBean newConfig = ZKUtil.getClusterConfig(zkClient, CLUSTER);
    Assert.assertEquals(newConfig.getSegments().size(), 1);
    SegmentBean segment = newConfig.getSegments().get(0);
    Assert.assertEquals(segment.getHosts().size(), 2);
    Assert.assertEquals(segment.getHosts().stream().filter(host -> host.getPort() == 8090).count(), 0);
}

From source file:com.qubole.rubix.bookkeeper.RetryingBookkeeperClient.java

License:Apache License

private <V> V retryConnection(Callable<V> callable) throws TException {
    int errors = 0;

    while (errors < maxRetries) {
        try {/* w ww  .j av  a 2  s.  c om*/
            if (!transport.isOpen()) {
                transport.open();
            }
            return callable.call();
        } catch (Exception e) {
            LOG.info("Error while connecting" + e.getStackTrace().toString());
            errors++;
        }
        if (transport.isOpen()) {
            transport.close();
        }
    }

    throw new TException();
}

From source file:edu.washington.cs.cse490h.donut.server.DonutClientTest.java

License:Apache License

@Test
public void testPing_False() throws Exception {
    DonutClient donutClient = new DonutClient(null, clientLocatorMock);

    TNode node = new TNode();

    expect(clientLocatorMock.get(node)).andReturn(keyLocator);
    clientLocatorMock.release(node);//from w ww.  j a  v  a  2  s.  c om
    keyLocator.ping();
    EasyMock.expectLastCall().andThrow(new TException());
    replay(clientLocatorMock, keyLocator);

    assertFalse(donutClient.ping(node));
}

From source file:edu.washington.cs.cse490h.donut.server.DonutClientTest.java

License:Apache License

@Test
public void testCheckPredecessor_Down() throws Exception {
    Node node = new Node(null, 0, null);
    TNode predecessor = new TNode("pred", 8080, null);
    node.setPredecessor(predecessor);//from  w w w .j a v  a  2 s  .c  om
    DonutClient donutClient = new DonutClient(node, clientLocatorMock);

    expect(clientLocatorMock.get(predecessor)).andReturn(keyLocator);
    clientLocatorMock.release(predecessor);
    keyLocator.ping();
    expectLastCall().andThrow(new TException());
    replay(clientLocatorMock, keyLocator);

    donutClient.checkPredecessor();
    assertNull(node.getPredecessor());
}

From source file:edu.washington.cs.cse490h.donut.server.DonutClientTest.java

License:Apache License

@Test
public void testStabilize_NodeThrowsTException() throws Exception {
    Node node = new Node("self", 0, new KeyId(0));
    TNode successor = new TNode("other", 0, new KeyId(200));
    node.setSuccessor(successor);/*w w w  .j  a  v  a 2s .  c  o m*/

    DonutClient donutClient = new DonutClient(node, clientLocatorMock);

    expect(clientLocatorMock.get(successor)).andReturn(keyLocator);
    clientLocatorMock.release(successor);
    expect(keyLocator.getPredecessor()).andThrow(new TException());
    replay(clientLocatorMock, keyLocator);

    donutClient.stabilize();
    assertSame(node.getTNode(), node.getSuccessor());
}