Package org.apache.jdo.tck.util

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


        if(debug) logger.debug("\nSTART testThreadSafe");
        pmf = getPMF();

        p1 = new PCPoint(3,3);

        ThreadExceptionHandler group = new ThreadExceptionHandler();
        Thread[] threads = new Thread[totalThreadCount];
        for (int i=0; i < totalThreadCount; i++) {
            Thread t = new Thread(group, new PMThread(pmf, p1));
            t.setName("ThreadSafeID-" + i);
            threads[i] = t;
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

        Query query = pm.newQuery(SSJDOQL);
        query.compile();

        // Thread executing the query
        CyclicBarrier barrier = new CyclicBarrier(2);
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
        Thread t = new Thread(group, runnable, "Query Executor");
        t.start();

        try {
            // Wait for the other thread
            barrier.await();

            // Wait a couple of millis such that the other thread can start query execution
            Thread.sleep(MAIN_SLEEP_MILLIS);

            // cancel query
            query.cancel(t);
            if (!isQueryCancelSupported()) {
                fail(ASSERTION_FAILED,
                     "Query.cancel should throw a JDOQueryInterruptedException, " +
                     "if query canceling is not supported ");
            }
        }
        catch (JDOUnsupportedOptionException ex) {
            if (isQueryCancelSupported()) {
                fail(ASSERTION_FAILED,
                     "Query.cancel should not result in a JDOQueryInterruptedException, " +
                     "if query canceling is supported ");
            }
        }

        t.join();
        Throwable problem = group.getUncaughtException(t);
        if (problem != null) {
            if (problem instanceof AssertionFailedError)
                throw (AssertionFailedError)problem;
            else
                throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

        Query query = pm.newQuery(SSJDOQL);
        query.compile();

        // Thread executing the query
        CyclicBarrier barrier = new CyclicBarrier(2);
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
        Thread t = new Thread(group, runnable, "Query Executor");
        t.start();

        try {
            // cancel query
            // Wait for the other thread
            barrier.await();

            // Wait a couple of millis such that the other thread can start query execution
            Thread.sleep(MAIN_SLEEP_MILLIS);

            query.cancelAll();
            if (!isQueryCancelSupported()) {
                fail(ASSERTION_FAILED,
                     "Query.cancel should throw a JDOQueryInterruptedException, " +
                     "if query canceling is not supported ");
            }
        }
        catch (JDOUnsupportedOptionException ex) {
            if (isQueryCancelSupported()) {
                fail(ASSERTION_FAILED,
                     "Query.cancel should not result in a JDOQueryInterruptedException, " +
                     "if query canceling is supported ");
            }
        }

        t.join();
        Throwable problem = group.getUncaughtException(t);
        if (problem != null) {
            if (problem instanceof AssertionFailedError)
                throw (AssertionFailedError)problem;
            else
                throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

    public void testDatastoreReadTimeout() throws Exception {

        if (debug) logger.debug("isDatastoreTimeoutSupported:" + isDatastoreTimeoutSupported());

        // Parallel thread writing the instances and causing them to be locked
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        ParallelWriter runnable = new ParallelWriter(THREAD_SLEEP_MILLIS_LONG);
        Thread t = new Thread(group, runnable, "Parallel Writer");
        t.start();

        // Wait for a second such that the other thread can lock the instances
        Thread.sleep(MAIN_SLEEP_MILLIS);
       
        try {
            runQueryReadingPCPointInstances(READ_TIMEOUT);
            runGetObjectByIdReadingPCPointInstance(READ_TIMEOUT);
            runNavigationalReadPCPointInstance(READ_TIMEOUT);
        }
        finally {
            t.join();
            Throwable problem = group.getUncaughtException(t);
            if (problem != null) {
                if (problem instanceof AssertionFailedError)
                    throw (AssertionFailedError)problem;
                else
                    throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

    public void testDatastoreWriteTimeout() throws Exception {

        if (debug) logger.debug("isDatastoreTimeoutSupported:" + isDatastoreTimeoutSupported());

        // Parallel thread reading the instances and causing them to be locked
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        ParallelReader runnable = new ParallelReader(THREAD_SLEEP_MILLIS_LONG);
        Thread t = new Thread(group, runnable, "Parallel Reader");
        t.start();

        // Wait for a second such that the other thread can lock the instances
        Thread.sleep(MAIN_SLEEP_MILLIS);

        try {
            runUpdatePCointInstance(WRITE_TIMEOUT);
            runDeletePCPointInstance(WRITE_TIMEOUT);
            runDeletePCPointInstancesByQuery(WRITE_TIMEOUT);
        }
        finally {
            t.join();
            Throwable problem = group.getUncaughtException(t);
            if (problem != null) {
                if (problem instanceof AssertionFailedError)
                    throw (AssertionFailedError)problem;
                else
                    throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

    /** Method testing zero DatastoreReadTimeout. */
    public void testZeroDatastoreReadTimeout() throws Exception {

        // Parallel thread writing the instances and causing them to be locked
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        ParallelWriter runnable = new ParallelWriter(THREAD_SLEEP_MILLIS_SHORT);
        Thread t = new Thread(group, runnable, "Parallel Writer");
        t.start();

        // Wait for a second such that the other thread can lock the instances
        Thread.sleep(MAIN_SLEEP_MILLIS);

        try {
            runQueryReadingPCPointInstances(ZERO_TIMEOUT);
        }
        finally {
            t.join();
            Throwable problem = group.getUncaughtException(t);
            if (problem != null) {
                if (problem instanceof AssertionFailedError)
                    throw (AssertionFailedError)problem;
                else
                    throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

    /** Method testing zero DatastoreWriteTimeout. */
    public void testZeroDatastoreWriteTimeout() throws Exception {

        // Parallel thread reading the instances and causing them to be locked
        ThreadExceptionHandler group = new ThreadExceptionHandler();
        ParallelReader runnable = new ParallelReader(THREAD_SLEEP_MILLIS_SHORT);
        Thread t = new Thread(group, runnable, "Parallel Reader");
        t.start();

        // Wait for a second such that the other thread can lock the instances
        Thread.sleep(MAIN_SLEEP_MILLIS);

        try {
            runUpdatePCointInstance(ZERO_TIMEOUT);
        }
        finally {
            t.join();
            Throwable problem = group.getUncaughtException(t);
            if (problem != null) {
                if (problem instanceof AssertionFailedError)
                    throw (AssertionFailedError)problem;
                else
                    throw new JDOFatalException( "Thread " + t.getName()+
View Full Code Here

    }

    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 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

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.