Example usage for java.lang AssertionError getCause

List of usage examples for java.lang AssertionError getCause

Introduction

In this page you can find the example usage for java.lang AssertionError getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:Main.java

public static boolean isAndroidGetsocknameError(AssertionError e) {
    return e.getCause() != null && e.getMessage() != null && e.getMessage().contains("getsockname failed");
}

From source file:eu.stratosphere.core.testing.GenericTestPlan.java

private void validateResults() {
    for (final GenericDataSinkBase<T> sinkOperator : this.getDataSinks()) {
        final Records expectedValues = this.expectedOutputs.get(sinkOperator);
        // need a format which is deserializable without configuration
        if (sinkOperator.getFormatWrapper().getUserCodeClass() == (Class<?>) SequentialOutputFormat.class
                && expectedValues != null && expectedValues.isInitialized()) {
            final Records actualValues = this.getActualOutput(sinkOperator);

            try {
                actualValues.assertEquals(expectedValues);
            } catch (final AssertionError e) {
                final AssertionError assertionError = new AssertionError(
                        sinkOperator.getName() + ": " + e.getMessage());
                assertionError.initCause(e.getCause());
                throw assertionError;
            } finally {
                actualValues.close();/*  www  . jav a 2 s. c o m*/
            }
        }
    }
}

From source file:org.apache.hadoop.test.TestGenericTestUtils.java

@Test
public void testAssertExceptionContainsWrongText() throws Throwable {
    try {/* w w w  . java 2s  .  c  om*/
        assertExceptionContains("Expected", new Exception("(actual)"));
    } catch (AssertionError e) {
        String s = e.toString();
        if (!s.contains(E_UNEXPECTED_EXCEPTION) || !s.contains("(actual)")) {
            throw e;
        }
        if (e.getCause() == null) {
            throw new AssertionError("No nested cause in assertion", e);
        }
    }
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerBadInputRollbackOnFailure() throws Exception {
    configure(processor, 1, 0);/*from   w w w .ja  va2s . co  m*/
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");

    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    runner.enqueue("I am not an Avro record".getBytes());
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerMultipleRecordsFailInMiddleRollbackOnFailure() throws Exception {
    configure(processor, 3);/*  w w w.  j  a  va  2 s . co m*/
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    processor.setGenerateWriteFailure(true);
    runner.enqueue(new byte[0]);
    try {
        runner.run();
        fail("ProcessException should be thrown, because any Hive Transaction is committed yet.");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_SUCCESS, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_RETRY, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerWithConnectFailure() throws Exception {
    configure(processor, 1);//from  w  w  w .ja  va2 s .  co m
    processor.setGenerateConnectFailure(true);
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.enqueue(new byte[0]);
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }
    runner.assertTransferCount(PutHive3Streaming.REL_RETRY, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_SUCCESS, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerWithConnectFailureRollbackOnFailure() throws Exception {
    configure(processor, 1);/* w ww .  j a v  a2s.  c  o m*/
    processor.setGenerateConnectFailure(true);
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    runner.enqueue(new byte[0]);
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_RETRY, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_SUCCESS, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerWithWriteFailureRollbackOnFailure() throws Exception {
    configure(processor, 2);/* w  ww  .  j ava 2s . c o  m*/
    processor.setGenerateWriteFailure(true);
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    Map<String, Object> user1 = new HashMap<String, Object>() {
        {
            put("name", "Joe");
            put("favorite_number", 146);
        }
    };
    Map<String, Object> user2 = new HashMap<String, Object>() {
        {
            put("name", "Mary");
            put("favorite_number", 42);
        }
    };
    runner.enqueue(createAvroRecord(Arrays.asList(user1, user2)));
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerWithSerializationErrorRollbackOnFailure() throws Exception {
    configure(processor, 1);/*from w  ww.  ja  v a 2  s  . c o m*/
    processor.setGenerateSerializationError(true);
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    Map<String, Object> user1 = new HashMap<String, Object>() {
        {
            put("name", "Joe");
            put("favorite_number", 146);
        }
    };
    runner.enqueue(createAvroRecord(Collections.singletonList(user1)));
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_SUCCESS, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}

From source file:org.apache.nifi.processors.hive.TestPutHive3Streaming.java

@Test
public void onTriggerWithCommitFailureRollbackOnFailure() throws Exception {
    configure(processor, 1);/*ww  w  .  jav a 2s. c om*/
    processor.setGenerateCommitFailure(true);
    runner.setProperty(PutHive3Streaming.METASTORE_URI, "thrift://localhost:9083");
    runner.setProperty(PutHive3Streaming.DB_NAME, "default");
    runner.setProperty(PutHive3Streaming.TABLE_NAME, "users");
    runner.setProperty(PutHive3Streaming.ROLLBACK_ON_FAILURE, "true");
    runner.enqueue(new byte[0]);
    try {
        runner.run();
        fail("ProcessException should be thrown");
    } catch (AssertionError e) {
        assertTrue(e.getCause() instanceof ProcessException);
    }

    runner.assertTransferCount(PutHive3Streaming.REL_FAILURE, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_SUCCESS, 0);
    runner.assertTransferCount(PutHive3Streaming.REL_RETRY, 0);
    // Assert incoming FlowFile stays in input queue.
    assertEquals(1, runner.getQueueSize().getObjectCount());
}