use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class BasicTest method testMetaDataMultithreaded.
/**
* Test for the MetaDataManager.
*/
public void testMetaDataMultithreaded() {
final MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
ThreadGroup group = new ThreadGroup("tgroup");
Thread[] threads = new Thread[500];
final List<String> errors = new ArrayList<>();
final Object lock = new Object();
for (int i = 0; i < 500; i++) {
threads[i] = new Thread(group, new Runnable() {
public void run() {
try {
synchronized (lock) {
lock.wait();
}
} catch (InterruptedException e) {
}
try {
// this populate and initilize the class
mgr.getMetaDataForClass(Manager.class, new ClassLoaderResolverImpl()).isPopulated();
} catch (Throwable e) {
e.printStackTrace();
errors.add(e.getMessage());
}
}
});
}
for (int i = 0; i < 500; i++) {
threads[i].start();
}
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
}
synchronized (lock) {
lock.notifyAll();
}
for (int i = 0; i < 500; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
assertEquals("Errors " + errors, 0, errors.size());
org.datanucleus.metadata.AbstractClassMetaData cmd2 = mgr.getMetaDataForClass(Book.class, new ClassLoaderResolverImpl());
if (cmd2 == null) {
fail("Failed to load MetaData for org.jpox.samples.store.Book class");
}
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class BasicTest method testDatastoreIdentityMetadata.
/**
* Tests datastore identity declared in many forms
*/
public void testDatastoreIdentityMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
assertEquals("identity", cmdD0.getIdentityMetaData().getValueStrategy().toString());
assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD1.getIdentityMetaData().getValueStrategy());
assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD2.getIdentityMetaData().getValueStrategy());
assertEquals("D_ID", cmdD0.getIdentityMetaData().getColumnMetaData().getName());
assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD1.getIdentityMetaData().getColumnMetaData().getName());
assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD2.getIdentityMetaData().getColumnMetaData().getName());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class BasicTest method testFieldColumnMetadata.
/**
* Tests the column field declared in many forms
*/
public void testFieldColumnMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
assertEquals("NNN", cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD1.getMetaDataForManagedMemberAtAbsolutePosition(cmdD1.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD2.getMetaDataForManagedMemberAtAbsolutePosition(cmdD2.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class BasicTest method testFieldDeclaredInSubClassMetadata.
/**
* Tests a field declared in the metadata of a subclass, like Subclass.field
*/
public void testFieldDeclaredInSubClassMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(Pet.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(Dog.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(Cat.class, new ClassLoaderResolverImpl());
assertNotNull(cmdD0.getMetaDataForMember("name"));
assertNotNull(cmdD1.getMetaDataForMember("name"));
assertEquals("dog", cmdD1.getMetaDataForMember("name").getColumnMetaData()[0].getName());
assertNotNull(cmdD2.getMetaDataForMember("name"));
assertEquals("cat", cmdD2.getMetaDataForMember("name").getColumnMetaData()[0].getName());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
metaDataMgr = new JDOMetaDataManager(nucleusCtx);
clr = new ClassLoaderResolverImpl();
}
Aggregations