Search in sources :

Example 56 with RegionFactory

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

the class PersistentRecoveryOrderDUnitTest method createPersistentRegionAsync.

protected AsyncInvocation createPersistentRegionAsync(final VM vm, final boolean diskSynchronous) {
    SerializableRunnable createRegion = new SerializableRunnable("Create persistent region") {

        public void run() {
            Cache cache = getCache();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            File dir = getDiskDirForVM(vm);
            dir.mkdirs();
            dsf.setDiskDirs(new File[] { dir });
            dsf.setMaxOplogSize(1);
            DiskStore ds = dsf.create(REGION_NAME);
            RegionFactory rf = new RegionFactory();
            rf.setDiskStoreName(ds.getName());
            rf.setDiskSynchronous(diskSynchronous);
            rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            rf.setScope(Scope.DISTRIBUTED_ACK);
            rf.create(REGION_NAME);
        }
    };
    return vm.invokeAsync(createRegion);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionFactory(org.apache.geode.cache.RegionFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 57 with RegionFactory

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

the class PersistentRVVRecoveryDUnitTest method testUpdateRVVWithAsyncPersistence.

/**
   * Test that with concurrent updates to an async disk region, we correctly update the RVV On disk
   */
@Test
public void testUpdateRVVWithAsyncPersistence() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(1);
    SerializableRunnable createRegion = new SerializableRunnable("Create persistent region") {

        public void run() {
            Cache cache = getCache();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            File dir = getDiskDirForVM(vm0);
            dir.mkdirs();
            dsf.setDiskDirs(new File[] { dir });
            dsf.setMaxOplogSize(1);
            dsf.setQueueSize(100);
            dsf.setTimeInterval(1000);
            DiskStore ds = dsf.create(REGION_NAME);
            RegionFactory rf = new RegionFactory();
            rf.setDiskStoreName(ds.getName());
            rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            rf.setScope(Scope.DISTRIBUTED_ACK);
            rf.setDiskSynchronous(false);
            rf.create(REGION_NAME);
        }
    };
    // Create a region with async persistence
    vm0.invoke(createRegion);
    // In two different threads, perform updates to the same key on the same region
    AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm0") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(REGION_NAME);
            for (int i = 0; i < 500; i++) {
                region.put("A", "vm0-" + i);
            }
        }
    });
    AsyncInvocation ins1 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm1") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(REGION_NAME);
            for (int i = 0; i < 500; i++) {
                region.put("A", "vm1-" + i);
            }
        }
    });
    // Wait for the update threads to finish.
    ins0.getResult(MAX_WAIT);
    ins1.getResult(MAX_WAIT);
    // Make sure the async queue is flushed to disk
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore(REGION_NAME);
            ds.flush();
        }
    });
    // Assert that the disk has seen all of the updates
    RegionVersionVector rvv = getRVV(vm0);
    RegionVersionVector diskRVV = getDiskRVV(vm0);
    assertSameRVV(rvv, diskRVV);
    // Bounce the cache and make the same assertion
    closeCache(vm0);
    vm0.invoke(createRegion);
    // Assert that the recovered RVV is the same as before the restart
    RegionVersionVector rvv2 = getRVV(vm0);
    assertSameRVV(rvv, rvv2);
    // The disk RVV should also match.
    RegionVersionVector diskRVV2 = getDiskRVV(vm0);
    assertSameRVV(rvv2, diskRVV2);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 58 with RegionFactory

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

the class ForceInvalidateEvictionDUnitTest method createPR.

private void createPR(VM vm) {
    final String name = getUniqueName();
    vm.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            RegionFactory rf = new RegionFactory();
            rf.setOffHeap(isOffHeapEnabled());
            rf.setDataPolicy(DataPolicy.PARTITION);
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(5);
            rf.setPartitionAttributes(paf.create());
            rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1));
            rf.setConcurrencyChecksEnabled(false);
            rf.create(name);
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 59 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 60 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)

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