use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class PdxRenameDUnitTest method testPdxRenameVersioning.
@Test
public void testPdxRenameVersioning() throws Exception {
final String DS_NAME = "PdxRenameDUnitTestDiskStore";
final String DS_NAME2 = "PdxRenameDUnitTestDiskStore2";
final int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final File f = new File(DS_NAME);
f.mkdir();
final File f2 = new File(DS_NAME2);
f2.mkdir();
this.filesToBeDeleted.add(DS_NAME);
this.filesToBeDeleted.add(DS_NAME2);
final Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + locatorPorts[0] + "],localhost[" + locatorPorts[1] + "]");
props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f });
dsf.create(DS_NAME);
RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME);
Region<String, PdxValue> region1 = rf1.create("region1");
region1.put("key1", new PdxValue(1));
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f2 });
dsf.create(DS_NAME2);
RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME2);
Region region1 = rf1.create("region1");
Object v = region1.get("key1");
assertNotNull(v);
cache.close();
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
}
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Collection<Object> renameResults = DiskStoreImpl.pdxRename(DS_NAME, new File[] { f }, "apache", "pivotal");
assertEquals(2, renameResults.size());
for (Object o : renameResults) {
if (o instanceof PdxType) {
PdxType t = (PdxType) o;
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", t.getClassName());
} else {
EnumInfo ei = (EnumInfo) o;
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$Day", ei.getClassName());
}
}
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f });
dsf.create(DS_NAME);
RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME);
Region<String, PdxValue> region1 = rf1.create("region1");
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f2 });
dsf.create(DS_NAME2);
RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME2);
Region region1 = rf1.create("region1");
PdxInstance v = (PdxInstance) region1.get("key1");
assertNotNull(v);
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", ((PdxInstanceImpl) v).getClassName());
cache.close();
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
}
return null;
}
});
}
use of org.apache.geode.pdx.PdxInstance 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.PdxInstance 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.PdxInstance 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);
}
use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class LuceneQueriesIntegrationTest method insertAJson.
private PdxInstance insertAJson(Region region, String key) {
String jsonCustomer = "{" + "\"name\": \"" + key + "\"," + "\"lastName\": \"Smith\"," + " \"age\": 25," + "\"address\":" + "{" + "\"streetAddress\": \"21 2nd Street\"," + "\"city\": \"New York\"," + "\"state\": \"NY\"," + "\"postalCode\": \"10021\"" + "}," + "\"phoneNumber\":" + "[" + "{" + " \"type\": \"home\"," + "\"number\": \"212 555-1234\"" + "}," + "{" + " \"type\": \"fax\"," + "\"number\": \"646 555-4567\"" + "}" + "]" + "}";
PdxInstance pdx = JSONFormatter.fromJSON(jsonCustomer);
region.put(key, pdx);
return pdx;
}
Aggregations