當前位置: 首頁>>代碼示例>>Java>>正文


Java NewProtobufRpcProto類代碼示例

本文整理匯總了Java中org.apache.hadoop.ipc.protobuf.TestRpcServiceProtos.NewProtobufRpcProto的典型用法代碼示例。如果您正苦於以下問題:Java NewProtobufRpcProto類的具體用法?Java NewProtobufRpcProto怎麽用?Java NewProtobufRpcProto使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NewProtobufRpcProto類屬於org.apache.hadoop.ipc.protobuf.TestRpcServiceProtos包,在下文中一共展示了NewProtobufRpcProto類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testProtocolVersionMismatch

import org.apache.hadoop.ipc.protobuf.TestRpcServiceProtos.NewProtobufRpcProto; //導入依賴的package包/類
@Test
public void testProtocolVersionMismatch() throws IOException, ServiceException {
  conf = new Configuration();
  conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
  // Set RPC engine to protobuf RPC engine
  RPC.setProtocolEngine(conf, NewRpcService.class, ProtobufRpcEngine.class);

  // Create server side implementation
  NewServerImpl serverImpl = new NewServerImpl();
  BlockingService service = NewProtobufRpcProto
      .newReflectiveBlockingService(serverImpl);
  // Get RPC server for server side implementation
  server = new RPC.Builder(conf).setProtocol(NewRpcService.class)
      .setInstance(service).setBindAddress(ADDRESS).setPort(PORT).build();
  addr = NetUtils.getConnectAddress(server);

  server.start();

  RPC.setProtocolEngine(conf, OldRpcService.class, ProtobufRpcEngine.class);

  OldRpcService proxy = RPC.getProxy(OldRpcService.class, 0, addr, conf);
  // Verify that exception is thrown if protocolVersion is mismatch between
  // client and server.
  EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build();
  try {
    proxy.ping(null, emptyRequest);
    fail("Expected an exception to occur as version mismatch.");
  } catch (Exception e) {
    if (! (e.getMessage().contains("version mismatch"))){
      // Exception type is not what we expected, re-throw it.
      throw new IOException(e);
    }
  }

  // Verify that missing of optional field is still compatible in RPC call.
  RPC.setProtocolEngine(conf, NewerRpcService.class, ProtobufRpcEngine.class);
  NewerRpcService newProxy = RPC.getProxy(NewerRpcService.class, 0, addr,
      conf);
  newProxy.echo(null, emptyRequest);

}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:42,代碼來源:TestProtoBufRPCCompatibility.java


注:本文中的org.apache.hadoop.ipc.protobuf.TestRpcServiceProtos.NewProtobufRpcProto類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。