Search in sources :

Example 21 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class JGroupsMessengerJUnitTest method testJChannelError.

@Test
public void testJChannelError() throws Exception {
    for (int i = 0; i < 2; i++) {
        boolean enableMcast = (i == 1);
        initMocks(enableMcast);
        JChannel mockChannel = mock(JChannel.class);
        when(mockChannel.isConnected()).thenReturn(true);
        doThrow(new RuntimeException()).when(mockChannel).send(any(Message.class));
        JChannel realChannel = messenger.myChannel;
        messenger.myChannel = mockChannel;
        try {
            InternalDistributedMember mbr = createAddress(8888);
            DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
            when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
            when(msg.getMulticast()).thenReturn(enableMcast);
            when(msg.getProcessorId()).thenReturn(1234);
            when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
            try {
                messenger.send(msg);
                fail("expected a failure");
            } catch (DistributedSystemDisconnectedException e) {
            // success
            }
            verify(mockChannel).send(isA(Message.class));
        } finally {
            messenger.myChannel = realChannel;
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 22 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class DiskStoreCommandsDUnitTest method testMissingDiskStore.

// GEODE-2102
@Category(FlakyTest.class)
@Test
public void testMissingDiskStore() {
    final String regionName = "testShowMissingDiskStoreRegion";
    setUpJmxManagerOnVm0ThenConnect(null);
    final VM vm0 = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    final String diskStoreName = "DiskStoreCommandsDUnitTest";
    // Default setup creates a cache in the Manager, now create a cache in VM1
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            getSystem(localProps);
            Cache cache = getCache();
        }
    });
    // Create a disk store and region in the Manager (VM0) and VM1 VMs
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                Cache cache = getCache();
                File diskStoreDirFile = new File(diskStoreName + vm.getPid());
                diskStoreDirFile.mkdirs();
                DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
                diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
                diskStoreFactory.setMaxOplogSize(1);
                diskStoreFactory.setAllowForceCompaction(true);
                diskStoreFactory.setAutoCompact(false);
                diskStoreFactory.create(regionName);
                RegionFactory regionFactory = cache.createRegionFactory();
                regionFactory.setDiskStoreName(regionName);
                regionFactory.setDiskSynchronous(true);
                regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
                regionFactory.setScope(Scope.DISTRIBUTED_ACK);
                regionFactory.create(regionName);
            }
        });
    }
    // Add data to the region
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.put("A", "B");
        }
    });
    // Make sure that everything thus far is okay and there are no missing disk stores
    CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("No missing disk store found"));
    // Close the region in the Manager (VM0) VM
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.close();
        }
    });
    // Add data to VM1 and then close the region
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.put("A", "C");
            region.close();
        }
    });
    // Add the region back to the Manager (VM0) VM
    vm0.invokeAsync(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            RegionFactory regionFactory = cache.createRegionFactory();
            regionFactory.setDiskStoreName(regionName);
            regionFactory.setDiskSynchronous(true);
            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            regionFactory.setScope(Scope.DISTRIBUTED_ACK);
            try {
                regionFactory.create(regionName);
            } catch (DistributedSystemDisconnectedException ignore) {
            // okay to ignore
            }
        }
    });
    // Wait for the region in the Manager (VM0) to come online
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            WaitCriterion waitCriterion = new WaitCriterion() {

                public boolean done() {
                    Cache cache = getCache();
                    PersistentMemberManager memberManager = ((InternalCache) cache).getPersistentMemberManager();
                    return !memberManager.getWaitingRegions().isEmpty();
                }

                public String description() {
                    return "Waiting for another persistent member to come online";
                }
            };
            waitForCriterion(waitCriterion, 70000, 100, true);
        }
    });
    // Validate that there is a missing disk store on VM1
    cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String stringResult = commandResultToString(cmdResult);
    System.out.println("command result=" + stringResult);
    assertEquals(5, countLinesInString(stringResult, false));
    assertTrue(stringContainsLine(stringResult, "Disk Store ID.*Host.*Directory"));
    assertTrue(stringContainsLine(stringResult, ".*" + diskStoreName + vm1.getPid()));
    // Extract the id from the returned missing disk store
    String line = getLineFromString(stringResult, 4);
    assertFalse(line.contains("---------"));
    StringTokenizer resultTokenizer = new StringTokenizer(line);
    String id = resultTokenizer.nextToken();
    // Remove the missing disk store and validate the result
    cmdResult = executeCommand("revoke missing-disk-store --id=" + id);
    assertNotNull(cmdResult);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("Missing disk store successfully revoked"));
    // Do our own cleanup so that the disk store directories can be removed
    super.destroyDefaultSetup();
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                try {
                    FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
                } catch (IOException iex) {
                // There's nothing else we can do
                }
            }
        });
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) Properties(java.util.Properties) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) StringTokenizer(java.util.StringTokenizer) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) 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 23 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class ReplyProcessor21 method getDistributionManager.

///////////////////// Instance Methods /////////////////////
/**
   * get the distribution manager for this processor. If the distributed system has a distribution
   * manager, it is used. Otherwise, we expect a distribution manager has been set with
   * setDistributionManager and we'll use that
   */
protected DM getDistributionManager() {
    try {
        DM result = this.system.getDistributionManager();
        if (result == null) {
            result = this.dmgr;
            Assert.assertTrue(result != null, "null DistributionManager");
        }
        return result;
    } catch (IllegalStateException ex) {
        // fix for bug 35000
        this.system.getCancelCriterion().checkCancelInProgress(null);
        throw new DistributedSystemDisconnectedException(ex.getMessage());
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 24 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class ReplyProcessor21 method stillWaiting.

/**
   * We're still waiting if there is any member still left in the set and an exception hasn't been
   * returned from anyone yet.
   *
   * @return true if we are still waiting for a response
   */
protected boolean stillWaiting() {
    if (shutdown) {
        // Create the exception here, so that the call stack reflects the
        // failed computation. If you set the exception in onShutdown,
        // the resulting stack is not of interest.
        ReplyException re = new ReplyException(new DistributedSystemDisconnectedException(LocalizedStrings.ReplyProcessor21_ABORTED_DUE_TO_SHUTDOWN.toLocalizedString()));
        this.exception = re;
        return false;
    }
    // Optional override by subclass
    if (canStopWaiting()) {
        return false;
    }
    // If an error has occurred, we're done.
    if (stopBecauseOfExceptions()) {
        return false;
    }
    // All else is good, keep waiting if we have members to wait on.
    return numMembers() > 0;
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 25 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class BucketAdvisor method getPrimaryLock.

/**
   * Lazily gets the lock for acquiring primary lock. Caller must handle null. If DLS, Cache, or
   * DistributedSystem are shutting down then null will be returned. If DLS does not yet exist and
   * createDLS is false then null will be returned.
   * 
   * @param createDLS true will create DLS if it does not exist
   * @return distributed lock indicating primary member or null
   */
DistributedMemberLock getPrimaryLock(boolean createDLS) {
    synchronized (this) {
        if (this.primaryLock == null) {
            DistributedLockService dls = DistributedLockService.getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
            if (dls == null) {
                if (!createDLS || getProxyBucketRegion().getCache().isClosed()) {
                    // cache closure has destroyed the DLS
                    return null;
                }
                try {
                    // TODO: call GemFireCache#getPartitionedRegionLockService
                    dls = DLockService.create(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME, getAdvisee().getSystem(), true, /* distributed */
                    true, /* destroyOnDisconnect */
                    true);
                } catch (IllegalArgumentException e) {
                    // indicates that the DLS is already created
                    dls = DistributedLockService.getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
                    if (dls == null) {
                        // ok, caller will loop if necessary
                        return null;
                    }
                }// perhaps: DistributedSystemUnavailableException
                 catch (IllegalStateException e) {
                    // create still throws IllegalStateException if isDisconnecting is true
                    return null;
                } catch (DistributedSystemDisconnectedException e) {
                    // this would certainly prevent us from creating a DLS... messy
                    return null;
                }
            }
            this.primaryLock = new DistributedMemberLock(dls, getAdvisee().getName(), DistributedMemberLock.NON_EXPIRING_LEASE, DistributedMemberLock.LockReentryPolicy.PREVENT_SILENTLY);
        }
        return this.primaryLock;
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributedLockService(org.apache.geode.distributed.DistributedLockService) DistributedMemberLock(org.apache.geode.distributed.internal.locks.DistributedMemberLock)

Aggregations

DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)42 IOException (java.io.IOException)15 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 Test (org.junit.Test)9 CancelException (org.apache.geode.CancelException)7 ReplyException (org.apache.geode.distributed.internal.ReplyException)7 Iterator (java.util.Iterator)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Cache (org.apache.geode.cache.Cache)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 InternalCache (org.apache.geode.internal.cache.InternalCache)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)4 InterruptedIOException (java.io.InterruptedIOException)3