Search in sources :

Example 6 with RMIException

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

the class PartitionedRegionMetaDataCleanupDUnitTest method testCleanupOnCloseCache.

@Test
public void testCleanupOnCloseCache() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, "region1", 5);
    createPR(vm1, "region2", 10);
    // This should fail
    IgnoredException ex = IgnoredException.addIgnoredException("IllegalStateException", vm1);
    try {
        createPR(vm1, "region1", 10);
        fail("Should have received an exception");
    } catch (RMIException e) {
    // ok
    } finally {
        ex.remove();
    }
    closeCache(vm0);
    waitForCreate(vm0, "region1", 15);
}
Also used : 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with RMIException

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

the class PartitionedRegionMetaDataCleanupDUnitTest method testCleanupOnCloseRegion.

@Test
public void testCleanupOnCloseRegion() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, "region1", 5);
    createPR(vm1, "region2", 10);
    // This should fail
    IgnoredException ex = IgnoredException.addIgnoredException("IllegalStateException", vm1);
    try {
        createPR(vm1, "region1", 10);
        fail("Should have received an exception");
    } catch (RMIException e) {
    // ok
    } finally {
        ex.remove();
    }
    closePr(vm0, "region1");
    waitForCreate(vm0, "region1", 15);
}
Also used : 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with RMIException

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

the class RollingUpgrade2DUnitTest method testOldMemberCantJoinRolledLocators.

/**
   * Demonstrate that an old process can't join a system that has upgraded locators. This is for
   * bugs #50510 and #50742.
   */
@Test
public void testOldMemberCantJoinRolledLocators() throws Exception {
    VM oldServer = Host.getHost(0).getVM(oldVersion, 1);
    // uses the DUnit locator
    Properties props = getSystemProperties();
    try {
        oldServer.invoke(invokeCreateCache(props));
    } catch (RMIException e) {
        Throwable cause = e.getCause();
        if (cause != null && (cause instanceof AssertionError)) {
            cause = cause.getCause();
            if (cause != null && cause.getMessage() != null && !cause.getMessage().startsWith("Rejecting the attempt of a member using an older version of the product to join the distributed system")) {
                throw e;
            }
        }
    }
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) VM(org.apache.geode.test.dunit.VM) Properties(java.util.Properties) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) BackwardCompatibilityTest(org.apache.geode.test.junit.categories.BackwardCompatibilityTest) Test(org.junit.Test)

Example 9 with RMIException

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

the class DistributedLockServiceDUnitTest method testCreateDestroy.

@Test
public void testCreateDestroy() throws Exception {
    final String serviceName = getUniqueName();
    final String abc = "abc";
    // create and destroy dls
    assertNull(DistributedLockService.getServiceNamed(serviceName));
    DistributedLockService service = DistributedLockService.create(serviceName, getSystem());
    assertSame(service, DistributedLockService.getServiceNamed(serviceName));
    DistributedLockService.destroy(serviceName);
    // assert attempt to use dls throws LockServiceDestroyedException
    try {
        service.lock(abc, -1, -1);
        fail("didn't get LockServiceDestroyedException");
    } catch (LockServiceDestroyedException ex) {
    }
    // assert that destroyed dls is no longer available
    service = DistributedLockService.getServiceNamed(serviceName);
    assertNull("" + service, service);
    // recreate the dls
    service = DistributedLockService.create(serviceName, getSystem());
    assertTrue(!((DLockService) service).isDestroyed());
    ((DLockService) service).checkDestroyed();
    // get the same dls from another thread and hold a lock
    Thread thread = new Thread(new Runnable() {

        public void run() {
            DistributedLockService dls = DistributedLockService.getServiceNamed(serviceName);
            assertTrue(!((DLockService) dls).isDestroyed());
            ((DLockService) dls).checkDestroyed();
            // get lock on abc and hold it
            dls.lock(abc, -1, -1);
        }
    });
    thread.start();
    ThreadUtils.join(thread, 30 * 1000);
    // start a new thread to wait for lock on abc
    AsyncInvocation remoteWaitingThread = Host.getHost(0).getVM(0).invokeAsync(new SerializableRunnable() {

        public void run() {
            DistributedLockService dls = DistributedLockService.create(serviceName, getSystem());
            try {
                // waiting to get lock abc
                dls.lock(abc, -1, -1);
                fail("remoteWaitingThread got lock after dls destroyed");
            } catch (LockServiceDestroyedException expected) {
                return;
            }
            fail("remoteWaitingThread lock failed to throw LockServiceDestroyedException");
        }
    });
    // loop will handle race condition with 1 sec sleep and retry
    int retry = 10;
    for (int i = 0; i < retry; i++) {
        try {
            // destroy DLS and free up remoteWaitingThread
            Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

                public void run() {
                    DistributedLockService.destroy(serviceName);
                }
            });
        } catch (RMIException e) {
            // race condition: remoteWaitingThread probably hasn't created DLS yet
            if (i < retry && e.getCause() instanceof IllegalArgumentException) {
                sleep(1000);
                continue;
            } else {
                throw e;
            }
        }
        // completed so break out of loop
        break;
    }
    DistributedLockService.destroy(serviceName);
    // make sure remoteWaitingThread stopped waiting and threw LockServiceDestroyedException
    ThreadUtils.join(remoteWaitingThread, 10 * 1000);
    if (remoteWaitingThread.exceptionOccurred()) {
        Throwable e = remoteWaitingThread.getException();
        org.apache.geode.test.dunit.Assert.fail(e.getMessage(), e);
    }
    // make sure LockServiceDestroyedException is thrown
    try {
        service.lock(abc, -1, -1);
        fail("didn't get LockServiceDestroyedException");
    } catch (LockServiceDestroyedException ex) {
    }
    // make sure getServiceNamed returns null
    service = DistributedLockService.getServiceNamed(serviceName);
    assertNull("" + service, service);
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DLockService(org.apache.geode.distributed.internal.locks.DLockService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RemoteThread(org.apache.geode.distributed.internal.locks.RemoteThread) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Example 10 with RMIException

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

the class SystemFailureDUnitTest method doCreateEntry.

protected void doCreateEntry(String name) {
    LogWriter log = org.apache.geode.test.dunit.LogWriterUtils.getLogWriter();
    log.info("<ExpectedException action=add>" + "dunit.RMIException" + "</ExpectedException>");
    Object[] args = new Object[] { name };
    Host host = Host.getHost(0);
    VM vm = host.getVM(0);
    try {
        vm.invoke(this.getClass(), "createEntry", args);
    } catch (RMIException e) {
    // expected
    }
    log.info("<ExpectedException action=add>" + "dunit.RMIException" + "</ExpectedException>");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host)

Aggregations

RMIException (org.apache.geode.test.dunit.RMIException)23 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 Test (org.junit.Test)20 VM (org.apache.geode.test.dunit.VM)17 Host (org.apache.geode.test.dunit.Host)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)14 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)10 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 IOException (java.io.IOException)6 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)6 Cache (org.apache.geode.cache.Cache)5 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)5 RevokedPersistentDataException (org.apache.geode.cache.persistence.RevokedPersistentDataException)4 AttributesFactory (org.apache.geode.cache.AttributesFactory)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 DiskStore (org.apache.geode.cache.DiskStore)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 PartitionedRegionStorageException (org.apache.geode.cache.PartitionedRegionStorageException)3 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)3 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)3