@Test(groups = {"ueber", "performance"})
  public void threadSafeTest() throws Exception {
    final MessageSenderManager msm = new MessageSenderManager();
    msm.setSenderPoolSize(SENDER_COUNT);
    msm.setSenderClass(SENDER_CLASS_NAME);
    msm.init();

    final Map<Runnable, Throwable> threads = new HashMap<Runnable, Throwable>();
    final ExecutorService es = Executors.newFixedThreadPool(THREAD_COUNT);

    for (int i = 0; i < SENDER_TASK_COUNT; i++) {
      final Runnable senderTask = new SenderTask(msm, threads);
      threads.put(senderTask, null);
      es.submit(senderTask);
    }
    es.shutdown();
    es.awaitTermination(
        (long) (SENDER_TASK_COUNT * THREAD_SLEEP_MILLIS * 1.2), TimeUnit.MILLISECONDS);
    assertTrue(es.isTerminated());
    assertTrue(es.isShutdown());
    final Iterator<Runnable> it = threads.keySet().iterator();
    while (it.hasNext()) {
      final Throwable t = threads.get(it.next());
      if (t != null) {
        fail("One of the threads threw following exception: " + t.getMessage());
      }
    }
    msm.close();
  }
Beispiel #2
0
 // Test that an exception thrown while handling a successful async connection get reported
 // as a failure on the client future.
 @Test
 public void testClientCreateFailure()
     throws InterruptedException, ExecutionException, TTransportException {
   try {
     createClient(MalformedService.class, syncServer).get();
     fail("Should not be able to successfully create a client for MalformedService.class");
   } catch (ExecutionException e) {
     Throwable rootCause = Throwables.getRootCause(e);
     assertTrue(rootCause instanceof IllegalArgumentException);
     assertTrue(rootCause.getMessage().startsWith("Type can not be coerced to a Thrift type"));
   }
 }
Beispiel #3
0
  /**
   * Verify that a {@link Throwable} is a {@link TTransportException} wrapping the expected cause
   *
   * @param throwable The {@link Throwable} to check
   * @param expectedCause The expected cause of the {@link TTransportException}
   */
  private void checkTransportException(
      Throwable throwable, Class<? extends Throwable> expectedCause) {
    assertNotNull(throwable);
    Throwable cause = throwable.getCause();

    if (!(throwable instanceof TTransportException)) {
      fail("Exception of type " + throwable.getClass() + " when expecting a TTransportException");
    } else if (!(expectedCause.isAssignableFrom(throwable.getCause().getClass()))) {
      fail(
          "TTransportException caused by "
              + cause.getClass()
              + " when expecting a TTransportException caused by "
              + expectedCause);
    }
  }
  @Test(groups = "standalone")
  public void testNonProxyHostsRequestOverridesConfig()
      throws IOException, ExecutionException, TimeoutException, InterruptedException {

    ProxyServer configProxy = proxyServer("localhost", port1 - 1).build();
    ProxyServer requestProxy = proxyServer("localhost", port1).setNonProxyHost("localhost").build();

    try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(configProxy))) {
      String target = "http://localhost:1234/";
      client.prepareGet(target).setProxyServer(requestProxy).execute().get();
      assertFalse(true);
    } catch (Throwable e) {
      assertNotNull(e.getCause());
      assertEquals(e.getCause().getClass(), ConnectException.class);
    }
  }
 protected void assertInvokeInterfaceThrows(
     java.lang.Class<? extends Throwable> errorClass,
     Class target,
     Extends iface,
     AbstractMethod method,
     String... args) {
   try {
     assertInvokeInterfaceEquals(0, target, iface, method, args);
     fail("Expected exception: " + errorClass);
   } catch (AssertionError e) {
     Throwable cause = e.getCause();
     if (cause == null) throw e;
     else if ((errorClass.isAssignableFrom(cause.getClass()))) {
       // this is success
       return;
     } else throw e;
   }
 }
  // @Test(groups = "standalone")
  public void redirected302InvalidTest() throws Exception {
    isSet.getAndSet(false);
    Exception e = null;

    try (AsyncHttpClient c = asyncHttpClient()) {
      c.preparePost(getTargetUrl())
          .setFollowRedirect(true)
          .setHeader("X-redirect", String.format("http://localhost:%d/", port2))
          .execute()
          .get();
    } catch (ExecutionException ex) {
      e = ex;
    }

    assertNotNull(e);
    Throwable cause = e.getCause();
    assertTrue(cause instanceof ConnectException);
    assertTrue(cause.getMessage().contains(":" + port2));
  }
Beispiel #7
0
 private void runRandomTest(final URL bamFile, final int count, final Random generator)
     throws IOException {
   final int maxCoordinate = 10000000;
   final List<String> referenceNames = getReferenceNames(bamFile);
   for (int i = 0; i < count; i++) {
     final String refName = referenceNames.get(generator.nextInt(referenceNames.size()));
     final int coord1 = generator.nextInt(maxCoordinate + 1);
     final int coord2 = generator.nextInt(maxCoordinate + 1);
     final int startPos = Math.min(coord1, coord2);
     final int endPos = Math.max(coord1, coord2);
     System.out.println("Testing query " + refName + ":" + startPos + "-" + endPos + " ...");
     try {
       runQueryTest(bamFile, refName, startPos, endPos, true);
       runQueryTest(bamFile, refName, startPos, endPos, false);
     } catch (Throwable exc) {
       String message = "Query test failed: " + refName + ":" + startPos + "-" + endPos;
       message += ": " + exc.getMessage();
       throw new RuntimeException(message, exc);
     }
   }
 }
  @Test(groups = "online", enabled = false)
  public void invalidStreamTest2() throws Exception {
    AsyncHttpClientConfig config =
        config() //
            .setRequestTimeout(10000) //
            .setFollowRedirect(true) //
            .setKeepAlive(false) //
            .setMaxRedirects(6) //
            .build();

    try (AsyncHttpClient c = asyncHttpClient(config)) {
      Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get();
      if (response != null) {
        System.out.println(response);
      }
    } catch (Throwable t) {
      t.printStackTrace();
      assertNotNull(t.getCause());
      assertEquals(t.getCause().getMessage(), "invalid version format: ICY");
    }
  }