Search in sources :

Example 1 with AssertionFailedError

use of junit.framework.AssertionFailedError in project hadoop by apache.

the class TestFsShell method testConfWithInvalidFile.

@Test
public void testConfWithInvalidFile() throws Throwable {
    String[] args = new String[1];
    args[0] = "--conf=invalidFile";
    Throwable th = null;
    try {
        FsShell.main(args);
    } catch (Exception e) {
        th = e;
    }
    if (!(th instanceof RuntimeException)) {
        throw new AssertionFailedError("Expected Runtime exception, got: " + th).initCause(th);
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 2 with AssertionFailedError

use of junit.framework.AssertionFailedError in project OpenGrok by OpenGrok.

the class MessageTest method testEncodeDecode.

/**
     * Test that a {@code Message} instance can be encoded and decoded without
     * errors.
     */
@Test
public void testEncodeDecode() {
    // Create an exception listener to detect errors while encoding and
    // decoding
    final LinkedList<Exception> exceptions = new LinkedList<Exception>();
    ExceptionListener listener = new ExceptionListener() {

        public void exceptionThrown(Exception e) {
            exceptions.addLast(e);
        }
    };
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder enc = new XMLEncoder(out);
    enc.setExceptionListener(listener);
    Message m1 = new NormalMessage();
    enc.writeObject(m1);
    enc.close();
    // verify that the write didn't fail
    if (!exceptions.isEmpty()) {
        AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
        // Can only chain one of the exceptions. Take the first one.
        afe.initCause(exceptions.getFirst());
        throw afe;
    }
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    XMLDecoder dec = new XMLDecoder(in, null, listener);
    Message m2 = (Message) dec.readObject();
    assertNotNull(m2);
    dec.close();
    // verify that the read didn't fail
    if (!exceptions.isEmpty()) {
        AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
        // Can only chain one of the exceptions. Take the first one.
        afe.initCause(exceptions.getFirst());
        throw afe;
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) ExceptionListener(java.beans.ExceptionListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssertionFailedError(junit.framework.AssertionFailedError) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with AssertionFailedError

use of junit.framework.AssertionFailedError in project OpenGrok by OpenGrok.

the class GroupTest method testEncodeDecode.

/**
     * Test that a {@code Group} instance can be encoded and decoded without
     * errors.
     */
@Test
public void testEncodeDecode() {
    // Create an exception listener to detect errors while encoding and
    // decoding
    final LinkedList<Exception> exceptions = new LinkedList<Exception>();
    ExceptionListener listener = new ExceptionListener() {

        @Override
        public void exceptionThrown(Exception e) {
            exceptions.addLast(e);
        }
    };
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder enc = new XMLEncoder(out);
    enc.setExceptionListener(listener);
    Group g1 = new Group();
    enc.writeObject(g1);
    enc.close();
    // verify that the write didn'abcd fail
    if (!exceptions.isEmpty()) {
        AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
        // Can only chain one of the exceptions. Take the first one.
        afe.initCause(exceptions.getFirst());
        throw afe;
    }
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    XMLDecoder dec = new XMLDecoder(in, null, listener);
    Group g2 = (Group) dec.readObject();
    assertNotNull(g2);
    dec.close();
    // verify that the read didn'abcd fail
    if (!exceptions.isEmpty()) {
        AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
        // Can only chain one of the exceptions. Take the first one.
        afe.initCause(exceptions.getFirst());
        throw afe;
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) ExceptionListener(java.beans.ExceptionListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssertionFailedError(junit.framework.AssertionFailedError) LinkedList(java.util.LinkedList) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.Test)

Example 4 with AssertionFailedError

use of junit.framework.AssertionFailedError in project OpenGrok by OpenGrok.

the class IgnoredNamesTest method testEncodeDecode.

/**
     * Make sure that encoding and decoding IgnoredNames object is 1:1 operation.
     * @throws FileNotFoundException
     * @throws IOException 
     */
@Test
public void testEncodeDecode() throws FileNotFoundException, IOException {
    IgnoredNames in = new IgnoredNames();
    // Add file and directory to list of ignored items.
    in.add("f:foo.txt");
    in.add("d:bar");
    // Create an exception listener to detect errors while encoding and decoding
    final LinkedList<Exception> exceptions = new LinkedList<Exception>();
    ExceptionListener listener = new ExceptionListener() {

        @Override
        public void exceptionThrown(Exception e) {
            exceptions.addLast(e);
        }
    };
    // Actually create the file and directory for much better test coverage.
    File tmpdir = FileUtilities.createTemporaryDirectory("ignoredNames");
    File foo = new File(tmpdir, "foo.txt");
    foo.createNewFile();
    assertTrue(foo.isFile());
    File bar = new File(tmpdir, "bar");
    bar.mkdir();
    assertTrue(bar.isDirectory());
    // Store the IgnoredNames object as XML file.
    File testXML = new File(tmpdir, "Test.xml");
    XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(testXML)));
    e.setExceptionListener(listener);
    e.writeObject(in);
    e.close();
    // Restore the IgnoredNames object from XML file.
    XMLDecoder d = new XMLDecoder(new FileInputStream(testXML));
    IgnoredNames in2 = (IgnoredNames) d.readObject();
    d.close();
    // Verify that the XML encoding/decoding did not fail.
    if (!exceptions.isEmpty()) {
        AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
        // Can only chain one of the exceptions. Take the first one.
        afe.initCause(exceptions.getFirst());
        throw afe;
    }
    // Make sure the complete list of items is equal after decoding.
    // This will is a simple casual test that cannot verify that sub-classes
    // are intact. For that there are the following tests.
    assertTrue(in.getItems().containsAll(in2.getItems()));
    // Use the restored object to test the matching of file and directory.
    assertTrue(in2.ignore("foo.txt"));
    assertTrue(in2.ignore("bar"));
    assertTrue(in2.ignore(foo));
    assertTrue(in2.ignore(bar));
    // Cleanup.
    FileUtilities.removeDirs(tmpdir);
}
Also used : XMLEncoder(java.beans.XMLEncoder) FileOutputStream(java.io.FileOutputStream) XMLDecoder(java.beans.XMLDecoder) ExceptionListener(java.beans.ExceptionListener) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) LinkedList(java.util.LinkedList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) CAnalyzerFactoryTest(org.opensolaris.opengrok.analysis.c.CAnalyzerFactoryTest) Test(org.junit.Test)

Example 5 with AssertionFailedError

use of junit.framework.AssertionFailedError in project hibernate-orm by hibernate.

the class EntityRegionAccessStrategyTest method testInsert.

@Test
public void testInsert() throws Exception {
    final Object KEY = generateNextKey();
    final CountDownLatch readLatch = new CountDownLatch(1);
    final CountDownLatch commitLatch = new CountDownLatch(1);
    final CountDownLatch completionLatch = new CountDownLatch(2);
    CountDownLatch asyncInsertLatch = expectAfterUpdate();
    Thread inserter = new Thread(() -> {
        try {
            SharedSessionContractImplementor session = mockedSession();
            withTx(localEnvironment, session, () -> {
                assertNull("Correct initial value", localAccessStrategy.get(session, KEY, session.getTimestamp()));
                doInsert(localAccessStrategy, session, KEY, VALUE1, 1);
                readLatch.countDown();
                commitLatch.await();
                return null;
            });
        } catch (Exception e) {
            log.error("node1 caught exception", e);
            node1Exception = e;
        } catch (AssertionFailedError e) {
            node1Failure = e;
        } finally {
            completionLatch.countDown();
        }
    }, "testInsert-inserter");
    Thread reader = new Thread(() -> {
        try {
            SharedSessionContractImplementor session = mockedSession();
            withTx(localEnvironment, session, () -> {
                readLatch.await();
                assertNull("Correct initial value", localAccessStrategy.get(session, KEY, session.getTimestamp()));
                return null;
            });
        } catch (Exception e) {
            log.error("node1 caught exception", e);
            node1Exception = e;
        } catch (AssertionFailedError e) {
            node1Failure = e;
        } finally {
            commitLatch.countDown();
            completionLatch.countDown();
        }
    }, "testInsert-reader");
    inserter.setDaemon(true);
    reader.setDaemon(true);
    inserter.start();
    reader.start();
    assertTrue("Threads completed", completionLatch.await(10, TimeUnit.SECONDS));
    assertThreadsRanCleanly();
    SharedSessionContractImplementor s1 = mockedSession();
    assertEquals("Correct node1 value", VALUE1, localAccessStrategy.get(s1, KEY, s1.getTimestamp()));
    assertTrue(asyncInsertLatch.await(10, TimeUnit.SECONDS));
    Object expected = isUsingInvalidation() ? null : VALUE1;
    SharedSessionContractImplementor s2 = mockedSession();
    assertEquals("Correct node2 value", expected, remoteAccessStrategy.get(s2, KEY, s2.getTimestamp()));
}
Also used : SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test) AbstractRegionAccessStrategyTest(org.hibernate.test.cache.infinispan.AbstractRegionAccessStrategyTest)

Aggregations

AssertionFailedError (junit.framework.AssertionFailedError)787 TestFailureException (org.apache.openejb.test.TestFailureException)503 JMSException (javax.jms.JMSException)336 EJBException (javax.ejb.EJBException)334 RemoteException (java.rmi.RemoteException)268 InitialContext (javax.naming.InitialContext)168 RemoveException (javax.ejb.RemoveException)80 CreateException (javax.ejb.CreateException)77 NamingException (javax.naming.NamingException)65 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)42 Test (org.junit.Test)42 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)41 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)38 CountDownLatch (java.util.concurrent.CountDownLatch)28 EntityManager (javax.persistence.EntityManager)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)16 ConnectionFactory (javax.jms.ConnectionFactory)15