Search in sources :

Example 21 with PartitionAttributesFactory

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Cache(org.apache.geode.cache.Cache)

Example 22 with PartitionAttributesFactory

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());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 23 with PartitionAttributesFactory

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;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory)

Example 24 with PartitionAttributesFactory

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());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with PartitionAttributesFactory

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");
// }
}
Also used : Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) Properties(java.util.Properties) CacheException(org.apache.geode.cache.CacheException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)340 AttributesFactory (org.apache.geode.cache.AttributesFactory)289 Region (org.apache.geode.cache.Region)173 Test (org.junit.Test)154 Cache (org.apache.geode.cache.Cache)136 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)116 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)112 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)110 VM (org.apache.geode.test.dunit.VM)101 Host (org.apache.geode.test.dunit.Host)99 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)95 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)75 CacheException (org.apache.geode.cache.CacheException)58 LocalRegion (org.apache.geode.internal.cache.LocalRegion)48 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)47 IOException (java.io.IOException)42 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)42 DiskStore (org.apache.geode.cache.DiskStore)41 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 BucketRegion (org.apache.geode.internal.cache.BucketRegion)35