当前位置: 首页>>代码示例>>Java>>正文


Java Call类代码示例

本文整理汇总了Java中org.apache.hadoop.ipc.Server.Call的典型用法代码示例。如果您正苦于以下问题:Java Call类的具体用法?Java Call怎么用?Java Call使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Call类属于org.apache.hadoop.ipc.Server包,在下文中一共展示了Call类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLogExceptions

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
@Test (timeout=300000)
public void testLogExceptions() throws Exception {
  final Configuration conf = new Configuration();
  final Call dummyCall = new Call(0, 0, null, null);
  Log logger = mock(Log.class);
  Server server = new Server("0.0.0.0", 0, LongWritable.class, 1, conf) {
    @Override
    public Writable call(
        RPC.RpcKind rpcKind, String protocol, Writable param,
        long receiveTime) throws Exception {
      return null;
    }
  };
  server.addSuppressedLoggingExceptions(TestException1.class);
  server.addTerseExceptions(TestException2.class);

  // Nothing should be logged for a suppressed exception.
  server.logException(logger, new TestException1(), dummyCall);
  verifyZeroInteractions(logger);

  // No stack trace should be logged for a terse exception.
  server.logException(logger, new TestException2(), dummyCall);
  verify(logger, times(1)).info(anyObject());

  // Full stack trace should be logged for other exceptions.
  final Throwable te3 = new TestException3();
  server.logException(logger, te3, dummyCall);
  verify(logger, times(1)).info(anyObject(), eq(te3));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:30,代码来源:TestServer.java

示例2: echoPostponed

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
@Override
public String echoPostponed(String value) {
  Call call = Server.getCurCall().get();
  call.postponeResponse();
  postponedCalls.add(call);
  return value;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:8,代码来源:TestSaslRPC.java

示例3: sendPostponed

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
@Override
public void sendPostponed() throws IOException {
  Collections.shuffle(postponedCalls);
  for (Call call : postponedCalls) {
    call.sendResponse();
  }
  postponedCalls.clear();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:9,代码来源:TestSaslRPC.java

示例4: testCallIdAndRetry

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
/**
 * Test if
 * (1) the rpc server uses the call id/retry provided by the rpc client, and
 * (2) the rpc client receives the same call id/retry from the rpc server.
 */
@Test(timeout=60000)
public void testCallIdAndRetry() throws IOException {
  final CallInfo info = new CallInfo();

  // Override client to store the call info and check response
  final Client client = new Client(LongWritable.class, conf) {
    @Override
    Call createCall(RpcKind rpcKind, Writable rpcRequest) {
      final Call call = super.createCall(rpcKind, rpcRequest);
      info.id = call.id;
      info.retry = call.retry;
      return call;
    }
    
    @Override
    void checkResponse(RpcResponseHeaderProto header) throws IOException {
      super.checkResponse(header);
      Assert.assertEquals(info.id, header.getCallId());
      Assert.assertEquals(info.retry, header.getRetryCount());
    }
  };

  // Attach a listener that tracks every call received by the server.
  final TestServer server = new TestServer(1, false);
  server.callListener = new Runnable() {
    @Override
    public void run() {
      Assert.assertEquals(info.id, Server.getCallId());
      Assert.assertEquals(info.retry, Server.getCallRetryCount());
    }
  };

  try {
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();
    final SerialCaller caller = new SerialCaller(client, addr, 10);
    caller.run();
    assertFalse(caller.failed);
  } finally {
    client.stop();
    server.stop();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:49,代码来源:TestIPC.java

示例5: testClientBackOff

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
/**
 *  Test RPC backoff.
 */
@Test (timeout=30000)
public void testClientBackOff() throws Exception {
  Server server;
  final TestRpcService proxy;

  boolean succeeded = false;
  final int numClients = 2;
  final List<Future<Void>> res = new ArrayList<Future<Void>>();
  final ExecutorService executorService =
      Executors.newFixedThreadPool(numClients);
  conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
  conf.setBoolean(CommonConfigurationKeys.IPC_CALLQUEUE_NAMESPACE +
      ".0." + CommonConfigurationKeys.IPC_BACKOFF_ENABLE, true);
  RPC.Builder builder = newServerBuilder(conf)
      .setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
  server = setupTestServer(builder);

  @SuppressWarnings("unchecked")
  CallQueueManager<Call> spy = spy((CallQueueManager<Call>) Whitebox
      .getInternalState(server, "callQueue"));
  Whitebox.setInternalState(server, "callQueue", spy);

  Exception lastException = null;
  proxy = getClient(addr, conf);
  try {
    // start a sleep RPC call to consume the only handler thread.
    // Start another sleep RPC call to make callQueue full.
    // Start another sleep RPC call to make reader thread block on CallQueue.
    for (int i = 0; i < numClients; i++) {
      res.add(executorService.submit(
          new Callable<Void>() {
            @Override
            public Void call() throws ServiceException, InterruptedException {
              proxy.sleep(null, newSleepRequest(100000));
              return null;
            }
          }));
      verify(spy, timeout(500).times(i + 1)).offer(Mockito.<Call>anyObject());
    }
    try {
      proxy.sleep(null, newSleepRequest(100));
    } catch (ServiceException e) {
      RemoteException re = (RemoteException) e.getCause();
      IOException unwrapExeption = re.unwrapRemoteException();
      if (unwrapExeption instanceof RetriableException) {
        succeeded = true;
      } else {
        lastException = unwrapExeption;
      }
    }
  } finally {
    executorService.shutdown();
    stop(server, proxy);
  }
  if (lastException != null) {
    LOG.error("Last received non-RetriableException:", lastException);
  }
  assertTrue("RetriableException not received", succeeded);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:63,代码来源:TestRPC.java

示例6: testClientBackOff

import org.apache.hadoop.ipc.Server.Call; //导入依赖的package包/类
/**
 *  Test RPC backoff by queue full.
 */
@Test (timeout=30000)
public void testClientBackOff() throws Exception {
  Server server;
  final TestRpcService proxy;

  boolean succeeded = false;
  final int numClients = 2;
  final List<Future<Void>> res = new ArrayList<Future<Void>>();
  final ExecutorService executorService =
      Executors.newFixedThreadPool(numClients);
  conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
  conf.setBoolean(CommonConfigurationKeys.IPC_NAMESPACE +
      ".0." + CommonConfigurationKeys.IPC_BACKOFF_ENABLE, true);
  RPC.Builder builder = newServerBuilder(conf)
      .setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
  server = setupTestServer(builder);

  @SuppressWarnings("unchecked")
  CallQueueManager<Call> spy = spy((CallQueueManager<Call>) Whitebox
      .getInternalState(server, "callQueue"));
  Whitebox.setInternalState(server, "callQueue", spy);

  Exception lastException = null;
  proxy = getClient(addr, conf);
  try {
    // start a sleep RPC call to consume the only handler thread.
    // Start another sleep RPC call to make callQueue full.
    // Start another sleep RPC call to make reader thread block on CallQueue.
    for (int i = 0; i < numClients; i++) {
      res.add(executorService.submit(
          new Callable<Void>() {
            @Override
            public Void call() throws ServiceException, InterruptedException {
              proxy.sleep(null, newSleepRequest(100000));
              return null;
            }
          }));
    }
    while (server.getCallQueueLen() != 1
        && countThreads(CallQueueManager.class.getName()) != 1) {
      Thread.sleep(100);
    }
    try {
      proxy.sleep(null, newSleepRequest(100));
    } catch (ServiceException e) {
      RemoteException re = (RemoteException) e.getCause();
      IOException unwrapExeption = re.unwrapRemoteException();
      if (unwrapExeption instanceof RetriableException) {
        succeeded = true;
      } else {
        lastException = unwrapExeption;
      }
    }
  } finally {
    executorService.shutdown();
    stop(server, proxy);
  }
  assertTrue("RetriableException not received", succeeded);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:63,代码来源:TestRPC.java


注:本文中的org.apache.hadoop.ipc.Server.Call类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。