Search in sources :

Example 96 with AsyncInvocation

use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testNestedPRRegions.

@Test
public void testNestedPRRegions() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    int numBuckets = 50;
    createNestedPR(vm0);
    createNestedPR(vm1);
    createNestedPR(vm2);
    createData(vm0, 0, numBuckets, "a", "parent1/" + PR_REGION_NAME);
    createData(vm0, 0, numBuckets, "b", "parent2/" + PR_REGION_NAME);
    checkData(vm2, 0, numBuckets, "a", "parent1/" + PR_REGION_NAME);
    checkData(vm2, 0, numBuckets, "b", "parent2/" + PR_REGION_NAME);
    Set<Integer> vm1_0Buckets = getBucketList(vm0, "parent1/" + PR_REGION_NAME);
    Set<Integer> vm1_1Buckets = getBucketList(vm1, "parent1/" + PR_REGION_NAME);
    Set<Integer> vm1_2Buckets = getBucketList(vm2, "parent1/" + PR_REGION_NAME);
    Set<Integer> vm2_0Buckets = getBucketList(vm0, "parent2/" + PR_REGION_NAME);
    Set<Integer> vm2_1Buckets = getBucketList(vm1, "parent2/" + PR_REGION_NAME);
    Set<Integer> vm2_2Buckets = getBucketList(vm2, "parent2/" + PR_REGION_NAME);
    closeCache(vm0);
    closeCache(vm1);
    closeCache(vm2);
    AsyncInvocation async0 = createNestedPRAsync(vm0);
    // [dsmith] Make sure that vm0 is waiting for vm1 and vm2 to recover
    // If VM(0) recovers early, that is a problem, because vm1
    // has newer data
    Thread.sleep(50);
    assertTrue(async0.isAlive());
    AsyncInvocation async1 = createNestedPRAsync(vm1);
    AsyncInvocation async2 = createNestedPRAsync(vm2);
    async0.getResult();
    async1.getResult();
    async2.getResult();
    assertEquals(vm1_0Buckets, getBucketList(vm0, "parent1/" + PR_REGION_NAME));
    assertEquals(vm1_1Buckets, getBucketList(vm1, "parent1/" + PR_REGION_NAME));
    assertEquals(vm1_2Buckets, getBucketList(vm2, "parent1/" + PR_REGION_NAME));
    assertEquals(vm2_0Buckets, getBucketList(vm0, "parent2/" + PR_REGION_NAME));
    assertEquals(vm2_1Buckets, getBucketList(vm1, "parent2/" + PR_REGION_NAME));
    assertEquals(vm2_2Buckets, getBucketList(vm2, "parent2/" + PR_REGION_NAME));
    checkData(vm0, 0, numBuckets, "a", "parent1/" + PR_REGION_NAME);
    checkData(vm0, 0, numBuckets, "b", "parent2/" + PR_REGION_NAME);
    createData(vm1, numBuckets, 113, "c", "parent1/" + PR_REGION_NAME);
    createData(vm1, numBuckets, 113, "d", "parent2/" + PR_REGION_NAME);
    checkData(vm2, numBuckets, 113, "c", "parent1/" + PR_REGION_NAME);
    checkData(vm2, numBuckets, 113, "d", "parent2/" + PR_REGION_NAME);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 97 with AsyncInvocation

use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testAllowRegionUseBeforeRedundancyRecovery.

/**
   * A test to make sure that we allow the PR to be used after at least one copy of every bucket is
   * recovered, but before the secondaries are initialized.
   * 
   * @throws Throwable
   */
@Test
public void testAllowRegionUseBeforeRedundancyRecovery() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int redundancy = 1;
    int numBuckets = 20;
    createPR(vm0, redundancy);
    createPR(vm1, redundancy);
    createPR(vm2, redundancy);
    createData(vm0, 0, numBuckets, "a");
    Set<Integer> vm0Buckets = getBucketList(vm0);
    Set<Integer> vm1Buckets = getBucketList(vm1);
    Set<Integer> vm2Buckets = getBucketList(vm2);
    closeCache(vm0);
    closeCache(vm1);
    closeCache(vm2);
    SerializableRunnable slowGII = new SerializableRunnable("Slow down GII") {

        @SuppressWarnings("synthetic-access")
        public void run() {
            InternalResourceManager.setResourceObserver(new RecoveryObserver());
            DistributionMessageObserver.setInstance(new BlockGIIMessageObserver());
        }
    };
    SerializableRunnable resetSlowGII = new SerializableRunnable("Unset the slow GII") {

        public void run() {
            BlockGIIMessageObserver messageObserver = (BlockGIIMessageObserver) DistributionMessageObserver.setInstance(null);
            RecoveryObserver recoveryObserver = (RecoveryObserver) InternalResourceManager.getResourceObserver();
            messageObserver.cdl.countDown();
            try {
                recoveryObserver.recoveryDone.await();
            } catch (InterruptedException e) {
                Assert.fail("Interrupted", e);
            }
            InternalResourceManager.setResourceObserver(null);
        }
    };
    try {
        vm0.invoke(slowGII);
        vm1.invoke(slowGII);
        vm2.invoke(slowGII);
        SerializableRunnable createPR = new SerializableRunnable("create PR") {

            public void run() {
                Cache cache = getCache();
                RegionAttributes attr = getPersistentPRAttributes(redundancy, -1, cache, 113, true);
                cache.createRegion(PR_REGION_NAME, attr);
            }
        };
        AsyncInvocation a1 = vm0.invokeAsync(createPR);
        AsyncInvocation a2 = vm1.invokeAsync(createPR);
        AsyncInvocation a3 = vm2.invokeAsync(createPR);
        a1.getResult(MAX_WAIT);
        a2.getResult(MAX_WAIT);
        a3.getResult(MAX_WAIT);
        // Make sure all of the primary are available.
        checkData(vm0, 0, numBuckets, "a");
        createData(vm0, 113, 113 + numBuckets, "b");
        // But none of the secondaries
        Set<Integer> vm0InitialBuckets = getBucketList(vm0);
        Set<Integer> vm1InitialBuckets = getBucketList(vm1);
        Set<Integer> vm2InitialBuckets = getBucketList(vm2);
        assertEquals("vm0=" + vm0InitialBuckets + ",vm1=" + vm1InitialBuckets + "vm2=" + vm2InitialBuckets, numBuckets, vm0InitialBuckets.size() + vm1InitialBuckets.size() + vm2InitialBuckets.size());
    } finally {
        // Reset the slow GII flag, and wait for the redundant buckets
        // to be recovered.
        AsyncInvocation reset0 = vm0.invokeAsync(resetSlowGII);
        AsyncInvocation reset1 = vm1.invokeAsync(resetSlowGII);
        AsyncInvocation reset2 = vm2.invokeAsync(resetSlowGII);
        reset0.getResult(MAX_WAIT);
        reset1.getResult(MAX_WAIT);
        reset2.getResult(MAX_WAIT);
    }
    // Now we better have all of the buckets
    assertEquals(vm0Buckets, getBucketList(vm0));
    assertEquals(vm1Buckets, getBucketList(vm1));
    assertEquals(vm2Buckets, getBucketList(vm2));
    // Make sure the members see the data recovered from disk
    // in those secondary buckets
    checkData(vm0, 0, numBuckets, "a");
    checkData(vm1, 0, numBuckets, "a");
    // Make sure the members see the new updates
    // in those secondary buckets
    checkData(vm0, 113, 113 + numBuckets, "b");
    checkData(vm1, 113, 113 + numBuckets, "b");
}
Also used : 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) 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 98 with AsyncInvocation

use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testBug41340.

/**
   * This test this case we replace buckets where are offline on A by creating them on C We then
   * shutdown C and restart A, which recovers those buckets
   */
@Test
public void testBug41340() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    createPR(vm0, 1, 0);
    createPR(vm1, 1, 0);
    createData(vm0, 0, NUM_BUCKETS, "a");
    // This should do nothing because we have satisfied redundancy.
    createPR(vm2, 1, 0);
    assertEquals(Collections.emptySet(), getBucketList(vm2));
    Set<Integer> vm0Buckets = getBucketList(vm0);
    final Set<Integer> lostBuckets = getBucketList(vm1);
    closeCache(vm1);
    // VM2 should pick up the slack
    waitForBucketRecovery(vm2, lostBuckets);
    createData(vm0, 0, NUM_BUCKETS, "b");
    // VM1 should recover, but it shouldn't host the bucket anymore
    createPR(vm1, 1, 0);
    // The data shouldn't be affected.
    checkData(vm1, 0, NUM_BUCKETS, "b");
    closeCache(vm2);
    // The buckets should move back to vm1.
    waitForBucketRecovery(vm1, lostBuckets);
    assertEquals(vm0Buckets, getBucketList(vm0));
    assertEquals(vm0Buckets, getBucketList(vm1));
    // The data shouldn't be affected.
    checkData(vm1, 0, NUM_BUCKETS, "b");
    // restart everything, and make sure it comes back correctly.
    closeCache(vm0);
    closeCache(vm1);
    AsyncInvocation async1 = createPRAsync(vm1, 1);
    AsyncInvocation async0 = createPRAsync(vm0, 1);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // The data shouldn't be affected.
    checkData(vm1, 0, NUM_BUCKETS, "b");
    assertEquals(vm0Buckets, getBucketList(vm0));
    assertEquals(vm0Buckets, getBucketList(vm1));
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 99 with AsyncInvocation

use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCleanStop.

// GEODE-1582: race in async region creation causing GII when not
@Category(FlakyTest.class)
// expected
@Test
public void testCleanStop() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, 1);
    createPR(vm1, 1);
    createData(vm0, 0, 1, "a");
    fakeCleanShutdown(vm1, 0);
    fakeCleanShutdown(vm0, 0);
    AsyncInvocation async1 = createPRAsync(vm0, 1);
    // [dsmith] Make sure that vm0 is waiting for vm1 to recover
    // If VM(0) recovers early, that is a problem, because
    // we can now longer do a clean restart
    AsyncInvocation async2 = createPRAsync(vm1, 1);
    async1.getResult(MAX_WAIT);
    async2.getResult(MAX_WAIT);
    checkData(vm0, 0, 1, "a");
    checkData(vm1, 0, 1, "a");
    checkRecoveredFromDisk(vm0, 0, true);
    checkRecoveredFromDisk(vm1, 0, true);
    closePR(vm0);
    closePR(vm1);
    async1 = createPRAsync(vm0, 1);
    async2 = createPRAsync(vm1, 1);
    async1.getResult(MAX_WAIT);
    async2.getResult(MAX_WAIT);
    checkData(vm0, 0, 1, "a");
    checkData(vm1, 0, 1, "a");
    checkRecoveredFromDisk(vm0, 0, false);
    checkRecoveredFromDisk(vm1, 0, true);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) 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 100 with AsyncInvocation

use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testRevokeAfterStartup.

@Test
public void testRevokeAfterStartup() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    int numBuckets = 50;
    createPR(vm0, 1);
    createPR(vm1, 1);
    createData(vm0, 0, numBuckets, "a");
    Set<Integer> vm0Buckets = getBucketList(vm0);
    Set<Integer> vm1Buckets = getBucketList(vm1);
    assertEquals(vm0Buckets, vm1Buckets);
    closeCache(vm0);
    createData(vm1, 0, numBuckets, "b");
    closeCache(vm1);
    AsyncInvocation a1 = createPRAsync(vm0, 1);
    // [dsmith] Make sure that vm0 is waiting for vm1 to recover
    // If VM(0) recovers early, that is a problem, because vm1
    // has newer data
    Thread.sleep(500);
    assertTrue(a1.isAlive());
    revokeKnownMissingMembers(vm2, 1);
    a1.getResult(MAX_WAIT);
    assertEquals(vm0Buckets, getBucketList(vm0));
    checkData(vm0, 0, numBuckets, "a");
    createData(vm0, numBuckets, 113, "b");
    checkData(vm0, numBuckets, 113, "b");
    IgnoredException ex = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getName(), vm1);
    try {
        createPR(vm1, 1);
        fail("Should have recieved a SplitDistributedSystemException");
    } catch (RMIException e) {
        // We revoked this member.
        if (!(e.getCause() instanceof RevokedPersistentDataException)) {
            throw e;
        }
    }
    ex.remove();
}
Also used : RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RMIException(org.apache.geode.test.dunit.RMIException) VM(org.apache.geode.test.dunit.VM) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)314 Test (org.junit.Test)280 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)275 VM (org.apache.geode.test.dunit.VM)186 Host (org.apache.geode.test.dunit.Host)175 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)139 Region (org.apache.geode.cache.Region)87 CacheException (org.apache.geode.cache.CacheException)65 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)65 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)61 Cache (org.apache.geode.cache.Cache)44 AttributesFactory (org.apache.geode.cache.AttributesFactory)41 IgnoredException (org.apache.geode.test.dunit.IgnoredException)35 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)28 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)26 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)25 Ignore (org.junit.Ignore)25 Category (org.junit.experimental.categories.Category)25