本文整理汇总了Java中org.apache.avro.ipc.Server.close方法的典型用法代码示例。如果您正苦于以下问题:Java Server.close方法的具体用法?Java Server.close怎么用?Java Server.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.ipc.Server
的用法示例。
在下文中一共展示了Server.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
示例4: 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);
}
}
};
}
示例5: 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);
}
示例6: testTwoHostFailover
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testTwoHostFailover() throws Exception {
Server s1 = null;
Server s2 = null;
RpcClient c = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
s2 = RpcTestUtils.startServer(h2);
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + s1.getPort());
p.put("hosts.h2", "127.0.0.1:" + s2.getPort());
c = RpcClientFactory.getInstance(p);
Assert.assertTrue(c instanceof LoadBalancingRpcClient);
for (int i = 0; i < 100; i++) {
if (i == 20) {
h2.setFailed();
} else if (i == 40) {
h2.setOK();
}
c.append(getEvent(i));
}
Assert.assertEquals(60, h1.getAppendCount());
Assert.assertEquals(40, h2.getAppendCount());
} finally {
if (s1 != null) s1.close();
if (s2 != null) s2.close();
if (c != null) c.close();
}
}
示例7: testTwoHostFailoverThrowAfterClose
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testTwoHostFailoverThrowAfterClose() throws Exception {
Server s1 = null;
Server s2 = null;
RpcClient c = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
s2 = RpcTestUtils.startServer(h2);
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + s1.getPort());
p.put("hosts.h2", "127.0.0.1:" + s2.getPort());
c = RpcClientFactory.getInstance(p);
Assert.assertTrue(c instanceof LoadBalancingRpcClient);
for (int i = 0; i < 100; i++) {
if (i == 20) {
h2.setFailed();
} else if (i == 40) {
h2.setOK();
}
c.append(getEvent(i));
}
Assert.assertEquals(60, h1.getAppendCount());
Assert.assertEquals(40, h2.getAppendCount());
if (c != null) c.close();
c.append(getEvent(3));
Assert.fail();
} finally {
if (s1 != null) s1.close();
if (s2 != null) s2.close();
}
}
示例8: testTwoHostFailoverBatch
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testTwoHostFailoverBatch() throws Exception {
Server s1 = null;
Server s2 = null;
RpcClient c = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
s2 = RpcTestUtils.startServer(h2);
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + s1.getPort());
p.put("hosts.h2", "127.0.0.1:" + s2.getPort());
c = RpcClientFactory.getInstance(p);
Assert.assertTrue(c instanceof LoadBalancingRpcClient);
for (int i = 0; i < 100; i++) {
if (i == 20) {
h2.setFailed();
} else if (i == 40) {
h2.setOK();
}
c.appendBatch(getBatchedEvent(i));
}
Assert.assertEquals(60, h1.getAppendBatchCount());
Assert.assertEquals(40, h2.getAppendBatchCount());
} finally {
if (s1 != null) s1.close();
if (s2 != null) s2.close();
if (c != null) c.close();
}
}
示例9: testLbDefaultClientTwoHosts
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testLbDefaultClientTwoHosts() throws Exception {
Server s1 = null;
Server s2 = null;
RpcClient c = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
s2 = RpcTestUtils.startServer(h2);
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + s1.getPort());
p.put("hosts.h2", "127.0.0.1:" + s2.getPort());
c = RpcClientFactory.getInstance(p);
Assert.assertTrue(c instanceof LoadBalancingRpcClient);
for (int i = 0; i < 100; i++) {
c.append(getEvent(i));
}
Assert.assertEquals(50, h1.getAppendCount());
Assert.assertEquals(50, h2.getAppendCount());
} finally {
if (s1 != null) s1.close();
if (s2 != null) s2.close();
if (c != null) c.close();
}
}
示例10: testLbDefaultClientTwoHostsBatch
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testLbDefaultClientTwoHostsBatch() throws Exception {
Server s1 = null;
Server s2 = null;
RpcClient c = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
s2 = RpcTestUtils.startServer(h2);
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + s1.getPort());
p.put("hosts.h2", "127.0.0.1:" + s2.getPort());
c = RpcClientFactory.getInstance(p);
Assert.assertTrue(c instanceof LoadBalancingRpcClient);
for (int i = 0; i < 100; i++) {
c.appendBatch(getBatchedEvent(i));
}
Assert.assertEquals(50, h1.getAppendBatchCount());
Assert.assertEquals(50, h2.getAppendBatchCount());
} finally {
if (s1 != null) s1.close();
if (s2 != null) s2.close();
if (c != null) c.close();
}
}
示例11: stopServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
/**
* Request that the specified Server stop, and attempt to wait for it to exit.
* @param server A running NettyServer
*/
public static void stopServer(Server server) {
try {
server.close();
server.join();
} catch (InterruptedException ex) {
logger.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
}
}
示例12: testProcess
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
@Test
public void testProcess() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createServer(new MockAvroServer());
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
for (int i = 0; i < 5; i++) {
Sink.Status status = sink.process();
Assert.assertEquals(Sink.Status.READY, status);
}
Assert.assertEquals(Sink.Status.BACKOFF, sink.process());
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
}
示例13: stopTestFlumeServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
public static void stopTestFlumeServer(Server server) {
try {
server.close();
server.join();
} catch (InterruptedException ex) {
LOG.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
}
}
示例14: stopServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
public static void stopServer(Server server) {
try {
server.close();
server.join();
} catch (InterruptedException ex) {
LOG.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
}
}
示例15: stopServer
import org.apache.avro.ipc.Server; //导入方法依赖的package包/类
public static void stopServer(Server server) {
try {
server.close();
server.join();
} catch (InterruptedException ex) {
logger.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
}
}