Search in sources :

Example 1 with RegionFactory

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

the class GatewayDeltaForwarderCacheListener method createOrRetrieveGatewayDeltaRegion.

@SuppressWarnings("unchecked")
private LocalRegion createOrRetrieveGatewayDeltaRegion() {
    Region region = this.cache.getRegion(GatewayDelta.GATEWAY_DELTA_REGION_NAME);
    if (region == null) {
        region = new RegionFactory().setScope(Scope.LOCAL).setDataPolicy(DataPolicy.EMPTY).setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)).addCacheListener(new GatewayDeltaEventApplicationCacheListener()).create(GatewayDelta.GATEWAY_DELTA_REGION_NAME);
    }
    if (this.cache.getLogger().fineEnabled()) {
        StringBuilder builder = new StringBuilder();
        builder.append("GatewayDeltaForwarderCacheListener: Created gateway delta region: ").append(region);
        this.cache.getLogger().fine(builder.toString());
    }
    return (LocalRegion) region;
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) LocalRegion(org.apache.geode.internal.cache.LocalRegion) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 2 with RegionFactory

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

the class CacheServerSSLConnectionDUnitTest method setUpServerVM.

@SuppressWarnings("rawtypes")
public void setUpServerVM(final boolean cacheServerSslenabled, final boolean legacy) throws Exception {
    Properties gemFireProps = new Properties();
    String cacheServerSslprotocols = "any";
    String cacheServerSslciphers = "any";
    boolean cacheServerSslRequireAuth = true;
    if (!legacy) {
        gemFireProps.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.CLUSTER + "," + SecurableCommunicationChannel.SERVER);
        gemFireProps.put(SSL_PROTOCOLS, cacheServerSslprotocols);
        gemFireProps.put(SSL_CIPHERS, cacheServerSslciphers);
        gemFireProps.put(SSL_REQUIRE_AUTHENTICATION, String.valueOf(cacheServerSslRequireAuth));
        String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_KEY_STORE);
        String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_TRUST_STORE);
        gemFireProps.put(SSL_KEYSTORE_TYPE, "jks");
        gemFireProps.put(SSL_KEYSTORE, keyStore);
        gemFireProps.put(SSL_KEYSTORE_PASSWORD, "password");
        gemFireProps.put(SSL_TRUSTSTORE, trustStore);
        gemFireProps.put(SSL_TRUSTSTORE_PASSWORD, "password");
    } else {
        gemFireProps.put(CLUSTER_SSL_ENABLED, String.valueOf(cacheServerSslenabled));
        gemFireProps.put(CLUSTER_SSL_PROTOCOLS, cacheServerSslprotocols);
        gemFireProps.put(CLUSTER_SSL_CIPHERS, cacheServerSslciphers);
        gemFireProps.put(CLUSTER_SSL_REQUIRE_AUTHENTICATION, String.valueOf(cacheServerSslRequireAuth));
        String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_KEY_STORE);
        String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_TRUST_STORE);
        gemFireProps.put(CLUSTER_SSL_KEYSTORE_TYPE, "jks");
        gemFireProps.put(CLUSTER_SSL_KEYSTORE, keyStore);
        gemFireProps.put(CLUSTER_SSL_KEYSTORE_PASSWORD, "password");
        gemFireProps.put(CLUSTER_SSL_TRUSTSTORE, trustStore);
        gemFireProps.put(CLUSTER_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 3 with RegionFactory

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

the class ClientServerRegisterInterestsDUnitTest method setupGemFireCacheServer.

private void setupGemFireCacheServer() {
    Host localhost = Host.getHost(0);
    gemfireServerVm = localhost.getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    gemfireServerVm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0").set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory();
                regionFactory.setDataPolicy(DataPolicy.REPLICATE);
                regionFactory.setKeyConstraint(String.class);
                regionFactory.setValueConstraint(String.class);
                Region<String, String> example = regionFactory.create("Example");
                assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
                assertEquals("/Example", example.getFullPath());
                assertEquals("Example", example.getName());
                assertTrue(example.isEmpty());
                example.put("1", "ONE");
                assertFalse(example.isEmpty());
                assertEquals(1, example.size());
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();
                clientSubscriptionConfig.setCapacity(100);
                clientSubscriptionConfig.setEvictionPolicy("entry");
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException(String.format("Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", serverPort.get()), e);
            }
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) RegionFactory(org.apache.geode.cache.RegionFactory) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 4 with RegionFactory

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

the class RemoveAllCacheListenerClientServerRegressionTest method setupGemFireCacheServer.

// ================================================================================
private void setupGemFireCacheServer(RegionShortcut shortcut, boolean concChecks) {
    serverVM = Host.getHost(0).getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    String serverName = this.getClass().getSimpleName() + "_server";
    serverVM.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", serverName).set(MCAST_PORT, "0").set(LOG_FILE, serverName + ".log").set(LOG_LEVEL, "config").set("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory(shortcut);
                regionFactory.addCacheListener(new TestListener());
                regionFactory.setConcurrencyChecksEnabled(concChecks);
                regionFactory.create(REGION_NAME);
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException("Failed to start cache server " + serverName + " on port " + serverPort.get() + ": " + e.getStackTrace());
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 5 with RegionFactory

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

the class ConcurrentIndexInitOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryDestroyAndQueryOnRR.

/**
  *
  */
@Test
public void testAsyncIndexInitDuringEntryDestroyAndQueryOnRR() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    name = "PartionedPortfoliosPR";
    // Create Overflow Persistent Partition Region
    vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionRegion = null;
            IndexManager.testHook = null;
            try {
                DiskStore ds = cache.findDiskStore("disk");
                if (ds == null) {
                    ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
                }
                AttributesFactory attr = new AttributesFactory();
                attr.setValueConstraint(PortfolioData.class);
                attr.setIndexMaintenanceSynchronous(true);
                EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
                evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
                attr.setEvictionAttributes(evicAttr);
                attr.setDataPolicy(DataPolicy.REPLICATE);
                // attr.setPartitionAttributes(new
                // PartitionAttributesFactory().setTotalNumBuckets(1).create());
                attr.setDiskStoreName("disk");
                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());
            // Create Indexes
            try {
                Index index = cache.getQueryService().createIndex("statusIndex", "p.status", "/" + name + " p");
                assertNotNull(index);
            } catch (Exception e1) {
                e1.printStackTrace();
                fail("Index creation failed");
            }
        }
    });
    // Start changing the value in Region which should turn into a deadlock if
    // the fix is not there
    AsyncInvocation asyncInv1 = vm0.invokeAsync(new CacheSerializableRunnable("Change value in region") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Do a put in region.
            Region r = getCache().getRegion(name);
            for (int i = 0; i < 100; i++) {
                r.put(i, new PortfolioData(i));
            }
            assertNull(IndexManager.testHook);
            IndexManager.testHook = new IndexManagerTestHook();
            // Destroy one of the values.
            getCache().getLogger().fine("Destroying the value");
            r.destroy(1);
            IndexManager.testHook = null;
        }
    });
    AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            while (!hooked) {
                Wait.pause(100);
            }
            // Create and hence initialize Index
            try {
                Index index = cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
                assertNotNull(index);
            } catch (Exception e1) {
                e1.printStackTrace();
                fail("Index creation failed");
            }
        }
    });
    // If we take more than 30 seconds then its a deadlock.
    ThreadUtils.join(asyncInv2, 30 * 1000);
    ThreadUtils.join(asyncInv1, 30 * 1000);
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) Index(org.apache.geode.cache.query.Index) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionFactory(org.apache.geode.cache.RegionFactory) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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