From commits-return-5578-apmail-openjpa-commits-archive=openjpa.apache.org@openjpa.apache.org Thu Nov 19 20:38:10 2009 Return-Path: Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: (qmail 42769 invoked from network); 19 Nov 2009 20:38:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Nov 2009 20:38:10 -0000 Received: (qmail 75703 invoked by uid 500); 19 Nov 2009 20:38:10 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 75648 invoked by uid 500); 19 Nov 2009 20:38:10 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 75639 invoked by uid 99); 19 Nov 2009 20:38:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Nov 2009 20:38:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Nov 2009 20:38:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3AF492388996; Thu, 19 Nov 2009 20:37:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r882285 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java Date: Thu, 19 Nov 2009 20:37:46 -0000 To: commits@openjpa.apache.org From: ppoddar@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091119203746.3AF492388996@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ppoddar Date: Thu Nov 19 20:37:45 2009 New Revision: 882285 URL: http://svn.apache.org/viewvc?rev=882285&view=rev Log: OPENJPA-1350: Test case (by Rick Curtis) to test early registration of type alias to avoid/minimze risk of multi-threaded repository initialization. Original change was revision 826944 Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java (with props) Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java?rev=882285&view=auto ============================================================================== --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java (added) +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java Thu Nov 19 20:37:45 2009 @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.persistence.meta; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.persistence.EntityManagerFactory; + +import org.apache.openjpa.meta.MetaDataRepository; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +public class TestQueryTypeAliasRegistration extends SingleEMFTestCase { + private final int threads = 100; + + @Override + public void setUp() throws Exception { + super.setUp(MdrTestEntity.class); + assertNotNull(emf); + // Create the Entity which we're going to try to get MetaData for using + // an alias. Do this to ensure that it has been registered to the PCRegistry. + new MdrTestEntity(); + } + + /** + * This method tests a timing window where more than one thread requests MetaData using an alias + * at the same time. All threads should get data back and no threads should receive an + * exception. + */ + public void testMultiThreadGetMetaDataAlias() throws Exception { + try { + List workers = new ArrayList(); + Set exceptions = new HashSet(); + for (int i = 0; i < threads; i++) { + Worker w = new Worker(emf); + workers.add(w); + } + for (Worker w : workers) { + w.start(); + } + for (Worker w : workers) { + w.join(); + Exception e = w.getException(); + if (e != null) { + exceptions.add(w.getException()); + } + } + assertTrue("Caught " + exceptions.toString(), exceptions.size() == 0); + } finally { + if (emf != null) { + emf.close(); + } + } + } + + class Worker extends Thread { + OpenJPAEntityManagerFactorySPI emf; + OpenJPAEntityManagerSPI em; + MetaDataRepository repo; + Exception ex; + + Worker(EntityManagerFactory e) { + emf = (OpenJPAEntityManagerFactorySPI) e; + // Create an EM here because that triggers registering the MDR as a class registration + // listener with the PCRegistry. + em = emf.createEntityManager(); + repo = em.getConfiguration().getMetaDataRepositoryInstance(); + } + + Exception getException() { + return ex; + } + + @Override + public void run() { + try { + repo.getMetaData("MdrTestEntity", Thread.currentThread().getContextClassLoader(), true); + } catch (Exception e) { + ex = e; + e.printStackTrace(); + } finally { + em.close(); + } + } + } +} Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java ------------------------------------------------------------------------------ svn:eol-style = native