Package org.apache.jdo.tck.util

Examples of org.apache.jdo.tck.util.ThreadExceptionHandler


    }

    protected void insertObjects(boolean sharedPC) {
        Object pc = null;

        ThreadExceptionHandler threadGroup = new ThreadExceptionHandler();
        for (int i = 0; i < inserters; i++) {
            if (sharedPC) { // each thread shares one PC
                if (pc==null)
                    pc = new StateTransitionObj(i);
            }
            else { // each thread has its own PC
                pc = new StateTransitionObj(i);
            }
            threads++;
            Thread t = new Thread(threadGroup, new Inserter(pmf, pc, sharedPC));
            t.setName("Inserter-" + i);
            t.start();
        }
       
        Thread.yield();
       
        while (! attemptsComplete()) {
            try  {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                logger.debug("interrupted while waiting for threads to insert");
            }
        }

        while (threads > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                logger.debug("interrupted while waiting for threads to finish");
            }
        }
       
        Collection exceptions = threadGroup.getAllUncaughtExceptions();
        for (Iterator i = exceptions.iterator(); i.hasNext(); ) {
            Map.Entry entry = (Map.Entry) i.next();
            Thread thread = (Thread)entry.getKey();
            Throwable throwable = (Throwable)entry.getValue();
            String message = "Uncaught exception " + throwable + " in thread " + thread;
View Full Code Here


    /** */
    private void runTestRefreshAllWithArraySideEffects(
        PersistenceManager pm1, PersistenceManager pm2) throws Exception {
        if (debug) logger.debug("\nSTART RefreshAllWithArraySideEffects");

        ThreadExceptionHandler group = new ThreadExceptionHandler();
        RefreshArrThreadT1 thread1 = new RefreshArrThreadT1(pm1);
        Thread  T1 = new Thread(group, thread1, "T1");
        RefreshArrThreadT2 thread2 = new RefreshArrThreadT2(pm2);
        Thread  T2 = new Thread(group, thread2, "T2");
        thread1.setOther(thread2);
        thread2.setOther(thread1);
       
        T1.start();
        T2.start();
       
        T1.join();
        T2.join();
       
        Throwable t1Problem = group.getUncaughtException(T1);
        if (t1Problem != null) {
            if (t1Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t1Problem;
            else
                throw new JDOFatalException( "Thread "+T1.getName()+" results in exception ", t1Problem );
        }
        Throwable t2Problem = group.getUncaughtException(T2);
        if (t2Problem != null) {
            if (t2Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t2Problem;
            else
                throw new JDOFatalException( "Thread "+T2.getName()+" results in exception ", t2Problem );
View Full Code Here

    /** */
    public void runTestRefreshAllWithCollectionSideEffects(PersistenceManager pm1,
                                                           PersistenceManager pm2) throws Exception {
        if (debug) logger.debug("\nSTART RefreshAllWithCollectionSideEffects");

        ThreadExceptionHandler group = new ThreadExceptionHandler();
        RefreshColThreadT1 thread1 = new RefreshColThreadT1(pm1);
        Thread  T1 = new Thread(group, thread1, "T1");
        RefreshColThreadT2 thread2 = new RefreshColThreadT2(pm2);
        Thread  T2 = new Thread(group, thread2, "T2");
        thread1.setOther(thread2);
        thread2.setOther(thread1);
       
        T1.start();
        T2.start();
       
        T1.join();
        T2.join();
       
        Throwable t1Problem = group.getUncaughtException(T1);
        if (t1Problem != null) {
            if (t1Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t1Problem;
            else
                throw new JDOFatalException( "Thread "+T1.getName()+" results in exception ", t1Problem );
        }
        Throwable t2Problem = group.getUncaughtException(T2);
        if (t2Problem != null) {
            if (t2Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t2Problem;
            else
                throw new JDOFatalException( "Thread "+T2.getName()+" results in exception ", t2Problem );
View Full Code Here

            tx.begin();

            if (debug)
                logger.debug(getThreadName() + ": Starting " +
                             nrOfThreads + " concurrent threads.");
            ThreadExceptionHandler group = new ThreadExceptionHandler();
            Thread[] threads = new Thread[nrOfThreads];
            for (int i = 0; i < nrOfThreads; i++) {
              // Runnable r = new QueryExecuter(pm);
                Runnable r =
                    new ExecutingMultipleQueriesSimultaneouslyIsThreadSafe().
                        getQueryExecuter(pm);
                Thread t = new Thread(group, r);
                t.setName("ThreadID-" + i);
                threads[i] = t;
                if (debug) logger.debug(getThreadName() + ": Running");
                t.start();
            }

            if (debug)
                logger.debug(getThreadName() +
                             ": Waiting for threads to join...");
            for (int i = 0; i < nrOfThreads; i++) {
                try { threads[i].join(); }
                catch (InterruptedException e) { }
            }
            if (debug) logger.debug(getThreadName() + ": All threads joined.");

            tx.commit();
            tx = null;
           
            // check unhandled exceptions
            Set uncaught = group.getAllUncaughtExceptions();
            if ((uncaught != null) && !uncaught.isEmpty()) {
                for (Iterator i = uncaught.iterator(); i.hasNext();) {
                    Map.Entry next = (Map.Entry)i.next();
                    Thread thread = (Thread)next.getKey();
                    Throwable problem = (Throwable)next.getValue();
View Full Code Here

    /** */
    private void runTestRefreshSideEffects(PersistenceManager pm1,
                                           PersistenceManager pm2) throws Exception {
        if (debug) logger.debug ("\nSTART RefreshSideEffects");

        ThreadExceptionHandler group = new ThreadExceptionHandler();
        RefreshThreadT1 thread1 = new RefreshThreadT1(pm1);
        Thread T1 = new Thread(group, thread1, "T1");
        RefreshThreadT2 thread2 = new RefreshThreadT2(pm2);
        Thread T2 = new Thread(group, thread2, "T2");
        thread1.setOther(thread2);
        thread2.setOther(thread1);

        T1.start();
        T2.start();
       
        T1.join();
        T2.join();
       
        Throwable t1Problem = group.getUncaughtException(T1);
        if (t1Problem != null) {
            if (t1Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t1Problem;
            else
                throw new JDOFatalException( "Thread "+T1.getName()+" results in exception ", t1Problem );
        }
        Throwable t2Problem = group.getUncaughtException(T2);
        if (t2Problem != null) {
            if (t2Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t2Problem;
            else
                throw new JDOFatalException( "Thread "+T2.getName()+" results in exception ", t2Problem );
View Full Code Here

            return;
        }
       
        if (debug) logger.debug ("\nSTART RefreshAllNoParameterSideEffects");
       
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        ThreadT1 thread1 = new ThreadT1(pm1);
        Thread  T1 = new Thread(group, thread1, "T1");
        ThreadT2 thread2 = new ThreadT2(pm2);
        Thread  T2 = new Thread(group, thread2, "T2");
        thread1.setOther(thread2);
        thread2.setOther(thread1);
       
        T1.start();
        T2.start();

        T1.join();
        T2.join();
       
        Throwable t1Problem = group.getUncaughtException(T1);
        if (t1Problem != null) {
            if (t1Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t1Problem;
            else
                throw new JDOFatalException( "Thread "+T1.getName()+" results in exception ", t1Problem );
        }
        Throwable t2Problem = group.getUncaughtException(T2);
        if (t2Problem != null) {
            if (t2Problem instanceof AssertionFailedError)
                throw (AssertionFailedError)t2Problem;
            else
                throw new JDOFatalException( "Thread "+T2.getName()+" results in exception ", t2Problem );
View Full Code Here

TOP

Related Classes of org.apache.jdo.tck.util.ThreadExceptionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.