aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1690250 - in /aries/trunk/jpa: itests/jpa-tck-itest/ jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/ jpa-container/src/test/java/org/apache/aries/jpa/...
Date Fri, 10 Jul 2015 12:11:39 GMT
Author: cschneider
Date: Fri Jul 10 12:11:38 2015
New Revision: 1690250

URL: http://svn.apache.org/r1690250
Log:
[ARIES-1351] Fixing tck tests

Modified:
    aries/trunk/jpa/itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd
    aries/trunk/jpa/itests/jpa-tck-itest/pom.xml
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ManagedEMF.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnitParser.java
    aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/impl/PropsConfigurationTest.java

Modified: aries/trunk/jpa/itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd (original)
+++ aries/trunk/jpa/itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd Fri Jul 10 12:11:38 2015
@@ -39,8 +39,8 @@ lib/org.eclipse.persistence.jpa-2.6.0.ja
 lib/org.eclipse.persistence.antlr-2.6.0.jar;version=file, \
 lib/org.eclipse.persistence.jpa.jpql-2.6.0.jar;version=file, \
 lib/org.eclipse.persistence.asm-2.6.0.jar;version=file, \
-lib/org.apache.aries.jpa.eclipselink.adapter-2.0.0-SNAPSHOT.jar;version=file, \
-lib/org.apache.aries.jpa.container-2.0.0-SNAPSHOT.jar;version=file, \
+lib/org.apache.aries.jpa.eclipselink.adapter-2.0.1-SNAPSHOT.jar;version=file, \
+lib/org.apache.aries.jpa.container-2.0.1-SNAPSHOT.jar;version=file, \
 lib/org.osgi.test.cases.jpa-5.0.0.jar;version=file 
 
 -runproperties = \

Modified: aries/trunk/jpa/itests/jpa-tck-itest/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-tck-itest/pom.xml?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/itests/jpa-tck-itest/pom.xml (original)
+++ aries/trunk/jpa/itests/jpa-tck-itest/pom.xml Fri Jul 10 12:11:38 2015
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.aries.jpa.itest</groupId>
         <artifactId>org.apache.aries.jpa.itest.parent</artifactId>
-        <version>2.0.0-SNAPSHOT</version>
+        <version>2.0.1-SNAPSHOT</version>
         <relativePath>..</relativePath>
     </parent>
 

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ManagedEMF.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ManagedEMF.java?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ManagedEMF.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ManagedEMF.java
Fri Jul 10 12:11:38 2015
@@ -40,7 +40,6 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
-import org.osgi.service.jpa.EntityManagerFactoryBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,32 +55,37 @@ public class ManagedEMF implements Close
 
     private EntityManagerFactory emf;
     private ServiceRegistration<EntityManagerFactory> reg;
-    private ServiceRegistration<EntityManagerFactoryBuilder> regBuilder;
     private PersistenceProvider provider;
     private PersistenceUnitInfo persistenceUnit;
     private Bundle bundle;
+    private ServiceRegistration<?> configReg;
+
+    private boolean closed;
 
     public ManagedEMF(BundleContext containerContext, Bundle bundle, PersistenceProvider
provider, PersistenceUnitInfo persistenceUnit) {
         this.provider = provider;
         this.persistenceUnit = persistenceUnit;
         this.bundle = bundle;
+        registerManagedService(containerContext, persistenceUnit);
+        //createAndPublishEMF(null);
+        closed = false;
+    }
 
+    private void registerManagedService(BundleContext containerContext, PersistenceUnitInfo
persistenceUnit) {
         Dictionary<String, Object> configuration = new Hashtable<String, Object>();
         configuration.put(Constants.SERVICE_PID,
                           JPA_CONFIGURATION_PREFIX + persistenceUnit.getPersistenceUnitName());
-        containerContext.registerService(ManagedService.class.getName(), this, configuration);
+        configReg = containerContext.registerService(ManagedService.class.getName(), this,
configuration);
     }
 
-    public void close() {
-        try {
-            reg.unregister();
-        } catch (Exception e) {
-            // Ignore. May happen if persistence unit bundle is unloaded/updated
-        }
-        try {
-            regBuilder.unregister();
-        } catch (Exception e) {
-            // Ignore. May happen if persistence unit bundle is unloaded/updated
+    public void closeEMF() {
+        if (reg != null) {
+            try {
+
+                reg.unregister();
+            } catch (Exception e) {
+                // Ignore. May happen if persistence unit bundle is unloaded/updated
+            }
         }
         if (emf != null && emf.isOpen()) {
             try {
@@ -93,17 +97,37 @@ public class ManagedEMF implements Close
         reg = null;
         emf = null;
     }
+    
+    public void close() {
+        closeEMF();
+        closed = true;
+        if (configReg != null) {
+            configReg.unregister();
+        }
+    }
 
     @Override
     public void updated(Dictionary<String, ?> properties) throws ConfigurationException
{
+        if (closed) {
+            return;
+        }
         if (emf != null) {
-            close();
+            closeEMF();
+        }
+        if (bundle.getState() == Bundle.UNINSTALLED || bundle.getState() == Bundle.INSTALLED)
{
+            // Not sure why but during the TCK tests updated sometimes was called
+            // for uninstalled bundles
+            return;
         }
         Map<String, Object> overrides = (properties != null) ? asMap(properties) :
null;
         LOGGER.info("Registering EntityManagerFactory for persistence unit " + persistenceUnit.getPersistenceUnitName());
         if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Using properties override " + overrides); 
         }
+        createAndPublishEMF(overrides);
+    }
+
+    private void createAndPublishEMF(Map<String, Object> overrides) {
         emf = provider.createContainerEntityManagerFactory(persistenceUnit, overrides);
         Dictionary<String, String> props = createProperties(persistenceUnit, bundle);
         BundleContext uctx = bundle.getBundleContext();

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
Fri Jul 10 12:11:38 2015
@@ -29,8 +29,6 @@ import org.apache.aries.jpa.container.pa
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,7 +37,6 @@ import org.slf4j.LoggerFactory;
  * Looks for bundles containing a persistence.xml. For each persistence unit
  * found a PersistenceProviderTracker is installed that tracks matching providers.
  */
-@SuppressWarnings("deprecation")
 public class PersistenceBundleTracker implements BundleTrackerCustomizer<Bundle> {
     private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceBundleTracker.class);
     Map<Bundle, Collection<PersistenceProviderTracker>> trackers;
@@ -59,7 +56,7 @@ public class PersistenceBundleTracker im
 
     public synchronized void removedBundle(Bundle bundle, BundleEvent event, Bundle object)
{
         Collection<PersistenceProviderTracker> providerTrackers = trackers.remove(bundle);
-        if (providerTrackers == null || providerTrackers.size() > 0) {
+        if (providerTrackers == null || providerTrackers.size() == 0) {
             return;
         }
         LOGGER.info("removing persistence units for " + bundle.getSymbolicName() + " " +
getType(event));
@@ -70,17 +67,13 @@ public class PersistenceBundleTracker im
     }
 
     private void findPersistenceUnits(Bundle bundle) {
-        ServiceReference<PackageAdmin> ref = context.getServiceReference(PackageAdmin.class);
-        PackageAdmin packageAdmin = context.getService(ref);
         for (PersistenceUnit punit : PersistenceUnitParser.getPersistenceUnits(bundle)) {
-            punit.addAnnotated(packageAdmin);
+            punit.addAnnotated();
             trackProvider(bundle, punit);
         }
-        context.ungetService(ref);
     }
 
-    private void trackProvider(Bundle bundle, 
-                               PersistenceUnit punit) {
+    private void trackProvider(Bundle bundle, PersistenceUnit punit) {
         LOGGER.info(String.format("Found persistence unit %s in bundle %s with provider %s.",
                                   punit.getPersistenceUnitName(), bundle.getSymbolicName(),
                                   punit.getPersistenceProviderClassName()));

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
Fri Jul 10 12:11:38 2015
@@ -38,7 +38,6 @@ import org.apache.aries.jpa.container.we
 import org.apache.aries.jpa.container.weaving.impl.TransformerRegistrySingleton;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.packageadmin.PackageAdmin;
 
 public class PersistenceUnit implements PersistenceUnitInfo {
 
@@ -218,7 +217,7 @@ public class PersistenceUnit implements
         this.validationMode = validationMode;
     }
 
-    public void addAnnotated(PackageAdmin packageAdmin) {
+    public void addAnnotated() {
         if (!excludeUnlistedClasses()) {
             Collection<String> detected = JPAAnnotationScanner.findJPAAnnotatedClasses(bundle);
             for (String name : detected) {

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnitParser.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnitParser.java?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnitParser.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnitParser.java
Fri Jul 10 12:11:38 2015
@@ -30,7 +30,6 @@ import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 
-import javax.persistence.spi.PersistenceUnitTransactionType;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
@@ -101,9 +100,6 @@ public class PersistenceUnitParser {
             JPAHandler handler = new JPAHandler(bundle);
             parser.parse(is, handler);
             punits.addAll(handler.getPersistenceUnits());
-            for (PersistenceUnit punit : punits) {
-                validate(punit);
-            }
         } catch (Exception e) {
             throw new RuntimeException("persistence.description.parse.error", e);
         } finally {
@@ -111,12 +107,6 @@ public class PersistenceUnitParser {
         }
     }
 
-    private static void validate(PersistenceUnit punit) {
-        if (punit.getTransactionType() == null) {
-            throw new IllegalArgumentException("No transaction type specified for persistence
unit " + punit.getName());
-        }
-    }
-
     private static void safeClose(InputStream is) {
         if (is != null) {
             try {

Modified: aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/impl/PropsConfigurationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/impl/PropsConfigurationTest.java?rev=1690250&r1=1690249&r2=1690250&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/impl/PropsConfigurationTest.java
(original)
+++ aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/impl/PropsConfigurationTest.java
Fri Jul 10 12:11:38 2015
@@ -34,12 +34,15 @@ import javax.persistence.spi.Persistence
 
 import org.apache.aries.jpa.container.impl.ManagedEMF;
 import org.junit.Test;
+import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
 import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
 
 public class PropsConfigurationTest {
 
@@ -54,6 +57,9 @@ public class PropsConfigurationTest {
             .thenReturn("org.eclipse.persistence.jpa.PersistenceProvider");
         when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA);
         BundleContext context = mock(BundleContext.class);
+        ServiceRegistration reg = mock(ServiceRegistration.class);
+        when(context.registerService(Mockito.eq(ManagedService.class.getName()), Mockito.any(),
Mockito.any(Dictionary.class)))
+            .thenReturn(reg);
         Bundle bundle = mock(Bundle.class);
         when(bundle.getBundleContext()).thenReturn(context);
         when(bundle.getVersion()).thenReturn(new Version("4.3.1"));
@@ -69,7 +75,9 @@ public class PropsConfigurationTest {
                                                        Mockito.any(Dictionary.class));
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({
+        "unchecked", "rawtypes"
+    })
     @Test
     public void testEmfWithProps() throws InvalidSyntaxException, ConfigurationException
{
         PersistenceUnitInfo punit = mock(PersistenceUnitInfo.class);
@@ -78,15 +86,18 @@ public class PropsConfigurationTest {
             .thenReturn("org.eclipse.persistence.jpa.PersistenceProvider");
         when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA);
         BundleContext context = mock(BundleContext.class);
+        ServiceRegistration reg = mock(ServiceRegistration.class);
+        when(context.registerService(Mockito.eq(ManagedService.class.getName()), Mockito.any(),
Mockito.any(Dictionary.class)))
+            .thenReturn(reg);
         Bundle bundle = mock(Bundle.class);
         when(bundle.getBundleContext()).thenReturn(context);
         when(bundle.getVersion()).thenReturn(new Version("4.3.1"));
         PersistenceProvider provider = mock(PersistenceProvider.class);
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put("hibernate.hbm2ddl.auto", "create-drop");
-        ManagedEMF emf = new ManagedEMF(context, bundle, provider, punit);
-        emf.updated(null);
-        emf.close();
+        ManagedEMF mEMF = new ManagedEMF(context, bundle, provider, punit);
+        mEMF.updated(null);
+        mEMF.close();
 
         verify(provider, atLeastOnce()).createContainerEntityManagerFactory(Mockito.eq(punit),
                                                                             Mockito.anyMap());



Mime
View raw message