Search in sources :

Example 16 with RMIException

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

the class PersistentPartitionedRegionDUnitTest method testBug42226.

/**
   * Test for bug 4226. 1. Member A has the bucket 2. Member B starts creating the bucket. It tells
   * member A that it hosts the bucket 3. Member A crashes 4. Member B destroys the bucket and
   * throws a partition offline exception, because it wasn't able to complete initialization. 5.
   * Member A recovers, and gets stuck waiting for member B.
   * 
   * @throws Throwable
   */
// GEODE-1208: time sensitive, multiple non-thread-safe test hooks,
@Category(FlakyTest.class)
// async actions
@Test
public void testBug42226() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect from the distributed
    // system when the initial image message shows up.
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        // Don't disconnect until we see a bucket
                        if (rim.regionPath.contains("_B_")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPR(vm0, 1, 0, 1);
    // Make sure we create a bucket
    createData(vm0, 0, 1, "a");
    // This should recover redundancy, which should cause vm0 to disconnect
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException");
    try {
        LogWriterUtils.getLogWriter().info("Creating region in VM1");
        createPR(vm1, 1, 0, 1);
        // Make sure get a partition offline exception
        try {
            createData(vm1, 0, 1, "a");
        } catch (RMIException e) {
            // We expect a PartitionOfflineException
            if (!(e.getCause() instanceof PartitionOfflineException)) {
                throw e;
            }
        }
    } finally {
        ex.remove();
    }
    // Make sure vm0 is really disconnected (avoids a race with the observer).
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            disconnectFromDS();
        }
    });
    // This should recreate the bucket
    AsyncInvocation async1 = createPRAsync(vm0, 1, 0, 1);
    async1.getResult(MAX_WAIT);
    checkData(vm1, 0, 1, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) 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 17 with RMIException

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

the class PersistentPartitionedRegionDUnitTest method testRevokedMemberRedundancy1.

/**
   * Test to make sure that we recreate a bucket if a member is revoked
   * 
   * @throws Throwable
   */
@Test
public void testRevokedMemberRedundancy1() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPR(vm0, 1);
    createPR(vm1, 1);
    createData(vm0, 0, NUM_BUCKETS, "a");
    Set<Integer> vm0Buckets = getBucketList(vm0);
    Set<Integer> vm1Buckets = getBucketList(vm1);
    assertEquals(vm0Buckets, vm1Buckets);
    closeCache(vm1);
    // This should work, because this bucket is still available.
    checkData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "b");
    revokeKnownMissingMembers(vm2, 1);
    // This should make a copy of all of the buckets,
    // because we have revoked VM1.
    createPR(vm2, 1);
    Set<Integer> vm2Buckets = getBucketList(vm2);
    assertEquals(vm1Buckets, vm2Buckets);
    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;
        }
    }
    // Test that we can bounce vm0 and vm1, and still get a RevokedPersistentDataException
    // when vm1 tries to recover
    closeCache(vm0);
    closeCache(vm2);
    AsyncInvocation async0 = createPRAsync(vm0, 1);
    AsyncInvocation async2 = createPRAsync(vm2, 1);
    async0.getResult();
    async2.getResult();
    try {
        createPR(vm1, 1);
        fail("Should have recieved a RevokedPersistentDataException");
    } catch (RMIException e) {
        // We revoked this member.
        if (!(e.getCause() instanceof RevokedPersistentDataException)) {
            throw e;
        }
    }
    ex.remove();
    // The data shouldn't be affected.
    checkData(vm2, 0, NUM_BUCKETS, "b");
}
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)

Example 18 with RMIException

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

the class Bug41733DUnitTest method testCrashAfterBucketCreation.

/**
   * Test the we can handle a member departing after creating a bucket on the remote node but before
   * we choose a primary
   */
@Test
public void testCrashAfterBucketCreation() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new SerializableRunnable("Install observer") {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof ManageBucketReplyMessage) {
                        disconnectFromDS();
                    }
                }
            });
        }
    });
    createPR(vm0, 0);
    // Create a couple of buckets in VM0. This will make sure
    // the next bucket we create will be created in VM 1.
    putData(vm0, 0, 2, "a");
    createPR(vm1, 0);
    // Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
    try {
        putData(vm0, 3, 4, "a");
        fail("should have received a cache closed exception");
    } catch (RMIException e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    assertEquals(Collections.singleton(3), getBucketList(vm1));
    // This shouldn't hang, because the bucket creation should finish,.
    putData(vm1, 3, 4, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ManageBucketReplyMessage(org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 19 with RMIException

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

the class RegionCreateDestroyDUnitTest method testCreateDestroyReservedRegion.

// GEODE-1878
@Category(FlakyTest.class)
@Test
public void testCreateDestroyReservedRegion() throws InterruptedException {
    Cache serverCache = getCache();
    try {
        serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(RESERVED_REGION_NAME);
        fail("Should have thrown an IllegalArgumentException");
    } catch (IllegalArgumentException arg) {
        assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", arg.getMessage());
    }
    try {
        startServer(serverCache);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    try {
        client1.invoke(() -> {
            ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
            try {
                cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(RESERVED_REGION_NAME);
                fail("Should have thrown an IllegalArgumentException");
            } catch (IllegalArgumentException e) {
                assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", e.getMessage());
            }
        });
    } catch (RMIException rmi) {
        rmi.getCause();
    }
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) IOException(java.io.IOException) ClientCache(org.apache.geode.cache.client.ClientCache) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Category(org.junit.experimental.categories.Category) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 20 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)

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