本文整理汇总了Java中org.apache.avro.ipc.Server类的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于org.apache.avro.ipc包,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testThreeParamBatchAppend
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testThreeParamBatchAppend() throws FlumeException,
EventDeliveryException {
int batchSize = 7;
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort(),
batchSize);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例2: testPropertiesBatchAppend
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testPropertiesBatchAppend() throws FlumeException,
EventDeliveryException {
int batchSize = 7;
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
Properties p = new Properties();
p.put("hosts", "host1");
p.put("hosts.host1", localhost + ":" + String.valueOf(server.getPort()));
p.put("batch-size", String.valueOf(batchSize));
client = RpcClientFactory.getInstance(p);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例3: testTwoParamBatchAppendOverflow
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testTwoParamBatchAppendOverflow() throws FlumeException,
EventDeliveryException {
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort());
int batchSize = client.getBatchSize();
int moreThanBatch = batchSize + 1;
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < moreThanBatch; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例4: testCreatingLbClientSingleHost
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test(expected = FlumeException.class)
public void testCreatingLbClientSingleHost() {
Server server1 = null;
RpcClient c = null;
try {
server1 = RpcTestUtils.startServer(new OKAvroHandler());
Properties p = new Properties();
p.put("host1", "127.0.0.1:" + server1.getPort());
p.put("hosts", "host1");
p.put("client.type", "default_loadbalance");
RpcClientFactory.getInstance(p);
} finally {
if (server1 != null) server1.close();
if (c != null) c.close();
}
}
示例5: handlerSimpleAppendTest
import org.apache.avro.ipc.Server; //导入依赖的package包/类
/**
* Helper method for testing simple (single) with compression level 6 appends on handlers
* @param handler
* @throws FlumeException
* @throws EventDeliveryException
*/
public static void handlerSimpleAppendTest(AvroSourceProtocol handler,
boolean enableServerCompression,
boolean enableClientCompression, int compressionLevel)
throws FlumeException, EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = startServer(handler, 0, enableServerCompression);
try {
Properties starterProp = new Properties();
if (enableClientCompression) {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "deflate");
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL,
"" + compressionLevel);
} else {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "none");
}
client = getStockLocalClient(server.getPort(), starterProp);
boolean isActive = client.isActive();
Assert.assertTrue("Client should be active", isActive);
client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
} finally {
stopServer(server);
if (client != null) client.close();
}
}
示例6: testServerDisconnect
import org.apache.avro.ipc.Server; //导入依赖的package包/类
/**
* First connect the client, then shut down the server, then send a request.
* @throws FlumeException
* @throws EventDeliveryException
* @throws InterruptedException
*/
@Test(expected = EventDeliveryException.class)
public void testServerDisconnect() throws FlumeException,
EventDeliveryException, InterruptedException {
NettyAvroRpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcTestUtils.getStockLocalClient(server.getPort());
server.close();
Thread.sleep(1000L); // wait a second for the close to occur
try {
server.join();
} catch (InterruptedException ex) {
logger.warn("Thread interrupted during join()", ex);
Thread.currentThread().interrupt();
}
try {
client.append(EventBuilder.withBody("hello", Charset.forName("UTF8")));
} finally {
Assert.assertFalse("Client should not be active", client.isActive());
}
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例7: testClientClosedRequest
import org.apache.avro.ipc.Server; //导入依赖的package包/类
/**
* First connect the client, then close the client, then send a request.
* @throws FlumeException
* @throws EventDeliveryException
*/
@Test(expected = EventDeliveryException.class)
public void testClientClosedRequest() throws FlumeException,
EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcTestUtils.getStockLocalClient(server.getPort());
client.close();
Assert.assertFalse("Client should not be active", client.isActive());
System.out.println("Yaya! I am not active after client close!");
client.append(EventBuilder.withBody("hello", Charset.forName("UTF8")));
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例8: testAppendWithMaxIOWorkers
import org.apache.avro.ipc.Server; //导入依赖的package包/类
/**
* configure the NettyAvroRpcClient with a non-default
* NioClientSocketChannelFactory number of io worker threads
*
* @throws FlumeException
* @throws EventDeliveryException
*/
@Test
public void testAppendWithMaxIOWorkers() throws FlumeException, EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
Properties props = new Properties();
props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, "localhost");
props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + "localhost", localhost
+ ":" + server.getPort());
props.setProperty(RpcClientConfigurationConstants.MAX_IO_WORKERS, Integer.toString(2));
try {
client = new NettyAvroRpcClient();
client.configure(props);
for (int i = 0; i < 5; i++) {
client.append(EventBuilder.withBody("evt:" + i, Charset.forName("UTF8")));
}
} finally {
RpcTestUtils.stopServer(server);
if (client != null) {
client.close();
}
}
}
示例9: testLifecycle
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testLifecycle() throws InterruptedException,
InstantiationException, IllegalAccessException {
setUp();
Server server = createServer(new MockAvroServer());
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例10: startTestFlumeServer
import org.apache.avro.ipc.Server; //导入依赖的package包/类
public static Server startTestFlumeServer(int port) {
Responder responder = new SpecificResponder(AvroSourceProtocol.class,
new OKAvroHandler());
Server server = new NettyServer(responder,
new InetSocketAddress("127.0.0.1", port));
server.start();
LOG.info("Server started on test flume server hostname: localhost, port: " + port);
try {
Thread.sleep(1000L);
} catch (InterruptedException ex) {
LOG.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
}
return server;
}
示例11: doExport
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url)
throws JahhanException {
log.info("impl => " + impl.getClass());
log.info("type => " + type.getName());
log.info("url => " + url);
final Server server = new NettyServer(new ReflectResponder(type, impl),
new InetSocketAddress(url.getHost(), url.getPort()));
server.start();
log.info("Start Avro Server");
return new Runnable() {
public void run() {
try {
log.info("Close Avro Server");
server.close();
} catch (Throwable e) {
log.warn(e.getMessage(), e);
}
}
};
}
示例12: testTwoParamSimpleAppend
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testTwoParamSimpleAppend() throws FlumeException,
EventDeliveryException {
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort());
client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例13: testTwoParamDeprecatedAppend
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testTwoParamDeprecatedAppend() throws FlumeException,
EventDeliveryException {
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getInstance(localhost, server.getPort());
client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例14: testThreeParamDeprecatedAppend
import org.apache.avro.ipc.Server; //导入依赖的package包/类
@Test
public void testThreeParamDeprecatedAppend() throws FlumeException,
EventDeliveryException {
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getInstance(localhost, server.getPort(), 3);
Assert.assertEquals("Batch size was specified", 3, client.getBatchSize());
client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例15: testFailedServers
import org.apache.avro.ipc.Server; //导入依赖的package包/类
/**
* Try writing to some servers and then kill them all.
*
* @throws FlumeException
* @throws EventDeliveryException
*/
@Test(
expected = EventDeliveryException.class)
public void testFailedServers() throws FlumeException, EventDeliveryException {
FailoverRpcClient client = null;
Server server1 = RpcTestUtils.startServer(new OKAvroHandler());
Server server2 = RpcTestUtils.startServer(new OKAvroHandler());
Server server3 = RpcTestUtils.startServer(new OKAvroHandler());
Properties props = new Properties();
props.put("client.type", "default_failover");
props.put("hosts", "host1 host2 host3");
props.put("hosts.host1", "localhost:" + String.valueOf(server1.getPort()));
props.put("hosts.host2", "localhost:" + String.valueOf(server2.getPort()));
props.put("hosts.host3", " localhost:" + String.valueOf(server3.getPort()));
client = (FailoverRpcClient) RpcClientFactory.getInstance(props);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < 50; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
server1.close();
server2.close();
server3.close();
events = new ArrayList<Event>();
for (int i = 0; i < 50; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
}