Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

In this page you can find the example usage for java.lang Throwable toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java

@Test
public void testGetTransportNodeState() throws IOException, InterruptedException {
    final TransportNodeState mockResponse = new TransportNodeState();
    mockResponse.setState(com.vmware.photon.controller.nsxclient.datatypes.TransportNodeState.SUCCESS);
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_OK);

    FabricApi client = new FabricApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.getTransportNodeState("id",
            new com.google.common.util.concurrent.FutureCallback<TransportNodeState>() {
                @Override//  w ww.j ava 2  s  . c  o  m
                public void onSuccess(TransportNodeState result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();
                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java

@Test
public void testGetTransportZoneSummary() throws IOException, InterruptedException {
    final TransportZoneSummary mockResponse = new TransportZoneSummary();
    mockResponse.setNumTransportNodes(5);
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_OK);

    FabricApi client = new FabricApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.getTransportZoneSummary("id",
            new com.google.common.util.concurrent.FutureCallback<TransportZoneSummary>() {
                @Override// ww  w  .ja va 2 s . c  o  m
                public void onSuccess(TransportZoneSummary result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();
                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java

@Test
public void testRegisterFabricNode() throws IOException, InterruptedException {
    final FabricNode mockResponse = new FabricNode();
    mockResponse.setId("id");
    mockResponse.setExternalId("externalId");
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_CREATED);

    FabricApi client = new FabricApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.registerFabricNode(new FabricNodeCreateSpec(),
            new com.google.common.util.concurrent.FutureCallback<FabricNode>() {
                @Override//  w w w .jav  a2s . c o m
                public void onSuccess(FabricNode result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();
                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java

@Test
public void testCreateTransportNode() throws IOException, InterruptedException {
    final TransportNode mockResponse = new TransportNode();
    mockResponse.setId("id");
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_CREATED);

    FabricApi client = new FabricApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.createTransportNode(new TransportNodeCreateSpec(),
            new com.google.common.util.concurrent.FutureCallback<TransportNode>() {
                @Override/*from w  w w  . j  av  a 2s . c o m*/
                public void onSuccess(TransportNode result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();

                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java

@Test
public void testCreateTransportZone() throws IOException, InterruptedException {
    final TransportZone mockResponse = new TransportZone();
    mockResponse.setId("id");
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_CREATED);

    FabricApi client = new FabricApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.createTransportZone(new TransportZoneCreateSpec(),
            new com.google.common.util.concurrent.FutureCallback<TransportZone>() {
                @Override/*from   www. j  a v a2s. co m*/
                public void onSuccess(TransportZone result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();

                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.openddal.test.BaseTestCase.java

/**
 * Log an error message.//from  w  ww .ja  v  a 2s . c o  m
 *
 * @param s the message
 * @param e the exception
 */
public static void logError(String s, Throwable e) {
    if (e == null) {
        e = new Exception(s);
    }
    System.out.flush();
    System.err.println("ERROR: " + s + " " + e.toString() + " ------------------------------");
    e.printStackTrace();
    // synchronize on this class, because file locks are only visible to
    // other JVMs
    synchronized (BaseTestCase.class) {
        try {
            // lock
            FileChannel fc = FilePath.get("error.lock").open("rw");
            FileLock lock;
            while (true) {
                lock = fc.tryLock();
                if (lock != null) {
                    break;
                }
                Thread.sleep(10);
            }
            // append
            FileWriter fw = new FileWriter("error.txt", true);
            PrintWriter pw = new PrintWriter(fw);
            e.printStackTrace(pw);
            pw.close();
            fw.close();
            // unlock
            lock.release();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    System.err.flush();
}

From source file:gov.utah.dts.sdc.webservice.DriversLicenseValidation.java

public void handleError(String text, Throwable t) {
    requestError = true;/*from  ww  w .j  a v a  2s.c  o m*/
    requestErrorMessage = t.toString();
    //log.debug(text);
    //log.debug(t);
    t.printStackTrace();
    return;
}

From source file:com.lucidtechnics.blackboard.util.Jsr223ScriptingUtil.java

public Object executeScript(String _scriptResource) {
    ScriptContext scriptContext = getScriptEngine().getContext();

    Object result = null;//from   w w w .ja v a  2  s  .co  m

    try {
        for (String key : getBindingsMap().keySet()) {
            scriptContext.setAttribute(key, getBindingsMap().get(key), ScriptContext.ENGINE_SCOPE);
        }

        CompiledScript script = compileScript(_scriptResource);

        if (script != null) {
            result = script.eval(scriptContext);
        } else {
            result = getScriptEngine().eval(new InputStreamReader(findScript(_scriptResource)), scriptContext);
        }
    } catch (Throwable t) {
        throw new RuntimeException(
                "Unable to execute script: " + _scriptResource + " for this reason: " + t.toString(), t);
    }

    return result;
}

From source file:com.amazonaws.services.iot.demo.danbo.rpi.mqtt.MQTTSubscriber.java

public void run() {
    try {//from www. j av  a2  s.c  o m
        log.debug("Starting Thread: " + threadName);
        this.subscribe(topic, qos);
    } catch (Throwable e) {
        log.error(e.toString());
        e.printStackTrace();
    } finally {
        log.debug("Finishing Thread: " + threadName);
    }
}

From source file:com.walmart.gatling.commons.ScriptExecutor.java

@Override
public void onReceive(Object message) {
    log.debug("Script worker received task: {}", message);
    if (message instanceof Master.Job) {
        Cancellable abortLoop = getContext().system().scheduler().schedule(Duration.Zero(),
                Duration.create(60, TimeUnit.SECONDS), () -> {
                    Master.Job job = (Master.Job) message;
                    runCancelJob(job);/*from  w w  w  .j av a 2 s.  co m*/
                }, getContext().system().dispatcher());
        ActorRef sender = getSender();
        ExecutorService pool = Executors.newFixedThreadPool(1);
        ExecutionContextExecutorService ctx = ExecutionContexts.fromExecutorService(pool);
        Future<Object> f = future(() -> runJob(message), ctx);
        f.onSuccess(new OnSuccess<Object>() {
            @Override
            public void onSuccess(Object result) throws Throwable {
                log.info("Notify Worker job status {}", result);
                sender.tell(result, getSelf());
                abortLoop.cancel();
            }
        }, ctx);
        f.onFailure(new OnFailure() {
            @Override
            public void onFailure(Throwable throwable) throws Throwable {
                log.error(throwable.toString());
                abortLoop.cancel();
                unhandled(message);
            }
        }, ctx);
        //getSender().tell(runJob(message));
    } else if (message instanceof Master.FileJob) {
        Master.FileJob fileJob = (Master.FileJob) message;
        try {
            if (fileJob.content != null) {
                FileUtils.touch(
                        new File(agentConfig.getJob().getPath(), fileJob.uploadFileRequest.getFileName()));
                FileUtils.writeStringToFile(
                        new File(agentConfig.getJob().getPath(), fileJob.uploadFileRequest.getFileName()),
                        fileJob.content);
                getSender().tell(new Worker.FileUploadComplete(fileJob.uploadFileRequest, HostUtils.lookupIp()),
                        getSelf());
            } else if (fileJob.remotePath != null) {
                FileUtils.touch(
                        new File(agentConfig.getJob().getPath(), fileJob.uploadFileRequest.getFileName()));
                FileUtils.copyURLToFile(new URL(fileJob.remotePath),
                        new File(agentConfig.getJob().getPath(), fileJob.uploadFileRequest.getFileName()));
                getSender().tell(new Worker.FileUploadComplete(fileJob.uploadFileRequest, HostUtils.lookupIp()),
                        getSelf());
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}