use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testConstrainedKeys.
/**
* Tests creating a cache whose keys are constrained
*/
@Test
public void testConstrainedKeys() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setKeyConstraint(String.class);
cache.createRegion("root", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml80DUnitTest method testIndexXmlCreation.
/**
* Tests xml creation for indexes First creates 3 indexes and makes sure the cache creates all 3
* Creates a 4th through the api and writes out the xml Restarts the cache with the new xml Makes
* sure the new cache has the 4 indexes
*/
@Test
public void testIndexXmlCreation() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.REPLICATE);
cache.createRegion("replicated", attrs);
cache.getQueryService().createIndex("crIndex", "CR_ID", "/replicated");
cache.getQueryService().createHashIndex("hashIndex", "HASH_ID", "/replicated");
cache.getQueryService().createKeyIndex("primaryKeyIndex", "ID", "/replicated");
testXml(cache);
Cache c = getCache();
assertNotNull(c);
QueryService qs = c.getQueryService();
Collection<Index> indexes = qs.getIndexes();
assertEquals(3, indexes.size());
c.getQueryService().createIndex("crIndex2", "r.CR_ID_2", "/replicated r");
c.getQueryService().createIndex("rIndex", "r.R_ID", "/replicated r, r.positions.values rv");
File dir = new File(this.temporaryFolder.getRoot(), "XML_" + this.getGemFireVersion());
dir.mkdirs();
File file = new File(dir, "actual-" + getUniqueName() + ".xml");
PrintWriter pw = new PrintWriter(new FileWriter(file), true);
CacheXmlGenerator.generate(c, pw, getUseSchema(), getGemFireVersion());
pw.close();
// Get index info before closing cache.
indexes = qs.getIndexes();
c.close();
GemFireCacheImpl.testCacheXml = file;
assertTrue(c.isClosed());
c = getCache();
qs = c.getQueryService();
Collection<Index> newIndexes = qs.getIndexes();
assertEquals(5, newIndexes.size());
Region r = c.getRegion("/replicated");
for (int i = 0; i < 5; i++) {
r.put(i, new TestObject(i));
}
// Validate to see, newly created indexes match the initial configuration
for (Index index : indexes) {
Index newIndex = qs.getIndex(r, index.getName());
assertEquals("Index from clause is not same for index " + index.getName(), newIndex.getFromClause(), index.getFromClause());
assertEquals("Index expression is not same for index " + index.getName(), newIndex.getIndexedExpression(), index.getIndexedExpression());
}
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
SelectResults results = (SelectResults) qs.newQuery("select * from /replicated r where r.ID = 1").execute();
assertEquals(1, results.size());
assertTrue(checkIndexUsed(observer, "primaryKeyIndex"));
observer.reset();
results = (SelectResults) qs.newQuery("select * from /replicated r where r.CR_ID = 1").execute();
assertEquals(2, results.size());
assertTrue(checkIndexUsed(observer, "crIndex"));
observer.reset();
results = (SelectResults) qs.newQuery("select * from /replicated r where r.CR_ID_2 = 1").execute();
assertEquals(2, results.size());
assertTrue(checkIndexUsed(observer, "crIndex2"));
observer.reset();
results = (SelectResults) qs.newQuery("select * from /replicated r, r.positions.values rv where r.R_ID > 1").execute();
assertEquals(3, results.size());
assertTrue(checkIndexUsed(observer, "rIndex"));
observer.reset();
results = (SelectResults) qs.newQuery("select * from /replicated r where r.HASH_ID = 1").execute();
assertEquals(1, results.size());
assertTrue(checkIndexUsed(observer, "hashIndex"));
observer.reset();
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml80DUnitTest method testDiskUsage.
@Test
public void testDiskUsage() throws Exception {
CacheCreation cache = new CacheCreation();
DiskStoreAttributesCreation disk = new DiskStoreAttributesCreation();
disk.setDiskUsageWarningPercentage(97);
disk.setDiskUsageCriticalPercentage(98);
disk.setName("mydisk");
cache.addDiskStore(disk);
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
attrs.setDiskStoreName("mydisk");
cache.createVMRegion("whatever", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml80DUnitTest method testCacheServerEnableTcpNoDelay.
@Test
public void testCacheServerEnableTcpNoDelay() throws Exception {
CacheCreation cache = new CacheCreation();
CacheServer cs = cache.addCacheServer();
cs.setPort(0);
cs.setTcpNoDelay(true);
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
cache.createVMRegion("rootNORMAL", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testBridgeAttributesRelatedToHAOverFlow.
/**
* Tests the client subscription attributes ({@code eviction-policy}, {@code capacity} and
* {@code overflow-directory}) related to client subscription config in gemfire cache-server
* framework
*
* @since GemFire 5.7
*/
@Test
public void testBridgeAttributesRelatedToHAOverFlow() throws Exception {
CacheCreation cache = new CacheCreation();
cache.setMessageSyncInterval(3445);
CacheServer bs = cache.addCacheServer();
ClientSubscriptionConfig csc = bs.getClientSubscriptionConfig();
csc.setEvictionPolicy("entry");
cache.getLogger().config("EvictionPolicy : " + csc.getEvictionPolicy());
csc.setCapacity(501);
cache.getLogger().config("EvictionCapacity : " + csc.getCapacity());
csc.setOverflowDirectory("overFlow");
cache.getLogger().config("EvictionOverflowDirectory : " + csc.getOverflowDirectory());
bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
cache.createVMRegion("rootNORMAL", attrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
assertNotNull(server);
ClientSubscriptionConfig chaqf = server.getClientSubscriptionConfig();
assertEquals("entry", chaqf.getEvictionPolicy());
assertEquals(501, chaqf.getCapacity());
assertEquals("overFlow", chaqf.getOverflowDirectory());
}
Aggregations