@@ -0,0 +1,2655 @@
+/*%0A * This file is part of Dimdwarf Application Server %3Chttp://dimdwarf.sourceforge.net/%3E%0A *%0A * Copyright (c) 2008-2009, Esko Luontola. All Rights Reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without modification,%0A * are permitted provided that the following conditions are met:%0A *%0A *     * Redistributions of source code must retain the above copyright notice,%0A *       this list of conditions and the following disclaimer.%0A *%0A *     * Redistributions in binary form must reproduce the above copyright notice,%0A *       this list of conditions and the following disclaimer in the documentation%0A *       and/or other materials provided with the distribution.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22 AND%0A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED%0A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR%0A * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES%0A * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;%0A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON%0A * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS%0A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A%0Apackage net.orfjackal.dimdwarf;%0A%0Aimport com.google.inject.util.ReferenceCache;%0Aimport junit.framework.TestCase;%0A%0Aimport java.util.*;%0Aimport java.util.concurrent.*;%0A%0Apublic class ReferenceCacheConcurrencyTest extends TestCase %7B%0A%0A    // TODO: upgrade to Guice 2.0 and check that this bug does not appear there%0A    // http://groups.google.com/group/google-guice/browse_thread/thread/7cdff66a4b7acc9d%0A    public void testConcurrentGet() throws Exception %7B%0A        final ReferenceCache%3CString, String%3E cache = new ReferenceCache%3CString, String%3E() %7B%0A            protected String create(String key) %7B%0A                return key;%0A            %7D%0A        %7D;%0A        ArrayList%3CCallable%3CString%3E%3E callsToGet = new ArrayList%3CCallable%3CString%3E%3E();%0A        for (int i = 0; i %3C 10; i++) %7B%0A            callsToGet.add(new Callable%3CString%3E() %7B%0A                public String call() throws Exception %7B%0A                    return cache.get(%22foo%22);%0A                %7D%0A            %7D);%0A        %7D%0A        List%3CFuture%3CString%3E%3E results = Executors.newCachedThreadPool().invokeAll(callsToGet);%0A        for (Future%3CString%3E result : results) %7B%0A            assertEquals(%22foo%22, result.get());%0A        %7D%0A    %7D%0A%7D%0A

Test case for checking a bug in Guice 1.0