use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class HashIndexQueryIntegrationTest method createPartitionedRegion.
private void createPartitionedRegion(String regionName, boolean synchMaintenance) throws ParseException {
Cache cache = CacheUtils.getCache();
PartitionAttributesFactory prAttFactory = new PartitionAttributesFactory();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setPartitionAttributes(prAttFactory.create());
attributesFactory.setIndexMaintenanceSynchronous(synchMaintenance);
RegionAttributes regionAttributes = attributesFactory.create();
region = cache.createRegion(regionName, regionAttributes);
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForMemLruWithMaxMem.
@Test
public void testPartitionedRegionAttributesForMemLruWithMaxMem() throws Exception {
final int redundantCopies = 1;
final int maxMem = 25;
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundantCopies);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
AttributesFactory fac = new AttributesFactory(attrs);
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, EvictionAction.LOCAL_DESTROY));
fac.setPartitionAttributes(paf.create());
cache.createRegion("parRoot", fac.create());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
RegionAttributes regionAttrs = region.getAttributes();
PartitionAttributes pa = regionAttrs.getPartitionAttributes();
EvictionAttributes ea = regionAttrs.getEvictionAttributes();
assertEquals(pa.getRedundantCopies(), 1);
assertEquals(pa.getLocalMaxMemory(), 100);
assertEquals(pa.getTotalMaxMemory(), 500);
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY);
assertNotSame(ea.getMaximum(), maxMem);
assertEquals(ea.getMaximum(), pa.getLocalMaxMemory());
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class QueryWithBucketParameterIntegrationTest method getPartitionAttributesFactoryWithPartitionResolver.
private PartitionAttributesFactory getPartitionAttributesFactoryWithPartitionResolver(int totalBuckets) {
PartitionAttributesFactory pAFactory = new PartitionAttributesFactory();
pAFactory.setRedundantCopies(1).setTotalNumBuckets(totalBuckets).setPartitionResolver(getPartitionResolver());
return pAFactory;
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class QueryJUnitTest method test007UndefinedResults.
@Test
public void test007UndefinedResults() {
CacheUtils.log("testQueryExceptionLogMessage");
Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
region.put("1", new Portfolio(1));
region.put("2", new Portfolio(0));
String queryStr = "SELECT DISTINCT * FROM /Portfolios.ketset";
Query q = CacheUtils.getQueryService().newQuery(queryStr);
Object results = null;
try {
results = q.execute();
} catch (Exception e) {
fail("Query execution failed " + e);
}
assertEquals(0, ((SelectResults) results).size());
PartitionAttributesFactory paf = new PartitionAttributesFactory();
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
region = CacheUtils.createRegion("PortfoliosPR", af.create(), false);
region.put("1", new Portfolio(1));
region.put("2", new Portfolio(0));
queryStr = "SELECT DISTINCT * FROM /PortfoliosPR.ketset";
q = CacheUtils.getQueryService().newQuery(queryStr);
try {
results = q.execute();
} catch (Exception e) {
fail("Query execution failed " + e);
}
assertEquals(0, ((SelectResults) results).size());
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PdxQueryDUnitTest method testPutAllWithIndexes.
/**
* This test creates 3 cache servers with a PR and one client which puts some PDX values in PR and
* runs a query. This was failing randomly in a POC.
*/
@Test
public void testPutAllWithIndexes() {
final String name = "testRegion";
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 Properties config = new Properties();
config.setProperty("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
// Start server
vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Cache cache = new CacheFactory(config).create();
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
prfactory.setRedundantCopies(0);
factory.setPartitionAttributes(prfactory.create());
cache.createRegionFactory(factory.create()).create(name);
try {
startCacheServer(0, false);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
// Create Index on empty region
try {
cache.getQueryService().createIndex("myFuncIndex", "intId", "/" + name);
} catch (Exception e) {
Assert.fail("index creation failed", e);
}
}
});
// Start server
vm1.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Cache cache = new CacheFactory(config).create();
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
prfactory.setRedundantCopies(0);
factory.setPartitionAttributes(prfactory.create());
cache.createRegionFactory(factory.create()).create(name);
try {
startCacheServer(0, false);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
}
});
// Start server
vm2.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Cache cache = new CacheFactory(config).create();
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
prfactory.setRedundantCopies(0);
factory.setPartitionAttributes(prfactory.create());
cache.createRegionFactory(factory.create()).create(name);
try {
startCacheServer(0, false);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
}
});
// Create client region
final int port = vm0.invoke(() -> PdxQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm2.getHost());
vm3.invoke(new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
Properties config = new Properties();
config.setProperty("mcast-port", "0");
ClientCache cache = new ClientCacheFactory(config).addPoolServer(host0, port).setPoolPRSingleHopEnabled(true).setPoolSubscriptionEnabled(true).create();
AttributesFactory factory = new AttributesFactory();
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(name);
}
});
vm3.invoke(new CacheSerializableRunnable("putAll() test") {
@Override
public void run2() throws CacheException {
try {
ClientCache cache = new ClientCacheFactory().create();
Region region = cache.getRegion(name);
QueryService queryService = cache.getQueryService();
String k;
for (int x = 0; x < 285; x++) {
k = Integer.valueOf(x).toString();
PortfolioPdx v = new PortfolioPdx(x, x);
region.put(k, v);
}
Query q = queryService.newQuery("SELECT DISTINCT * from /" + name + " WHERE ID = 2");
SelectResults qResult = (SelectResults) q.execute();
for (Object o : qResult.asList()) {
System.out.println("o = " + o);
}
} catch (Exception e) {
Assert.fail("Querying failed: ", e);
}
}
});
Invoke.invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
// }
}
Aggregations