Search in sources :

Example 26 with TServer

use of org.apache.thrift.server.TServer in project accumulo by apache.

the class TServerUtilsTest method testStartServerPortRange.

@Test
public void testStartServerPortRange() throws Exception {
    TServer server = null;
    int[] port = findTwoFreeSequentialPorts(1024);
    String portRange = Integer.toString(port[0]) + "-" + Integer.toString(port[1]);
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, portRange);
    try {
        ServerAddress address = startServer();
        assertNotNull(address);
        server = address.getServer();
        assertNotNull(server);
        assertTrue(port[0] == address.getAddress().getPort() || port[1] == address.getAddress().getPort());
    } finally {
        if (null != server) {
            TServerUtils.stopTServer(server);
        }
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TServer(org.apache.thrift.server.TServer) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) Test(org.junit.Test)

Example 27 with TServer

use of org.apache.thrift.server.TServer in project accumulo by apache.

the class ProxyDurabilityIT method testDurability.

@Test
public void testDurability() throws Exception {
    Connector c = getConnector();
    Properties props = new Properties();
    // Avoid issues with locally installed client configuration files with custom properties
    File emptyFile = Files.createTempFile(null, null).toFile();
    emptyFile.deleteOnExit();
    props.put("instance", c.getInstance().getInstanceName());
    props.put("zookeepers", c.getInstance().getZooKeepers());
    props.put("tokenClass", PasswordToken.class.getName());
    props.put("clientConfigurationFile", emptyFile.toString());
    TJSONProtocol.Factory protocol = new TJSONProtocol.Factory();
    int proxyPort = PortUtils.getRandomFreePort();
    final TServer proxyServer = Proxy.createProxyServer(HostAndPort.fromParts("localhost", proxyPort), protocol, props).server;
    while (!proxyServer.isServing()) sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    Client client = new TestProxyClient("localhost", proxyPort, protocol).proxy();
    Map<String, String> properties = new TreeMap<>();
    properties.put("password", ROOT_PASSWORD);
    ByteBuffer login = client.login("root", properties);
    String tableName = getUniqueNames(1)[0];
    client.createTable(login, tableName, true, TimeType.MILLIS);
    assertTrue(c.tableOperations().exists(tableName));
    WriterOptions options = new WriterOptions();
    options.setDurability(Durability.NONE);
    String writer = client.createWriter(login, tableName, options);
    Map<ByteBuffer, List<ColumnUpdate>> cells = new TreeMap<>();
    ColumnUpdate column = new ColumnUpdate(bytes("cf"), bytes("cq"));
    column.setValue("value".getBytes());
    cells.put(bytes("row"), Collections.singletonList(column));
    client.update(writer, cells);
    client.closeWriter(writer);
    assertEquals(1, count(tableName));
    restartTServer();
    assertEquals(0, count(tableName));
    ConditionalWriterOptions cfg = new ConditionalWriterOptions();
    cfg.setDurability(Durability.SYNC);
    String cwriter = client.createConditionalWriter(login, tableName, cfg);
    ConditionalUpdates updates = new ConditionalUpdates();
    updates.addToConditions(new Condition(new Column(bytes("cf"), bytes("cq"), bytes(""))));
    updates.addToUpdates(column);
    Map<ByteBuffer, ConditionalStatus> status = client.updateRowsConditionally(cwriter, Collections.singletonMap(bytes("row"), updates));
    assertEquals(ConditionalStatus.ACCEPTED, status.get(bytes("row")));
    assertEquals(1, count(tableName));
    restartTServer();
    assertEquals(1, count(tableName));
    proxyServer.stop();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) TServer(org.apache.thrift.server.TServer) Properties(java.util.Properties) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) ConditionalUpdates(org.apache.accumulo.proxy.thrift.ConditionalUpdates) Column(org.apache.accumulo.proxy.thrift.Column) List(java.util.List) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) Condition(org.apache.accumulo.proxy.thrift.Condition) TreeMap(java.util.TreeMap) ByteBuffer(java.nio.ByteBuffer) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) ConditionalStatus(org.apache.accumulo.proxy.thrift.ConditionalStatus) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) File(java.io.File) Test(org.junit.Test)

Example 28 with TServer

use of org.apache.thrift.server.TServer in project mlib by myshzzx.

the class AsyncTest1 method test2.

@Test
public void test2() throws Exception {
    TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress("l", 19000), 0);
    TServer server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(new TService1.AsyncProcessor<TService1.AsyncIface>(new Service2Impl())).protocolFactory(new TCompactProtocol.Factory()));
    new Thread() {

        @Override
        public void run() {
            server.serve();
        }
    }.start();
    Thread.sleep(1000);
    TNonblockingSocket transport = new TNonblockingSocket("l", 19000, 5000);
    TService1.AsyncIface client = new TService1.AsyncClient(new TCompactProtocol.Factory(), new TAsyncClientManager(), transport);
    byte[] b = { 1, 2, 3 };
    AsyncMethodCallback<TService1.AsyncClient.getStr_call> h = new AsyncMethodCallback<TService1.AsyncClient.getStr_call>() {

        @Override
        public void onComplete(TService1.AsyncClient.getStr_call response) {
            try {
                System.out.println(response.getResult());
            } catch (TException e) {
                log.error("async get rsp fail.", e);
            }
        }

        @Override
        public void onError(Exception e) {
            log.error("async call fail.", e);
        }
    };
    for (int i = 0; i < 2; i++) {
        client.getStr("mysh", ByteBuffer.wrap(b), h);
    }
    Thread.sleep(10000000);
}
Also used : TException(org.apache.thrift.TException) TNonblockingSocket(org.apache.thrift.transport.TNonblockingSocket) TServer(org.apache.thrift.server.TServer) InetSocketAddress(java.net.InetSocketAddress) LoggerFactory(org.slf4j.LoggerFactory) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TAsyncClientManager(org.apache.thrift.async.TAsyncClientManager) THsHaServer(org.apache.thrift.server.THsHaServer) AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) TException(org.apache.thrift.TException) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) Test(org.junit.Test)

Example 29 with TServer

use of org.apache.thrift.server.TServer in project commons by twitter.

the class PingPongServer method run.

@Override
public void run() {
    PingPongHandler handler = new PingPongHandler();
    PingPong.Processor processor = new PingPong.Processor(handler);
    TServer server;
    try {
        TServerTransport transport = new TServerSocket(THRIFT_PORT.get());
        server = new TSimpleServer(processor, transport);
    } catch (TTransportException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Starting thrift server.");
    server.serve();
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) PingPong(com.twitter.common.examples.pingpong.PingPong) TTransportException(org.apache.thrift.transport.TTransportException) TSimpleServer(org.apache.thrift.server.TSimpleServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 30 with TServer

use of org.apache.thrift.server.TServer in project yyl_example by Relucent.

the class HelloServer method getSimpleServer.

/**
 * 简单的单线程服务模型,一般用于测试
 */
public static TServer getSimpleServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TServer server = new TSimpleServer(new TServer.Args(transport).processor(processor));
    return server;
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) TSimpleServer(org.apache.thrift.server.TSimpleServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Aggregations

TServer (org.apache.thrift.server.TServer)33 TServerSocket (org.apache.thrift.transport.TServerSocket)16 TProcessor (org.apache.thrift.TProcessor)12 TNonblockingServerSocket (org.apache.thrift.transport.TNonblockingServerSocket)11 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)9 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)9 Test (org.junit.Test)9 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)8 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)7 TThreadedSelectorServer (org.apache.thrift.server.TThreadedSelectorServer)7 TServerTransport (org.apache.thrift.transport.TServerTransport)7 TTransportFactory (org.apache.thrift.transport.TTransportFactory)7 InetSocketAddress (java.net.InetSocketAddress)6 TFramedTransport (org.apache.thrift.transport.TFramedTransport)6 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)5 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)5 TProtocol (org.apache.thrift.protocol.TProtocol)5 TTransport (org.apache.thrift.transport.TTransport)5 IOException (java.io.IOException)4 ServerSocket (java.net.ServerSocket)4