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);
}
}
}
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();
}
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);
}
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();
}
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;
}
Aggregations