OPENJPA-1529 Committing L2 shared cache mode test cases contributed by Dianne Richards.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@915838 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jeremy Bauer 2010-02-24 16:01:26 +00:00
parent 05e0669c07
commit 0c76b25ef5
15 changed files with 626 additions and 11 deletions

View File

@ -19,6 +19,8 @@
package org.apache.openjpa.persistence.cache.jpa; package org.apache.openjpa.persistence.cache.jpa;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
@ -60,13 +62,21 @@ public abstract class AbstractCacheTestCase extends AbstractPersistenceTestCase
em.close(); em.close();
} }
public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName) { public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName,
Map<String, Object> additionalProperties) {
Map<String, Object> propertiesMap = getPropertiesMap("openjpa.DataCache", "true",
"openjpa.QueryCache", "true",
"openjpa.RemoteCommitProvider", "sjvm", persistentTypes,
"openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() });
if (additionalProperties != null) {
Set<String> keys = additionalProperties.keySet();
for (String key : keys) {
propertiesMap.put(key, additionalProperties.get(key));
}
}
OpenJPAEntityManagerFactorySPI emf = OpenJPAEntityManagerFactorySPI emf =
(OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(puName, (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(puName,
"META-INF/caching-persistence.xml", getPropertiesMap("openjpa.DataCache", "true", "META-INF/caching-persistence.xml", propertiesMap );
"openjpa.QueryCache", "true",
"openjpa.RemoteCommitProvider", "sjvm", persistentTypes,
"openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() } ));
return emf; return emf;
} }

View File

@ -39,7 +39,7 @@ public class TestCacheModeAll extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-all"); emf = createEntityManagerFactory("cache-mode-all",null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -47,7 +47,7 @@ public class TestCacheModeDisableSelective extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-disable"); emf = createEntityManagerFactory("cache-mode-disable", null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -38,7 +38,7 @@ public class TestCacheModeEmpty extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-empty"); emf = createEntityManagerFactory("cache-mode-empty", null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -47,7 +47,7 @@ public class TestCacheModeEnableSelective extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-enable"); emf = createEntityManagerFactory("cache-mode-enable", null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -0,0 +1,59 @@
/*
* 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.cache.jpa;
import java.util.Map;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.OpenJPAPersistence;
public class TestCacheModeInvalid extends AbstractCacheTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
@Override
public void setUp() {}
public void testInvalidElement() {
try {
Map<String, Object> propertiesMap = getPropertiesMap("openjpa.DataCache", "true",
"openjpa.QueryCache", "true",
"openjpa.RemoteCommitProvider", "sjvm", persistentTypes,
"openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() });
emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory("cache-mode-invalid",
"META-INF/caching-persistence-invalid.xml", propertiesMap );
} catch (Throwable e) {
assertException(e, org.apache.openjpa.util.GeneralException.class);
String msg = e.getMessage();
assertTrue(msg.contains("org.xml.sax.SAXException"));
}
}
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
return null;
}
@Override
public JDBCListener getListener() {
return null;
}
}

View File

@ -39,7 +39,7 @@ public class TestCacheModeNone extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-none"); emf = createEntityManagerFactory("cache-mode-none",null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -38,7 +38,7 @@ public class TestCacheModeUnspecified extends AbstractCacheModeTestCase {
@Override @Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) { if (emf == null) {
emf = createEntityManagerFactory("cache-mode-unspecified"); emf = createEntityManagerFactory("cache-mode-unspecified", null);
assertNotNull(emf); assertNotNull(emf);
cache = emf.getCache(); cache = emf.getCache();
assertNotNull(cache); assertNotNull(cache);

View File

@ -0,0 +1,86 @@
/*
* 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.cache.jpa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
public class TestPropertyCacheModeAll extends AbstractCacheModeTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
private static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
private static Class<?>[] expectedInCache = persistentTypes;
private static Class<?>[] expectedNotInCache = {};
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "ALL");
emf = createEntityManagerFactory("cache-mode-empty",propertyMap);
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
}
return emf;
}
public JDBCListener getListener() {
if (listener == null) {
listener = new Listener();
}
return listener;
}
public List<String> getSql() {
return sql;
}
public void testCacheables() {
assertCacheables(cache, true);
}
public void testUncacheables() {
assertUncacheables(cache, true);
}
public void testUnspecified() {
assertUnspecified(cache, true);
}
@Override
protected Class<?>[] getExpectedInCache() {
return expectedInCache;
}
@Override
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
}

View File

@ -0,0 +1,94 @@
/*
* 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.cache.jpa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
public class TestPropertyCacheModeDisableSelective extends AbstractCacheModeTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
private static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
private static Class<?>[] expectedInCache =
{ CacheableEntity.class, XmlCacheableEntity.class, NegatedUncacheableEntity.class, UnspecifiedEntity.class, };
private static Class<?>[] expectedNotInCache =
{ UncacheableEntity.class, XmlUncacheableEntity.class, };
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "DISABLE_SELECTIVE");
emf = createEntityManagerFactory("cache-mode-empty", propertyMap);
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
}
return emf;
}
public JDBCListener getListener() {
if (listener == null) {
listener = new Listener();
}
return listener;
}
public List<String> getSql() {
return sql;
}
public void testCacheables() {
assertCacheables(cache, true);
}
public void testUncacheables() {
assertUncacheables(cache, false);
}
public void testUnspecified() {
assertUnspecified(cache, true);
}
@Override
protected Class<?>[] getExpectedInCache() {
return expectedInCache;
}
@Override
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
}

View File

@ -0,0 +1,99 @@
/*
* 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.cache.jpa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
public class TestPropertyCacheModeEnableSelective extends AbstractCacheModeTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
private static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
private static Class<?>[] expectedInCache =
{ CacheableEntity.class, XmlCacheableEntity.class, NegatedUncacheableEntity.class, };
private static Class<?>[] expectedNotInCache =
{ UncacheableEntity.class, XmlUncacheableEntity.class, UnspecifiedEntity.class, };
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "ENABLE_SELECTIVE");
emf = createEntityManagerFactory("cache-mode-empty", propertyMap);
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
}
return emf;
}
public JDBCListener getListener() {
if (listener == null) {
listener = new Listener();
}
return listener;
}
public List<String> getSql() {
return sql;
}
@Override
protected Class<?>[] getExpectedInCache() {
return expectedInCache;
}
@Override
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
// =======================================================================
// Tests
// =======================================================================
public void testCacheables() {
assertCacheables(cache, true);
}
public void testUncacheables() {
assertUncacheables(cache, false);
}
public void testUnspecified() {
assertUnspecified(cache, false);
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.cache.jpa;
import java.util.HashMap;
import java.util.Map;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
public class TestPropertyCacheModeInvalid extends AbstractCacheTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
@Override
public void setUp() {}
public void testInvalidPropertyValue() {
try {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "INVALID");
emf = createEntityManagerFactory("cache-mode-empty",propertyMap);
} catch (Throwable e) {
assertException(e, java.lang.IllegalArgumentException.class);
String msg = e.getMessage();
assertTrue(msg.contains("javax.persistence.SharedCacheMode.INVALID"));
}
}
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
return null;
}
@Override
public JDBCListener getListener() {
return null;
}
}

View File

@ -0,0 +1,92 @@
/*
* 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.cache.jpa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
public class TestPropertyCacheModeNone extends AbstractCacheModeTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
private static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
private static Class<?>[] expectedInCache = {};
private static Class<?>[] expectedNotInCache = persistentTypes;
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "NONE");
emf = createEntityManagerFactory("cache-mode-empty", propertyMap);
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
}
return emf;
}
public JDBCListener getListener() {
if (listener == null) {
listener = new Listener();
}
return listener;
}
public List<String> getSql() {
return sql;
}
@Override
public boolean getCacheEnabled() {
return false;
}
public void testCacheables() {
assertCacheables(cache, false);
}
public void testUncacheables() {
assertUncacheables(cache, false);
}
public void testUnspecified() {
assertUnspecified(cache, false);
}
@Override
protected Class<?>[] getExpectedInCache() {
return expectedInCache;
}
@Override
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
}

View File

@ -0,0 +1,85 @@
/*
* 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.cache.jpa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
public class TestPropertyCacheModeUnspecified extends AbstractCacheModeTestCase {
private static OpenJPAEntityManagerFactorySPI emf = null;
private static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
private static Class<?>[] expectedInCache = persistentTypes;
private static Class<?>[] expectedNotInCache = {};
@Override
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
propertyMap.put("javax.persistence.sharedCache.mode", "UNSPECIFIED");
emf = createEntityManagerFactory("cache-mode-empty", propertyMap);
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
}
return emf;
}
public JDBCListener getListener() {
if (listener == null) {
listener = new Listener();
}
return listener;
}
public List<String> getSql() {
return sql;
}
public void testCacheables() {
assertCacheables(cache, true);
}
public void testUncacheables() {
assertUncacheables(cache, true);
}
public void testUnspecified() {
assertUnspecified(cache, true);
}
@Override
protected Class<?>[] getExpectedInCache() {
return expectedInCache;
}
@Override
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<!-- Caching Persistence Units -->
<persistence-unit name="cache-mode-invalid">
<mapping-file>META-INF/caching-orm.xml</mapping-file>
<shared-cache-mode>INVALID</shared-cache-mode>
<properties>
<!-- Connection info is passed in via system properties -->
<!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>