Search in sources :

Example 41 with RegionFactory

use of org.apache.geode.cache.RegionFactory in project geode by apache.

the class GemfireDataCommandsDUnitTest method createParReg.

private Region<?, ?> createParReg(String regionName, Cache cache) {
    RegionFactory regionFactory = cache.createRegionFactory();
    regionFactory.setDataPolicy(DataPolicy.PARTITION);
    return regionFactory.create(regionName);
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory)

Example 42 with RegionFactory

use of org.apache.geode.cache.RegionFactory in project geode by apache.

the class PdxClientServerDUnitTest method createServerRegion.

private int createServerRegion(final Class constraintClass) throws IOException {
    CacheFactory cf = new CacheFactory(getDistributedSystemProperties());
    Cache cache = getCache(cf);
    RegionFactory rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
    rf.setValueConstraint(constraintClass);
    rf.create("testSimplePdx");
    CacheServer server = cache.addCacheServer();
    int port = AvailablePortHelper.getRandomAvailableTCPPort();
    server.setPort(port);
    server.start();
    return port;
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheServer(org.apache.geode.cache.server.CacheServer) 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)

Example 43 with RegionFactory

use of org.apache.geode.cache.RegionFactory in project geode by apache.

the class SSLNoClientAuthDUnitTest method setUpServerVM.

@SuppressWarnings("rawtypes")
public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
    Properties gemFireProps = new Properties();
    String cacheServerSslprotocols = "any";
    String cacheServerSslciphers = "any";
    boolean cacheServerSslRequireAuth = false;
    gemFireProps.put(SERVER_SSL_ENABLED, String.valueOf(cacheServerSslenabled));
    gemFireProps.put(SERVER_SSL_PROTOCOLS, cacheServerSslprotocols);
    gemFireProps.put(SERVER_SSL_CIPHERS, cacheServerSslciphers);
    gemFireProps.put(SERVER_SSL_REQUIRE_AUTHENTICATION, String.valueOf(cacheServerSslRequireAuth));
    String keyStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
    String trustStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
    gemFireProps.put(SERVER_SSL_KEYSTORE_TYPE, "jks");
    gemFireProps.put(SERVER_SSL_KEYSTORE, keyStore);
    gemFireProps.put(SERVER_SSL_KEYSTORE_PASSWORD, "password");
    gemFireProps.put(SERVER_SSL_TRUSTSTORE, trustStore);
    gemFireProps.put(SERVER_SSL_TRUSTSTORE_PASSWORD, "password");
    StringWriter sw = new StringWriter();
    PrintWriter writer = new PrintWriter(sw);
    gemFireProps.list(writer);
    System.out.println("Starting cacheserver ds with following properties \n" + sw);
    createCache(gemFireProps);
    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
    Region r = factory.create("serverRegion");
    r.put("serverkey", "servervalue");
}
Also used : StringWriter(java.io.StringWriter) RegionFactory(org.apache.geode.cache.RegionFactory) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PrintWriter(java.io.PrintWriter)

Example 44 with RegionFactory

use of org.apache.geode.cache.RegionFactory in project geode by apache.

the class InitializeIndexEntryDestroyQueryDUnitTest method testConcurrentRemoveIndexAndQueryOnPR.

@Test
public void testConcurrentRemoveIndexAndQueryOnPR() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    setCacheInVMs(vm0);
    name = "PartionedPortfoliosPR";
    // Create Local Region
    vm0.invoke(new CacheSerializableRunnable("Create local region with asynchronous index maintenance") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionRegion = null;
            try {
                AttributesFactory attr = new AttributesFactory();
                attr.setValueConstraint(PortfolioData.class);
                attr.setIndexMaintenanceSynchronous(false);
                attr.setPartitionAttributes(new PartitionAttributesFactory().create());
                RegionFactory regionFactory = cache.createRegionFactory(attr.create());
                partitionRegion = regionFactory.create(name);
            } catch (IllegalStateException ex) {
                LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
            }
            assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
            assertNotNull("Region ref null", partitionRegion);
            assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
        }
    });
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    // Putting the data into the PR's created
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    vm0.invoke(new CacheSerializableRunnable("Create Index") {

        @Override
        public void run2() throws CacheException {
            // Create Index first to go in hook.
            Cache cache = getCache();
            Index sindex = null;
            Index iindex = null;
            Index pkindex = null;
            try {
                sindex = cache.getQueryService().createIndex("statusIndex", "p.status", "/" + name + " p");
                iindex = cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
                pkindex = cache.getQueryService().createIndex("pkidIndex", "p.pk", "/" + name + " p");
            } catch (Exception e1) {
                e1.printStackTrace();
                fail("Index creation failed");
            }
            assertNotNull(sindex);
            assertNotNull(iindex);
            assertNotNull(pkindex);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Run query on region") {

        @Override
        public void run2() throws CacheException {
            // Do a put in region.
            Query query = getCache().getQueryService().newQuery("select * from /" + name + " p where p.status = 'active' and p.ID > 0 and p.pk != ' ' ");
            // Now run the query
            SelectResults results = null;
            for (int i = 0; i < 10; i++) {
                try {
                    getCache().getLogger().fine("Querying the region with " + query);
                    results = (SelectResults) query.execute();
                } catch (Exception e) {
                    Assert.fail("Query: " + query + " execution failed with exception", e);
                }
                for (Object obj : results) {
                    if (obj instanceof Undefined) {
                        fail("Found an undefined element" + Arrays.toString(results.toArray()));
                    }
                }
            }
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Create Index") {

        @Override
        public void run2() throws CacheException {
            Region r = getCache().getRegion(name);
            // Create Index first to go in hook.
            getCache().getQueryService().removeIndexes(r);
        }
    });
}
Also used : Undefined(org.apache.geode.cache.query.internal.Undefined) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) Index(org.apache.geode.cache.query.Index) CacheException(org.apache.geode.cache.CacheException) 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) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Utils.createPortfolioData(org.apache.geode.cache.query.Utils.createPortfolioData) Cache(org.apache.geode.cache.Cache) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 45 with RegionFactory

use of org.apache.geode.cache.RegionFactory in project geode by apache.

the class MultiVMRegionTestCase method createRegionWithAttribute.

protected void createRegionWithAttribute(VM vm, final String name, final boolean syncDiskWrite) {
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        @Override
        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                f.setDiskSynchronous(syncDiskWrite);
                CCRegion = (LocalRegion) f.create(name);
            } catch (CacheException ex) {
                fail("While creating region", ex);
            }
        }
    };
    vm.invoke(createRegion);
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable)

Aggregations

RegionFactory (org.apache.geode.cache.RegionFactory)124 Region (org.apache.geode.cache.Region)63 Cache (org.apache.geode.cache.Cache)57 Test (org.junit.Test)54 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)51 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)44 VM (org.apache.geode.test.dunit.VM)44 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)31 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 CacheException (org.apache.geode.cache.CacheException)30 Host (org.apache.geode.test.dunit.Host)28 Properties (java.util.Properties)25 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)22 File (java.io.File)21 DiskStore (org.apache.geode.cache.DiskStore)20 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)20 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)17 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)17