Search in sources :

Example 61 with AsyncInvocation

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

the class PartitionedRegionHAFailureAndRecoveryDUnitTest method createPartitionRegionAsynch.

/**
   * This function creates multiple partition regions on specified nodes.
   */
private void createPartitionRegionAsynch(final String regionPrefix, final int startIndexForRegion, final int endIndexForRegion, final int localMaxMemory, final int redundancy, final int recoveryDelay) throws Exception {
    final AsyncInvocation[] async = new AsyncInvocation[vmArr.length];
    for (int count = 0; count < vmArr.length; count++) {
        VM vm = vmArr[count];
        async[count] = vm.invokeAsync(getCreateMultiplePRregion(regionPrefix, endIndexForRegion, redundancy, localMaxMemory, recoveryDelay));
    }
    for (int count2 = 0; count2 < async.length; count2++) {
        ThreadUtils.join(async[count2], 30 * 1000);
    }
    for (int count2 = 0; count2 < async.length; count2++) {
        if (async[count2].exceptionOccurred()) {
            Assert.fail("exception during " + count2, async[count2].getException());
        }
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation)

Example 62 with AsyncInvocation

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

the class RemoveGlobalDUnitTest method testRemoveGlobalSingleVM.

// test methods
@Test
public void testRemoveGlobalSingleVM() throws Throwable {
    SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with cache writer") {

        public void run2() throws CacheException {
            cache.setLockTimeout(5);
            CacheWriter cacheWriter = new CacheWriterCallBack();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            factory.setCacheWriter(cacheWriter);
            region = cache.createRegion("map", factory.create());
        }
    };
    vm0.invoke(createRegionWithWriter);
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("put object") {

        public void run2() throws CacheException {
            for (int i = 1; i < 5; i++) {
                region.put(new Integer(i), java.lang.Integer.toString(i));
            }
            region.remove(new Integer(2));
        }
    });
    vm0.invoke(new CacheSerializableRunnable("verify locking") {

        public void run2() throws CacheException {
            synchronized (RemoveGlobalDUnitTest.class) {
                if (!lockedForRemove) {
                    try {
                        RemoveGlobalDUnitTest.class.wait();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            try {
                // getLogWriter().fine("000000000000000");
                region.put(new Integer(2), "newEntry");
                fail("Should have thrown TimeoutException");
            } catch (TimeoutException tme) {
            // pass
            }
        }
    });
    ThreadUtils.join(async, 30 * 1000);
    if (async.exceptionOccurred())
        throw async.getException();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) CacheWriter(org.apache.geode.cache.CacheWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) TimeoutException(org.apache.geode.cache.TimeoutException) CacheException(org.apache.geode.cache.CacheException) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 63 with AsyncInvocation

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

the class Bug51400DUnitTest method testDeadlock.

@Ignore("ticket51932")
@Test
public void testDeadlock() throws Throwable {
    int maxQSize = 5;
    // Set infinite ack interval so that the queue will not be drained.
    int ackInterval = Integer.MAX_VALUE;
    fail("Invoking bad method");
    int port1 = 0;
    // int port1 = (Integer) server0.invoke(() -> Bug51400DUnitTest.createServerCache( maxQSize));
    client1.invoke(Bug51400DUnitTest.class, "createClientCache", new Object[] { NetworkUtils.getServerHostName(Host.getHost(0)), new Integer[] { port1 }, ackInterval });
    // Do puts from server as well as from client on the same key.
    AsyncInvocation ai1 = server0.invokeAsync(() -> Bug51400DUnitTest.updateKey(2 * maxQSize));
    AsyncInvocation ai2 = client1.invokeAsync(() -> Bug51400DUnitTest.updateKey(2 * maxQSize));
    ai1.getResult();
    ai2.getResult();
    // Verify that the queue has crossed its limit of maxQSize
    server0.invoke(() -> Bug51400DUnitTest.verifyQueueSize(true, 2 * maxQSize));
}
Also used : AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 64 with AsyncInvocation

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

the class ShutdownAllDUnitTest method testCleanStop.

// shutdownAll, then restart to verify
@Test
public void testCleanStop() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createRegion(vm0, "region", "disk", true, 1);
    createRegion(vm1, "region", "disk", true, 1);
    createData(vm0, 0, 1, "a", "region");
    shutDownAllMembers(vm2, 2);
    AsyncInvocation a0 = createRegionAsync(vm0, "region", "disk", true, 1);
    // [dsmith] Make sure that vm0 is waiting for vm1 to recover
    // If VM(0) recovers early, that is a problem, because we
    // are no longer doing a clean recovery.
    Thread.sleep(500);
    assertTrue(a0.isAlive());
    AsyncInvocation a1 = createRegionAsync(vm1, "region", "disk", true, 1);
    a0.getResult(MAX_WAIT);
    a1.getResult(MAX_WAIT);
    checkData(vm0, 0, 1, "a", "region");
    checkData(vm1, 0, 1, "a", "region");
    checkPRRecoveredFromDisk(vm0, "region", 0, true);
    checkPRRecoveredFromDisk(vm1, "region", 0, true);
    closeRegion(vm0, "region");
    closeRegion(vm1, "region");
    a0 = createRegionAsync(vm0, "region", "disk", true, 1);
    a1 = createRegionAsync(vm1, "region", "disk", true, 1);
    a0.getResult(MAX_WAIT);
    a1.getResult(MAX_WAIT);
    checkData(vm0, 0, 1, "a", "region");
    checkData(vm1, 0, 1, "a", "region");
    checkPRRecoveredFromDisk(vm0, "region", 0, false);
    checkPRRecoveredFromDisk(vm1, "region", 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 65 with AsyncInvocation

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

the class ShutdownAllDUnitTest method testShutdownAllFromServer.

@Test
public void testShutdownAllFromServer() 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;
    createRegion(vm0, "region", "disk", true, 1);
    createRegion(vm1, "region", "disk", true, 1);
    createRegion(vm2, "region", "disk", true, 1);
    createData(vm0, 0, numBuckets, "a", "region");
    shutDownAllMembers(vm2, 3);
    assertTrue(InternalDistributedSystem.getExistingSystems().isEmpty());
    // restart vm0, vm1, vm2
    AsyncInvocation a0 = createRegionAsync(vm0, "region", "disk", true, 1);
    AsyncInvocation a1 = createRegionAsync(vm1, "region", "disk", true, 1);
    AsyncInvocation a2 = createRegionAsync(vm2, "region", "disk", true, 1);
    a0.getResult(MAX_WAIT);
    a1.getResult(MAX_WAIT);
    a2.getResult(MAX_WAIT);
    createData(vm0, 0, numBuckets, "a", "region");
    createData(vm1, 0, numBuckets, "a", "region");
    createData(vm2, 0, numBuckets, "a", "region");
    createData(vm0, numBuckets, 113, "b", "region");
    checkData(vm0, numBuckets, 113, "b", "region");
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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