コード例 #1
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
  /** Test that, if the socket factory throws an IOE, it properly propagates to the client. */
  public void testSocketFactoryException() throws Exception {
    SocketFactory mockFactory = mock(SocketFactory.class);
    doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
    Client client = new Client(LongWritable.class, conf, mockFactory);

    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
    try {
      client.call(new LongWritable(RANDOM.nextLong()), address, null, null);
      fail("Expected an exception to have been thrown");
    } catch (IOException e) {
      assertTrue(e.getMessage().contains("Injected fault"));
    }
  }
コード例 #2
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
 public void testStandAloneClient() throws Exception {
   testParallel(10, false, 2, 4, 2, 4, 100);
   Client client = new Client(LongWritable.class, conf);
   InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
   try {
     client.call(new LongWritable(RANDOM.nextLong()), address, null, null);
     fail("Expected an exception to have been thrown");
   } catch (IOException e) {
     String message = e.getMessage();
     String addressText = address.toString();
     assertTrue("Did not find " + addressText + " in " + message, message.contains(addressText));
     Throwable cause = e.getCause();
     assertNotNull("No nested exception in " + e, cause);
     String causeText = cause.getMessage();
     assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText));
   }
 }
コード例 #3
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
  public void testErrorClient() throws Exception {
    // start server
    Server server = new TestServer(1, false);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();

    // start client
    Client client = new Client(LongErrorWritable.class, conf);
    try {
      client.call(new LongErrorWritable(RANDOM.nextLong()), addr, null, null);
      fail("Expected an exception to have been thrown");
    } catch (IOException e) {
      // check error
      Throwable cause = e.getCause();
      assertTrue(cause instanceof IOException);
      assertEquals(LongErrorWritable.ERR_MSG, cause.getMessage());
    }
  }
コード例 #4
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
 public void run() {
   for (int i = 0; i < count; i++) {
     try {
       LongWritable param = new LongWritable(RANDOM.nextLong());
       LongWritable value = (LongWritable) client.call(param, server, null, null);
       if (!param.equals(value)) {
         LOG.fatal("Call failed!");
         failed = true;
         break;
       }
     } catch (Exception e) {
       LOG.fatal("Caught: " + StringUtils.stringifyException(e));
       failed = true;
     }
   }
 }
コード例 #5
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
 public void run() {
   for (int i = 0; i < count; i++) {
     try {
       Writable[] params = new Writable[addresses.length];
       for (int j = 0; j < addresses.length; j++)
         params[j] = new LongWritable(RANDOM.nextLong());
       Writable[] values = client.call(params, addresses, null, null);
       for (int j = 0; j < addresses.length; j++) {
         if (!params[j].equals(values[j])) {
           LOG.fatal("Call failed!");
           failed = true;
           break;
         }
       }
     } catch (Exception e) {
       LOG.fatal("Caught: " + StringUtils.stringifyException(e));
       failed = true;
     }
   }
 }
コード例 #6
0
ファイル: TestIPC.java プロジェクト: Ronald33/hadoop-0.21
 static {
   Client.setPingInterval(conf, PING_INTERVAL);
 }