org.jclouds.util.Throwables2 Java Examples

The following examples show how to use org.jclouds.util.Throwables2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeJsWebAppSimpleIntegrationTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void detectFailureIfNodeJsBindToPort() throws Exception {
    ServerSocket listener = new ServerSocket(httpPort);
    try {
        LocalhostMachineProvisioningLocation loc = app.newLocalhostProvisioningLocation();
        NodeJsWebAppService nodejs = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class).configure("httpPort", httpPort));
        try {
            nodejs.start(ImmutableList.of(loc));
            fail("Should have thrown start-exception");
        } catch (Exception e) {
            // LocalhostMachineProvisioningLocation does NetworkUtils.isPortAvailable, so get -1
            IllegalArgumentException iae = Throwables2.getFirstThrowableOfType(e, IllegalArgumentException.class);
            if (iae == null || iae.getMessage() == null || !iae.getMessage().equals("port for http is null")) throw e;
        } finally {
            nodejs.stop();
        }
        assertFalse(nodejs.getAttribute(NodeJsWebAppServiceImpl.SERVICE_UP));
    } finally {
        listener.close();
    }
}
 
Example #2
Source File: JmxHelperTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testReconnectsOnJmxServerTemporaryFailure() throws Exception {
    int port = jmxService.getJmxPort();
    GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName);
    assertEquals(jmxHelper.getAttribute(jmxObjectName, "myattr"), "myval");
    
    // Simulate temporary network-failure
    jmxService.shutdown();

    // Ensure that we have a failed query while the "network is down"         
    try {
        jmxHelper.getAttribute(jmxObjectName, attributeName);
        fail();
    } catch (Exception e) {
        if (Throwables2.getFirstThrowableOfType(e, IOException.class) == null) {
            throw e;
        }
    }

    // Simulate the network restarting
    jmxService = new JmxService(LOCALHOST_NAME, port);
    
    GeneralisedDynamicMBean mbean2 = jmxService.registerMBean(MutableMap.of("myattr", "myval2"), objectName);
    assertEquals(jmxHelper.getAttribute(jmxObjectName, "myattr"), "myval2");
}