use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.
the class PdxQueryDUnitTest method testLocalPRQuery.
/**
* Tests query on with PR.
*/
@Test
public void testLocalPRQuery() throws CacheException {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
final int numberOfEntries = 100;
vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
configAndStartBridgeServer(true, true);
}
});
vm1.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
configAndStartBridgeServer(true, false);
}
});
vm2.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
configAndStartBridgeServer(true, false);
}
});
vm3.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
configAndStartBridgeServer(true, false);
}
});
// Load region using class loader and execute query on the same thread.
vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
try {
// Load TestObject
for (int i = 0; i < numberOfEntries; i++) {
PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("PortfolioPdxVersion", false);
PortfolioPdxVersion portfolioPdxVersion = new PortfolioPdxVersion(new Integer(i), new Integer(i));
PdxInstance pdxInstance = portfolioPdxVersion.createPdxInstance(pdxInstanceFactory);
region.put("key-" + i, pdxInstance);
}
} catch (Exception ex) {
Assert.fail("Failed to load the class.", ex);
}
QueryService localQueryService = null;
try {
localQueryService = region.getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
for (int i = 1; i < 3; i++) {
try {
logger.info("### Executing Query on server:" + queryString[i]);
Query query = localQueryService.newQuery(queryString[i]);
SelectResults rs = (SelectResults) query.execute();
assertEquals(numberOfEntries, rs.size());
} catch (Exception e) {
Assert.fail("Failed executing " + queryString[i], e);
}
}
}
});
this.closeClient(vm2);
this.closeClient(vm3);
this.closeClient(vm1);
this.closeClient(vm0);
}
use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.
the class PdxDeleteFieldJUnitTest method testPdxFieldDelete.
@Test
public void testPdxFieldDelete() throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
try {
Cache cache = (new CacheFactory(props)).create();
try {
PdxValue pdxValue = new PdxValue(1, 2L);
byte[] pdxValueBytes = BlobHelper.serializeToBlob(pdxValue);
{
PdxValue deserializedPdxValue = (PdxValue) BlobHelper.deserializeBlob(pdxValueBytes);
assertEquals(1, deserializedPdxValue.value);
assertEquals(2L, deserializedPdxValue.fieldToDelete);
}
PdxType pt;
// force PdxInstance on deserialization
DefaultQuery.setPdxReadSerialized(true);
try {
PdxInstanceImpl pi = (PdxInstanceImpl) BlobHelper.deserializeBlob(pdxValueBytes);
pt = pi.getPdxType();
assertEquals(1, pi.getField("value"));
assertEquals(2L, pi.getField("fieldToDelete"));
} finally {
DefaultQuery.setPdxReadSerialized(false);
}
assertEquals(PdxValue.class.getName(), pt.getClassName());
PdxField field = pt.getPdxField("fieldToDelete");
pt.setHasDeletedField(true);
field.setDeleted(true);
assertEquals(null, pt.getPdxField("fieldToDelete"));
assertEquals(2, pt.getFieldCount());
{
PdxValue deserializedPdxValue = (PdxValue) BlobHelper.deserializeBlob(pdxValueBytes);
assertEquals(1, deserializedPdxValue.value);
// fieldToDelete should now be 0 (the default) instead of 2.
assertEquals(0L, deserializedPdxValue.fieldToDelete);
}
// force PdxInstance on deserialization
DefaultQuery.setPdxReadSerialized(true);
try {
PdxInstance pi = (PdxInstance) BlobHelper.deserializeBlob(pdxValueBytes);
assertEquals(1, pi.getField("value"));
assertEquals(false, pi.hasField("fieldToDelete"));
assertEquals(null, pi.getField("fieldToDelete"));
assertSame(pt, ((PdxInstanceImpl) pi).getPdxType());
PdxValue deserializedPdxValue = (PdxValue) pi.getObject();
assertEquals(1, deserializedPdxValue.value);
assertEquals(0L, deserializedPdxValue.fieldToDelete);
} finally {
DefaultQuery.setPdxReadSerialized(false);
}
TypeRegistry tr = ((GemFireCacheImpl) cache).getPdxRegistry();
// Clear the local registry so we will regenerate a type for the same class
tr.testClearLocalTypeRegistry();
{
PdxInstanceFactory piFactory = cache.createPdxInstanceFactory(PdxValue.class.getName());
piFactory.writeInt("value", 1);
PdxInstance pi = piFactory.create();
assertEquals(1, pi.getField("value"));
assertEquals(null, pi.getField("fieldToDelete"));
PdxType pt2 = ((PdxInstanceImpl) pi).getPdxType();
assertEquals(null, pt2.getPdxField("fieldToDelete"));
assertEquals(1, pt2.getFieldCount());
}
} finally {
if (!cache.isClosed()) {
cache.close();
}
}
} finally {
}
}
use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.
the class TypedJsonJUnitTest method testPDXObject.
@Test
public void testPDXObject() {
final Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
DistributedSystem.connect(props);
Cache cache = new CacheFactory().create();
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
Portfolio p = new Portfolio(2);
pf.writeInt("ID", 111);
pf.writeString("status", "active");
pf.writeString("secId", "IBM");
pf.writeObject("portfolio", p);
PdxInstance pi = pf.create();
TypedJson tJsonObj = new TypedJson(RESULT, pi);
System.out.println(tJsonObj);
cache.close();
}
use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.
the class TypedJsonJUnitTest method testNestedPDXObject.
@Test
public void testNestedPDXObject() {
final Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
DistributedSystem.connect(props);
Cache cache = new CacheFactory().create();
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 111);
pf.writeString("status", "active");
pf.writeString("secId", "IBM");
PdxInstance pi = pf.create();
PDXContainer cont = new PDXContainer(1);
cont.setPi(pi);
TypedJson tJsonObj = new TypedJson(RESULT, cont);
System.out.println(tJsonObj);
cache.close();
}
use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.
the class QueryDataDUnitTest method putPdxInstances.
private void putPdxInstances(final String regionName) throws CacheException {
Region region = this.managementTestRule.getCache().getRegion(regionName);
PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pdxInstanceFactory.writeInt("ID", 111);
pdxInstanceFactory.writeString("status", "active");
pdxInstanceFactory.writeString("secId", "IBM");
PdxInstance pdxInstance = pdxInstanceFactory.create();
region.put("IBM", pdxInstance);
pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pdxInstanceFactory.writeInt("ID", 222);
pdxInstanceFactory.writeString("status", "inactive");
pdxInstanceFactory.writeString("secId", "YHOO");
pdxInstance = pdxInstanceFactory.create();
region.put("YHOO", pdxInstance);
pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pdxInstanceFactory.writeInt("ID", 333);
pdxInstanceFactory.writeString("status", "active");
pdxInstanceFactory.writeString("secId", "GOOGL");
pdxInstance = pdxInstanceFactory.create();
region.put("GOOGL", pdxInstance);
pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pdxInstanceFactory.writeInt("ID", 111);
pdxInstanceFactory.writeString("status", "inactive");
pdxInstanceFactory.writeString("secId", "VMW");
pdxInstance = pdxInstanceFactory.create();
region.put("VMW", pdxInstance);
}
Aggregations