use of javax.jdo.PersistenceManagerFactory in project tests by datanucleus.
the class PersistenceManagerFactoryTest method testServerTimeZoneID.
/**
* Test for serverTimeZoneID setting.
*/
public void testServerTimeZoneID() {
PersistenceManagerFactory pmf = null;
// Try setting the serverTimeZoneID to an invalid value
try {
Properties userProps = new Properties();
userProps.setProperty("javax.jdo.option.ServerTimeZoneID", "JPOX_CENTRAL_TIMEZONE");
pmf = getPMF(1, userProps);
fail("Expected a JDOUserException when setting the ServerTimeZoneID to an invalid value but worked!");
} catch (JDOFatalUserException jdoe) {
// Expected
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
// Try setting it to a valid value and make sure it is retained
try {
Properties userProps = new Properties();
userProps.setProperty("javax.jdo.option.ServerTimeZoneID", "UTC");
pmf = getPMF(1, userProps);
assertEquals("ServerTimeZoneID was not set correctly", ((JDOPersistenceManagerFactory) pmf).getServerTimeZoneID(), "UTC");
} catch (Exception e) {
fail("Exception thrown when setting the ServerTimeZoneID to UTC");
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
// Try leaving it unset and check the value
try {
pmf = getPMF(1, null);
assertEquals("ServerTimeZoneID was not set correctly", ((JDOPersistenceManagerFactory) pmf).getServerTimeZoneID(), null);
} catch (Exception e) {
fail("Exception thrown when setting the ServerTimeZoneID to UTC");
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
}
use of javax.jdo.PersistenceManagerFactory in project tests by datanucleus.
the class PersistenceManagerFactoryTest method testNullProperties.
/**
* Test setting a null for for a property value but string was expected
*/
public void testNullProperties() {
Properties props = TestHelper.getPropertiesForDatastore(1);
Map<Object, Object> map = new HashMap<>();
map.putAll(props);
map.put("javax.jdo.option.Mapping", null);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(map);
assertNotNull(pmf);
pmf.close();
}
use of javax.jdo.PersistenceManagerFactory in project tests by datanucleus.
the class DynamicEnhanceSchemaToolTest method persist.
public void persist(DynamicEnhanceSchemaToolClassLoader runtimeCL) throws Exception {
// Persist
Map props = getPropertiesForDatastore(runtimeCL);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(props);
try {
ClassLoaderResolver clr = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getClassLoaderResolver(runtimeCL);
JDOMetadata filemd = pmf.newMetadata();
createMetadata(filemd);
NucleusLogger.PERSISTENCE.info(">> registering metadata");
pmf.registerMetadata(filemd);
NucleusLogger.PERSISTENCE.info(filemd);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
Class clazz = clr.classForName("test.Client");
Object o = clazz.newInstance();
pm.makePersistent(o);
tx.commit();
id = pm.getObjectId(o);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Object obj = pm.getObjectById(id);
pm.deletePersistent(obj);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
pmf.close();
}
}
use of javax.jdo.PersistenceManagerFactory in project tests by datanucleus.
the class MultithreadPMTest method testEvictAllAndWrites.
/**
* Test changing the state
*/
public void testEvictAllAndWrites() {
Properties multiProps = new Properties();
multiProps.setProperty(PropertyNames.PROPERTY_MULTITHREADED, "true");
PersistenceManagerFactory myPMF = getPMF(1, multiProps);
try {
int THREAD_SIZE = 1000;
Thread[] threads = new Thread[THREAD_SIZE];
Thread[] threads2 = new Thread[THREAD_SIZE];
final PersistenceManager pm = myPMF.getPersistenceManager();
pm.currentTransaction().begin();
final Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
final Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
woody.setManager(bart);
pm.makePersistent(woody);
final Object id = pm.getObjectId(woody);
pm.currentTransaction().commit();
pm.currentTransaction().begin();
try {
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i] = new Thread(new Runnable() {
public void run() {
pm.getObjectById(id, true);
woody.setLastName("name");
woody.setManager(boss);
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads2[i] = new Thread(new Runnable() {
public void run() {
pm.evictAll();
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i].start();
threads2[i].start();
}
for (int i = 0; i < THREAD_SIZE; i++) {
try {
threads[i].join();
threads2[i].join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
} finally {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(myPMF);
myPMF.close();
}
}
use of javax.jdo.PersistenceManagerFactory in project tests by datanucleus.
the class MultithreadPMTest method testMultipleTransitionRead.
/**
* Test changing the state
*/
public void testMultipleTransitionRead() {
Properties multiProps = new Properties();
multiProps.setProperty(PropertyNames.PROPERTY_MULTITHREADED, "true");
PersistenceManagerFactory myPMF = getPMF(1, multiProps);
try {
int THREAD_SIZE = 1000;
Thread[] threads = new Thread[THREAD_SIZE];
PersistenceManager pm = myPMF.getPersistenceManager();
pm.currentTransaction().begin();
final Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
woody.setManager(bart);
pm.makePersistent(woody);
pm.currentTransaction().commit();
pm.currentTransaction().begin();
try {
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i] = new Thread(new Runnable() {
public void run() {
woody.getLastName();
woody.getManager().getLastName();
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i].start();
}
for (int i = 0; i < THREAD_SIZE; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
} finally {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(myPMF);
myPMF.close();
}
}
Aggregations