Java 类org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos 实例源码

项目:pbase    文件:TestSecureRPC.java   
/**
 * To run this test, we must specify the following system properties:
 *<p>
 * <b> hbase.regionserver.kerberos.principal </b>
 * <p>
 * <b> hbase.regionserver.keytab.file </b>
 */
@Test
public void testRpcCallWithEnabledKerberosSaslAuth() throws Exception {
  assumeTrue(isKerberosPropertySetted());
  String krbKeytab = getKeytabFileForTesting();
  String krbPrincipal = getPrincipalForTesting();

  Configuration cnf = new Configuration();
  cnf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(cnf);
  UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab);
  UserGroupInformation ugi = UserGroupInformation.getLoginUser();
  UserGroupInformation ugi2 = UserGroupInformation.getCurrentUser();

  // check that the login user is okay:
  assertSame(ugi, ugi2);
  assertEquals(AuthenticationMethod.KERBEROS, ugi.getAuthenticationMethod());
  assertEquals(krbPrincipal, ugi.getUserName());

  Configuration conf = getSecuredConfiguration();

  SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
  Mockito.when(securityInfoMock.getServerPrincipal())
    .thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
  SecurityInfo.addInfo("TestDelayedService", securityInfoMock);

  boolean delayReturnValue = false;
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
      TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);

  rpcServer = new RpcServer(null, "testSecuredDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
        isa, conf, new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = RpcClientFactory
      .createClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), 1000);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    TestThread th1 = new TestThread(stub, true, results);
    th1.start();
    Thread.sleep(100);
    th1.join();

    assertEquals(0xDEADBEEF, results.get(0).intValue());
  } finally {
    rpcClient.close();
  }
}
项目:pbase    文件:TestDelayedRpc.java   
private void testDelayedRpc(boolean delayReturnValue) throws Exception {
  LOG.info("Running testDelayedRpc delayReturnValue=" + delayReturnValue);
  Configuration conf = HBaseConfiguration.create();
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = RpcClientFactory.createClient(
      conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    // Setting true sets 'delayed' on the client.
    TestThread th1 = new TestThread(stub, true, results);
    // Setting 'false' means we will return UNDELAYED as response immediately.
    TestThread th2 = new TestThread(stub, false, results);
    TestThread th3 = new TestThread(stub, false, results);
    th1.start();
    Thread.sleep(100);
    th2.start();
    Thread.sleep(200);
    th3.start();

    th1.join();
    th2.join();
    th3.join();

    // We should get the two undelayed responses first.
    assertEquals(UNDELAYED, results.get(0).intValue());
    assertEquals(UNDELAYED, results.get(1).intValue());
    assertEquals(results.get(2).intValue(), delayReturnValue ? DELAYED :  0xDEADBEEF);
  } finally {
    rpcClient.close();
  }
}
项目:pbase    文件:TestDelayedRpc.java   
/**
 * Tests that we see a WARN message in the logs.
 * @throws Exception
 */
@Test (timeout=60000)
public void testTooManyDelayedRpcs() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  final int MAX_DELAYED_RPC = 10;
  conf.setInt("hbase.ipc.warn.delayedrpc.number", MAX_DELAYED_RPC);
  // Set up an appender to catch the "Too many delayed calls" that we expect.
  ListAppender listAppender = new ListAppender();
  Logger log = Logger.getLogger(RpcServer.class);
  log.addAppender(listAppender);
  log.setLevel(Level.WARN);


  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(true);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testTooManyDelayedRpcs",
    Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = RpcClientFactory.createClient(
      conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    Thread threads[] = new Thread[MAX_DELAYED_RPC + 1];
    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i] = new TestThread(stub, true, null);
      threads[i].start();
    }

    /* No warnings till here. */
    assertTrue(listAppender.getMessages().isEmpty());

    /* This should give a warning. */
    threads[MAX_DELAYED_RPC] = new TestThread(stub, true, null);
    threads[MAX_DELAYED_RPC].start();

    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i].join();
    }

    assertFalse(listAppender.getMessages().isEmpty());
    assertTrue(listAppender.getMessages().get(0).startsWith("Too many delayed calls"));

    log.removeAppender(listAppender);
  } finally {
    rpcClient.close();
  }
}
项目:pbase    文件:TestDelayedRpc.java   
public TestThread(TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub,
    boolean delay, List<Integer> results) {
  this.stub = stub;
  this.delay = delay;
  this.results = results;
}
项目:HIndex    文件:TestSecureRPC.java   
/**
 * To run this test, we must specify the following system properties:
 *<p>
 * <b> hbase.regionserver.kerberos.principal </b>
 * <p>
 * <b> hbase.regionserver.keytab.file </b>
 */
@Test
public void testRpcCallWithEnabledKerberosSaslAuth() throws Exception {
  assumeTrue(isKerberosPropertySetted());
  String krbKeytab = getKeytabFileForTesting();
  String krbPrincipal = getPrincipalForTesting();

  Configuration cnf = new Configuration();
  cnf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(cnf);
  UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab);
  UserGroupInformation ugi = UserGroupInformation.getLoginUser();
  UserGroupInformation ugi2 = UserGroupInformation.getCurrentUser();

  // check that the login user is okay:
  assertSame(ugi, ugi2);
  assertEquals(AuthenticationMethod.KERBEROS, ugi.getAuthenticationMethod());
  assertEquals(krbPrincipal, ugi.getUserName());

  Configuration conf = getSecuredConfiguration();

  SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
  Mockito.when(securityInfoMock.getServerPrincipal())
    .thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
  SecurityInfo.addInfo("TestDelayedService", securityInfoMock);

  boolean delayReturnValue = false;
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
      TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);

  rpcServer = new RpcServer(null, "testSecuredDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
        isa, conf, new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), 1000);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    TestThread th1 = new TestThread(stub, true, results);
    th1.start();
    Thread.sleep(100);
    th1.join();

    assertEquals(0xDEADBEEF, results.get(0).intValue());
  } finally {
    rpcClient.stop();
  }
}
项目:HIndex    文件:TestDelayedRpc.java   
private void testDelayedRpc(boolean delayReturnValue) throws Exception {
  LOG.info("Running testDelayedRpc delayReturnValue=" + delayReturnValue);
  Configuration conf = HBaseConfiguration.create();
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    // Setting true sets 'delayed' on the client.
    TestThread th1 = new TestThread(stub, true, results);
    // Setting 'false' means we will return UNDELAYED as response immediately.
    TestThread th2 = new TestThread(stub, false, results);
    TestThread th3 = new TestThread(stub, false, results);
    th1.start();
    Thread.sleep(100);
    th2.start();
    Thread.sleep(200);
    th3.start();

    th1.join();
    th2.join();
    th3.join();

    // We should get the two undelayed responses first.
    assertEquals(UNDELAYED, results.get(0).intValue());
    assertEquals(UNDELAYED, results.get(1).intValue());
    assertEquals(results.get(2).intValue(), delayReturnValue ? DELAYED :  0xDEADBEEF);
  } finally {
    rpcClient.stop();
  }
}
项目:HIndex    文件:TestDelayedRpc.java   
/**
 * Tests that we see a WARN message in the logs.
 * @throws Exception
 */
@Test (timeout=60000)
public void testTooManyDelayedRpcs() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  final int MAX_DELAYED_RPC = 10;
  conf.setInt("hbase.ipc.warn.delayedrpc.number", MAX_DELAYED_RPC);
  // Set up an appender to catch the "Too many delayed calls" that we expect.
  ListAppender listAppender = new ListAppender();
  Logger log = Logger.getLogger("org.apache.hadoop.ipc.RpcServer");
  log.addAppender(listAppender);
  log.setLevel(Level.WARN);


  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(true);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testTooManyDelayedRpcs",
    Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    Thread threads[] = new Thread[MAX_DELAYED_RPC + 1];
    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i] = new TestThread(stub, true, null);
      threads[i].start();
    }

    /* No warnings till here. */
    assertTrue(listAppender.getMessages().isEmpty());

    /* This should give a warning. */
    threads[MAX_DELAYED_RPC] = new TestThread(stub, true, null);
    threads[MAX_DELAYED_RPC].start();

    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i].join();
    }

    assertFalse(listAppender.getMessages().isEmpty());
    assertTrue(listAppender.getMessages().get(0).startsWith("Too many delayed calls"));

    log.removeAppender(listAppender);
  } finally {
    rpcClient.stop();
  }
}
项目:HIndex    文件:TestDelayedRpc.java   
public TestThread(TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub,
    boolean delay, List<Integer> results) {
  this.stub = stub;
  this.delay = delay;
  this.results = results;
}
项目:PyroDB    文件:TestSecureRPC.java   
/**
 * To run this test, we must specify the following system properties:
 *<p>
 * <b> hbase.regionserver.kerberos.principal </b>
 * <p>
 * <b> hbase.regionserver.keytab.file </b>
 */
@Test
public void testRpcCallWithEnabledKerberosSaslAuth() throws Exception {
  assumeTrue(isKerberosPropertySetted());
  String krbKeytab = getKeytabFileForTesting();
  String krbPrincipal = getPrincipalForTesting();

  Configuration cnf = new Configuration();
  cnf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(cnf);
  UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab);
  UserGroupInformation ugi = UserGroupInformation.getLoginUser();
  UserGroupInformation ugi2 = UserGroupInformation.getCurrentUser();

  // check that the login user is okay:
  assertSame(ugi, ugi2);
  assertEquals(AuthenticationMethod.KERBEROS, ugi.getAuthenticationMethod());
  assertEquals(krbPrincipal, ugi.getUserName());

  Configuration conf = getSecuredConfiguration();

  SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
  Mockito.when(securityInfoMock.getServerPrincipal())
    .thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
  SecurityInfo.addInfo("TestDelayedService", securityInfoMock);

  boolean delayReturnValue = false;
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
      TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);

  rpcServer = new RpcServer(null, "testSecuredDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
        isa, conf, new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), 1000);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    TestThread th1 = new TestThread(stub, true, results);
    th1.start();
    Thread.sleep(100);
    th1.join();

    assertEquals(0xDEADBEEF, results.get(0).intValue());
  } finally {
    rpcClient.stop();
  }
}
项目:PyroDB    文件:TestDelayedRpc.java   
private void testDelayedRpc(boolean delayReturnValue) throws Exception {
  LOG.info("Running testDelayedRpc delayReturnValue=" + delayReturnValue);
  Configuration conf = HBaseConfiguration.create();
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    // Setting true sets 'delayed' on the client.
    TestThread th1 = new TestThread(stub, true, results);
    // Setting 'false' means we will return UNDELAYED as response immediately.
    TestThread th2 = new TestThread(stub, false, results);
    TestThread th3 = new TestThread(stub, false, results);
    th1.start();
    Thread.sleep(100);
    th2.start();
    Thread.sleep(200);
    th3.start();

    th1.join();
    th2.join();
    th3.join();

    // We should get the two undelayed responses first.
    assertEquals(UNDELAYED, results.get(0).intValue());
    assertEquals(UNDELAYED, results.get(1).intValue());
    assertEquals(results.get(2).intValue(), delayReturnValue ? DELAYED :  0xDEADBEEF);
  } finally {
    rpcClient.stop();
  }
}
项目:PyroDB    文件:TestDelayedRpc.java   
/**
 * Tests that we see a WARN message in the logs.
 * @throws Exception
 */
@Test (timeout=60000)
public void testTooManyDelayedRpcs() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  final int MAX_DELAYED_RPC = 10;
  conf.setInt("hbase.ipc.warn.delayedrpc.number", MAX_DELAYED_RPC);
  // Set up an appender to catch the "Too many delayed calls" that we expect.
  ListAppender listAppender = new ListAppender();
  Logger log = Logger.getLogger("org.apache.hadoop.ipc.RpcServer");
  log.addAppender(listAppender);
  log.setLevel(Level.WARN);


  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(true);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testTooManyDelayedRpcs",
    Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa,
      conf,
      new FifoRpcScheduler(conf, 1));
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    Thread threads[] = new Thread[MAX_DELAYED_RPC + 1];
    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i] = new TestThread(stub, true, null);
      threads[i].start();
    }

    /* No warnings till here. */
    assertTrue(listAppender.getMessages().isEmpty());

    /* This should give a warning. */
    threads[MAX_DELAYED_RPC] = new TestThread(stub, true, null);
    threads[MAX_DELAYED_RPC].start();

    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i].join();
    }

    assertFalse(listAppender.getMessages().isEmpty());
    assertTrue(listAppender.getMessages().get(0).startsWith("Too many delayed calls"));

    log.removeAppender(listAppender);
  } finally {
    rpcClient.stop();
  }
}
项目:PyroDB    文件:TestDelayedRpc.java   
public TestThread(TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub,
    boolean delay, List<Integer> results) {
  this.stub = stub;
  this.delay = delay;
  this.results = results;
}
项目:c5    文件:TestDelayedRpc.java   
private void testDelayedRpc(boolean delayReturnValue) throws Exception {
  LOG.info("Running testDelayedRpc delayReturnValue=" + delayReturnValue);
  Configuration conf = HBaseConfiguration.create();
  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testDelayedRpc",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa, 1, 0, conf, 0);
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    List<Integer> results = new ArrayList<Integer>();
    // Setting true sets 'delayed' on the client.
    TestThread th1 = new TestThread(stub, true, results);
    // Setting 'false' means we will return UNDELAYED as response immediately.
    TestThread th2 = new TestThread(stub, false, results);
    TestThread th3 = new TestThread(stub, false, results);
    th1.start();
    Thread.sleep(100);
    th2.start();
    Thread.sleep(200);
    th3.start();

    th1.join();
    th2.join();
    th3.join();

    // We should get the two undelayed responses first.
    assertEquals(UNDELAYED, results.get(0).intValue());
    assertEquals(UNDELAYED, results.get(1).intValue());
    assertEquals(results.get(2).intValue(), delayReturnValue ? DELAYED :  0xDEADBEEF);
  } finally {
    rpcClient.stop();
  }
}
项目:c5    文件:TestDelayedRpc.java   
/**
 * Tests that we see a WARN message in the logs.
 * @throws Exception
 */
@Test (timeout=60000)
public void testTooManyDelayedRpcs() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  final int MAX_DELAYED_RPC = 10;
  conf.setInt("hbase.ipc.warn.delayedrpc.number", MAX_DELAYED_RPC);
  // Set up an appender to catch the "Too many delayed calls" that we expect.
  ListAppender listAppender = new ListAppender();
  Logger log = Logger.getLogger("org.apache.hadoop.ipc.RpcServer");
  log.addAppender(listAppender);
  log.setLevel(Level.WARN);


  InetSocketAddress isa = new InetSocketAddress("localhost", 0);
  TestDelayedImplementation instance = new TestDelayedImplementation(true);
  BlockingService service =
    TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
  rpcServer = new RpcServer(null, "testTooManyDelayedRpcs",
    Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
      isa, 1, 0, conf, 0);
  rpcServer.start();
  RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
  try {
    BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
        ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
            rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
        User.getCurrent(), RPC_CLIENT_TIMEOUT);
    TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
      TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
    Thread threads[] = new Thread[MAX_DELAYED_RPC + 1];
    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i] = new TestThread(stub, true, null);
      threads[i].start();
    }

    /* No warnings till here. */
    assertTrue(listAppender.getMessages().isEmpty());

    /* This should give a warning. */
    threads[MAX_DELAYED_RPC] = new TestThread(stub, true, null);
    threads[MAX_DELAYED_RPC].start();

    for (int i = 0; i < MAX_DELAYED_RPC; i++) {
      threads[i].join();
    }

    assertFalse(listAppender.getMessages().isEmpty());
    assertTrue(listAppender.getMessages().get(0).startsWith("Too many delayed calls"));

    log.removeAppender(listAppender);
  } finally {
    rpcClient.stop();
  }
}
项目:c5    文件:TestDelayedRpc.java   
public TestThread(TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub,
    boolean delay, List<Integer> results) {
  this.stub = stub;
  this.delay = delay;
  this.results = results;
}