@@ -0,0 +1,3207 @@
+/*%0A * The Gemma project%0A * %0A * Copyright (c) 2012 University of British Columbia%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *       http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A */%0A%0Apackage ubic.gemma.persistence;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0Aimport java.util.concurrent.ConcurrentHashMap;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport org.junit.Test;%0A%0Aimport ubic.gemma.model.expression.experiment.ExpressionExperiment;%0Aimport ubic.gemma.testing.BaseSpringContextTest;%0A%0A/**%0A * Tests for deadlocking issues; see bug 2888.%0A * %0A * @author paul%0A * @version $Id$%0A */%0Apublic class ExperimentLoadTortureTest extends BaseSpringContextTest %7B%0A%0A    /**%0A     * This test will fail with a deadlock on ACL table.%0A     * %0A     * @throws Exception%0A     */%0A    // @Test%0A    public void testConcurrentLoading() throws Exception %7B%0A        /*%0A         * Initialize things, so we're not using a completely fresh db.%0A         */%0A        getTestPersistentCompleteExpressionExperiment( false );%0A%0A        // I was playing around with larger values, but this has worked every time (exposing bug)%0A        int numThreads = 2;%0A        final int numExperimentsPerThread = 1;%0A%0A        final AtomicInteger c = new AtomicInteger( 0 );%0A%0A        final ConcurrentHashMap%3CExpressionExperiment, Integer%3E results = new ConcurrentHashMap%3CExpressionExperiment, Integer%3E();%0A%0A        final AtomicBoolean failed = new AtomicBoolean( false );%0A%0A        for ( int i = 0; i %3C numThreads; i++ ) %7B%0A            final int t = i;%0A            new Thread( new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    for ( int j = 0; j %3C numExperimentsPerThread; j++ ) %7B%0A                        log.info( %22Thread %22 + t + %22 experiment %22 + j );%0A                        try %7B%0A                            ExpressionExperiment ee = getTestPersistentCompleteExpressionExperiment( false );%0A                            results.put( ee, 1 );%0A                        %7D catch ( Exception e ) %7B%0A                            log.error( %22Failure in: Thread %22 + t + %22 experiment %22 + j, e );%0A                            failed.set( true );%0A                        %7D finally %7B%0A                            c.incrementAndGet();%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D ).start();%0A        %7D%0A%0A        while ( c.get() %3C numThreads * numExperimentsPerThread && !failed.get() ) %7B%0A            Thread.sleep( 2000 );%0A            log.info( %22Waiting ...%22 );%0A        %7D%0A%0A        assertEquals( %22Multithreaded loading failure: check logs for deadlock%22, numThreads * numExperimentsPerThread,%0A                results.size() );%0A    %7D%0A%7D%0A

test for bug 2922 (not @Test)