Search in sources :

Example 56 with DiskStore

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

the class PersistentColocatedPartitionedRegionDUnitTest method testRebalanceWithOfflineChildRegion.

// GEODE-506: time sensitive, async actions with 30 sec max
@Category(FlakyTest.class)
@Test
public void testRebalanceWithOfflineChildRegion() throws Throwable {
    SerializableRunnable createParentPR = new SerializableRunnable("createParentPR") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            paf.setRecoveryDelay(0);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
        }
    };
    SerializableRunnable createChildPR = new SerializableRunnable("createChildPR") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            paf.setRecoveryDelay(0);
            paf.setColocatedWith(PR_REGION_NAME);
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    rebalanceWithOfflineChildRegion(createParentPR, createChildPR);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 57 with DiskStore

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

the class PersistentColocatedPartitionedRegionDUnitTest method createColocatedPRs.

/**
   * Create three PRs on a VM, named region1, region2, and region3. The colocated with attribute
   * describes which region region3 should be colocated with.
   * 
   * @param colocatedWith
   */
private void createColocatedPRs(final String colocatedWith) {
    Cache cache = getCache();
    DiskStore ds = cache.findDiskStore("disk");
    if (ds == null) {
        ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
    }
    AttributesFactory af = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(0);
    af.setPartitionAttributes(paf.create());
    af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
    af.setDiskStoreName("disk");
    cache.createRegion("region1", af.create());
    cache.createRegion("region2", af.create());
    if (colocatedWith != null) {
        paf.setColocatedWith(colocatedWith);
    }
    af.setPartitionAttributes(paf.create());
    cache.createRegion("region3", af.create());
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) Cache(org.apache.geode.cache.Cache)

Example 58 with DiskStore

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

the class PersistentColocatedPartitionedRegionDUnitTest method testColocatedPRs.

/**
   * Testing that we can colocate persistent PRs
   */
@Test
public void testColocatedPRs() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    SerializableRunnable createPRs = new SerializableRunnable("region1") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
            paf.setColocatedWith("region2");
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PARTITION);
            af.setDiskStoreName(null);
            cache.createRegion("region3", af.create());
        }
    };
    vm0.invoke(createPRs);
    vm1.invoke(createPRs);
    vm2.invoke(createPRs);
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "b", "region2");
    createData(vm0, 0, NUM_BUCKETS, "c", "region3");
    Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
    assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
    assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
    Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
    assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
    assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
    Set<Integer> vm2Buckets = getBucketList(vm2, PR_REGION_NAME);
    assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
    assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
    closeCache(vm0);
    closeCache(vm1);
    closeCache(vm2);
    AsyncInvocation async0 = vm0.invokeAsync(createPRs);
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    AsyncInvocation async2 = vm2.invokeAsync(createPRs);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    async2.getResult(MAX_WAIT);
    // The secondary buckets can be recovered asynchronously,
    // so wait for them to come back.
    waitForBuckets(vm0, vm0Buckets, PR_REGION_NAME);
    waitForBuckets(vm0, vm0Buckets, "region2");
    waitForBuckets(vm1, vm1Buckets, PR_REGION_NAME);
    waitForBuckets(vm1, vm1Buckets, "region2");
    checkData(vm0, 0, NUM_BUCKETS, "a");
    checkData(vm0, 0, NUM_BUCKETS, "b", "region2");
    // region 3 didn't have persistent data, so it nothing should be recovered
    checkData(vm0, 0, NUM_BUCKETS, null, "region3");
    // Make sure can do a put in all of the buckets in region 3
    createData(vm0, 0, NUM_BUCKETS, "c", "region3");
    // Now all of those buckets should exist.
    checkData(vm0, 0, NUM_BUCKETS, "c", "region3");
    // The region 3 buckets should be restored in the appropriate places.
    assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
    assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
    assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 59 with DiskStore

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

the class PersistentPartitionedRegionDUnitTest method testSinglePRWithCustomExpiry.

/**
   * Test for bug 44184
   */
@Test
public void testSinglePRWithCustomExpiry() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(1);
    SerializableRunnable createPR = new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            af.setPartitionAttributes(paf.create());
            af.setCustomEntryIdleTimeout(new TestCustomExpiration());
            af.setEntryIdleTimeout(new ExpirationAttributes(60, ExpirationAction.INVALIDATE));
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            RegionAttributes attr = af.create();
            cache.createRegion(PR_REGION_NAME, attr);
        }
    };
    vm0.invoke(createPR);
    createData(vm0, 0, 1, "a");
    Set<Integer> vm0Buckets = getBucketList(vm0);
    // closePR(vm0);
    closeCache(vm0);
    vm0.invoke(createPR);
    assertEquals(vm0Buckets, getBucketList(vm0));
    checkData(vm0, 0, 1, "a");
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 60 with DiskStore

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

the class PersistentColocatedPartitionedRegionDUnitTest method testRebalanceWithOfflineChildRegionTwoDiskStores.

// GEODE-1380: time sensitive, async actions with 30 sec max
@Category(FlakyTest.class)
@Test
public void testRebalanceWithOfflineChildRegionTwoDiskStores() throws Throwable {
    SerializableRunnable createParentPR = new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            paf.setRecoveryDelay(0);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
        }
    };
    SerializableRunnable createChildPR = new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            DiskStore ds2 = cache.findDiskStore("disk2");
            if (ds2 == null) {
                ds2 = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk2");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            paf.setRecoveryDelay(0);
            paf.setColocatedWith(PR_REGION_NAME);
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk2");
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    rebalanceWithOfflineChildRegion(createParentPR, createChildPR);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

DiskStore (org.apache.geode.cache.DiskStore)190 Test (org.junit.Test)120 AttributesFactory (org.apache.geode.cache.AttributesFactory)91 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)91 File (java.io.File)79 Region (org.apache.geode.cache.Region)71 Cache (org.apache.geode.cache.Cache)61 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)46 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)39 LocalRegion (org.apache.geode.internal.cache.LocalRegion)32 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 VM (org.apache.geode.test.dunit.VM)28 DiskRegion (org.apache.geode.internal.cache.DiskRegion)24 Host (org.apache.geode.test.dunit.Host)23 Expectations (org.jmock.Expectations)23 InternalCache (org.apache.geode.internal.cache.InternalCache)21 UnitTest (org.apache.geode.test.junit.categories.UnitTest)21 IOException (java.io.IOException)20