use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method createServerRegionWithPersistence.
private int createServerRegionWithPersistence(VM vm, final boolean persistentPdxRegistry) {
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
CacheFactory cf = new CacheFactory();
if (persistentPdxRegistry) {
cf.setPdxPersistent(true).setPdxDiskStore("store");
}
//
Cache cache = getCache(cf);
cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("store");
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
af.setDiskStoreName("store");
createRootRegion("testSimplePdx", af.create());
CacheServer server = getCache().addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.start();
return port;
}
};
return (Integer) vm.invoke(createRegion);
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxSerializableJUnitTest method testPdxPersistentKeysDefDS.
@Test
public void testPdxPersistentKeysDefDS() throws Exception {
this.c.close();
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).create();
try {
this.c.createDiskStoreFactory().create("r2DS");
Region r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r1");
r1.put(new SimpleClass(1, (byte) 1), "1");
r1.put(new SimpleClass(2, (byte) 2), "2");
// so we have something to compact offline
r1.put(new SimpleClass(1, (byte) 1), "1.2");
Region r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
r2.put(new SimpleClass(1, (byte) 1), new SimpleClass(1, (byte) 1));
r2.put(new SimpleClass(2, (byte) 2), new SimpleClass(2, (byte) 2));
this.c.close();
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).create();
this.c.createDiskStoreFactory().create("r2DS");
r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r1");
r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
this.c.close();
// use a cache.xml to recover
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").create();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true);
pw.println("<?xml version=\"1.0\"?>");
pw.println("<!DOCTYPE cache PUBLIC");
pw.println(" \"-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN\"");
pw.println(" \"http://www.gemstone.com/dtd/cache7_0.dtd\">");
pw.println("<cache>");
pw.println(" <disk-store name=\"r2DS\"/>");
pw.println(" <pdx persistent=\"true\"/>");
pw.println(" <region name=\"r1\" refid=\"LOCAL_PERSISTENT\">");
pw.println(" <region-attributes disk-store-name=\"r2DS\"/>");
pw.println(" </region>");
pw.println(" <region name=\"r2\" refid=\"LOCAL_PERSISTENT\">");
pw.println(" <region-attributes disk-store-name=\"r2DS\"/>");
pw.println(" </region>");
pw.println("</cache>");
pw.close();
byte[] bytes = baos.toByteArray();
this.c.loadCacheXml(new ByteArrayInputStream(bytes));
r1 = this.c.getRegion("/r1");
r2 = this.c.getRegion("/r2");
assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
this.c.close();
// make sure offlines tools work with disk store that has pdx keys
SystemAdmin.validateDiskStore("DEFAULT", ".");
SystemAdmin.compactDiskStore("DEFAULT", ".");
SystemAdmin.modifyDiskStore("DEFAULT", ".");
SystemAdmin.validateDiskStore("r2DS", ".");
SystemAdmin.compactDiskStore("r2DS", ".");
SystemAdmin.modifyDiskStore("r2DS", ".");
} finally {
try {
this.c.close();
} finally {
Pattern pattern = Pattern.compile("BACKUP(DEFAULT|r2DS).*");
File[] files = new File(".").listFiles((dir1, name) -> pattern.matcher(name).matches());
if (files != null) {
for (File file : files) {
Files.delete(file.toPath());
}
}
}
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxSerializableJUnitTest method testPdxPersistentKeys.
// for bugs 44271 and 44914
@Test
public void testPdxPersistentKeys() throws Exception {
this.c.close();
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).setPdxDiskStore("pdxDS").create();
try {
DiskStoreFactory dsf = this.c.createDiskStoreFactory();
dsf.create("pdxDS");
this.c.createDiskStoreFactory().create("r2DS");
Region r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).create("r1");
r1.put(new SimpleClass(1, (byte) 1), "1");
r1.put(new SimpleClass(2, (byte) 2), "2");
// so we have something to compact offline
r1.put(new SimpleClass(1, (byte) 1), "1.2");
Region r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
r2.put(new SimpleClass(1, (byte) 1), new SimpleClass(1, (byte) 1));
r2.put(new SimpleClass(2, (byte) 2), new SimpleClass(2, (byte) 2));
this.c.close();
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).setPdxDiskStore("pdxDS").create();
dsf = this.c.createDiskStoreFactory();
dsf.create("pdxDS");
this.c.createDiskStoreFactory().create("r2DS");
r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).create("r1");
r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
this.c.close();
// use a cache.xml to recover
this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").create();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true);
pw.println("<?xml version=\"1.0\"?>");
pw.println("<!DOCTYPE cache PUBLIC");
pw.println(" \"-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN\"");
pw.println(" \"http://www.gemstone.com/dtd/cache7_0.dtd\">");
pw.println("<cache>");
pw.println(" <disk-store name=\"r2DS\"/>");
pw.println(" <disk-store name=\"pdxDS\"/>");
pw.println(" <pdx persistent=\"true\" disk-store-name=\"pdxDS\"/>");
pw.println(" <region name=\"r1\" refid=\"LOCAL_PERSISTENT\"/>");
pw.println(" <region name=\"r2\" refid=\"LOCAL_PERSISTENT\">");
pw.println(" <region-attributes disk-store-name=\"r2DS\"/>");
pw.println(" </region>");
pw.println("</cache>");
pw.close();
byte[] bytes = baos.toByteArray();
this.c.loadCacheXml(new ByteArrayInputStream(bytes));
r1 = this.c.getRegion("/r1");
r2 = this.c.getRegion("/r2");
assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
this.c.close();
// make sure offlines tools work with disk store that has pdx keys
SystemAdmin.validateDiskStore("DEFAULT", ".");
SystemAdmin.compactDiskStore("DEFAULT", ".");
SystemAdmin.modifyDiskStore("DEFAULT", ".");
SystemAdmin.validateDiskStore("r2DS", ".");
SystemAdmin.compactDiskStore("r2DS", ".");
SystemAdmin.modifyDiskStore("r2DS", ".");
SystemAdmin.validateDiskStore("pdxDS", ".");
SystemAdmin.compactDiskStore("pdxDS", ".");
SystemAdmin.modifyDiskStore("pdxDS", ".");
} finally {
try {
this.c.close();
} finally {
Pattern pattern = Pattern.compile("BACKUP(DEFAULT|pdxDS|r2DS).*");
File[] files = new File(".").listFiles((dir1, name) -> pattern.matcher(name).matches());
if (files != null) {
for (File file : files) {
Files.delete(file.toPath());
}
}
}
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxSerializableDUnitTest method testPersistenceDefaultDiskStore.
@Test
public void testPersistenceDefaultDiskStore() throws Throwable {
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
// Make sure the type registry is persistent
CacheFactory cf = new CacheFactory();
cf.setPdxPersistent(true);
getCache(cf);
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
createRootRegion("testSimplePdx", af.create());
return null;
}
};
persistenceTest(createRegion);
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxAttributesJUnitTest method testDuplicatePdxTypeId.
@Test
public void testDuplicatePdxTypeId() throws Exception {
int dsId = 5;
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.set(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, String.valueOf(dsId));
Cache cache = cf.create();
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
Iterator itr = pdxRegion.entrySet().iterator();
boolean foundException = false;
boolean foundEnumException = false;
while (itr.hasNext()) {
Map.Entry ent = (Map.Entry) itr.next();
if (ent.getKey() instanceof Integer) {
int pdxTypeId = (int) ent.getKey();
try {
pdxRegion.put(pdxTypeId, new PdxType());
} catch (CacheWriterException cwe) {
foundException = true;
}
} else {
EnumId enumId = (EnumId) ent.getKey();
EnumInfo enumInfo = new EnumInfo(SimpleEnum.ONE);
try {
pdxRegion.put(enumId, enumInfo);
} catch (CacheWriterException cwe) {
foundEnumException = true;
}
}
}
assertEquals(true, foundException);
assertEquals(true, foundEnumException);
cache.close();
}
Aggregations