Exemplo n.º 1
0
  /**
   * Tests the API using the supplied tester instance. First the API is tested with non-null
   * parameters, then with null parameters and finally the failure of the API is tested.
   *
   * @param inTester the tester to test the API invocation.
   * @param <R> the return type of the API.
   * @throws Exception if there were unexpected errors
   */
  private static <R> void testAPI(final WSTester<R> inTester) throws Exception {
    // Test a regular invocation.
    R value = inTester.setReturnValue(false);
    verifyEquals(value, inTester.invokeApi(false));
    inTester.verifyInputParams(false);

    // Test invocation with nulls
    resetServiceParameters();
    value = inTester.setReturnValue(true);
    verifyEquals(value, inTester.invokeApi(true));
    inTester.verifyInputParams(true);

    // Test a failure
    resetServiceParameters();
    I18NException failure = new I18NException(new I18NMessage0P(Messages.LOGGER, "test"));
    getMockSAService().setFailure(failure);
    inTester.setReturnValue(false);
    ConnectionException e =
        new ExpectedFailure<ConnectionException>() {
          @Override
          protected void run() throws Exception {
            inTester.invokeApi(false);
          }
        }.getException();
    assertNotNull(e.getCause());
    assertEquals(failure, e.getCause());
    // Verify that input parameters were received even when failure occured.
    inTester.verifyInputParams(false);

    // Test service interruption
    verifyInvocationCannotBeInterrupted(inTester);
  }
Exemplo n.º 2
0
 private HostConnectionPool addHost(Host host) {
   try {
     HostDistance distance = loadBalancer.distance(host);
     if (distance == HostDistance.IGNORED) {
       return pools.get(host);
     } else {
       logger.debug("Adding {} to list of queried hosts", host);
       return pools.put(host, new HostConnectionPool(host, distance, this));
     }
   } catch (AuthenticationException e) {
     logger.error("Error creating pool to {} ({})", host, e.getMessage());
     host.getMonitor()
         .signalConnectionFailure(new ConnectionException(e.getHost(), e.getMessage()));
     return pools.get(host);
   } catch (ConnectionException e) {
     logger.debug("Error creating pool to {} ({})", host, e.getMessage());
     host.getMonitor().signalConnectionFailure(e);
     return pools.get(host);
   }
 }