FederatingManager extends Manager { @VisibleForTesting void removeMemberArtifacts(DistributedMember member, boolean crashed) { Region<String, Object> monitoringRegion = repo.getEntryFromMonitoringRegionMap(member); Region<NotificationKey, Notification> notificationRegion = repo.getEntryFromNotifRegionMap(member); if (monitoringRegion == null && notificationRegion == null) { return; } repo.romoveEntryFromMonitoringRegionMap(member); repo.removeEntryFromNotifRegionMap(member); if (!cache.isClosed()) { try { if (monitoringRegion != null) { proxyFactory.removeAllProxies(member, monitoringRegion); monitoringRegion.localDestroyRegion(); } } catch (CancelException | RegionDestroyedException ignore) { } try { if (notificationRegion != null) { notificationRegion.localDestroyRegion(); } } catch (CancelException | RegionDestroyedException ignore) { } } if (!system.getDistributedMember().equals(member)) { try { service.memberDeparted((InternalDistributedMember) member, crashed); } catch (CancelException | RegionDestroyedException ignore) { } } } @VisibleForTesting  FederatingManager(ManagementResourceRepo repo, InternalDistributedSystem system,
      SystemManagementService service, InternalCache cache, StatisticsFactory statisticsFactory,
      StatisticsClock statisticsClock, MBeanProxyFactory proxyFactory, MemberMessenger messenger,
      ExecutorService executorService);   FederatingManager(ManagementResourceRepo repo, InternalDistributedSystem system,
      SystemManagementService service, InternalCache cache, StatisticsFactory statisticsFactory,
      StatisticsClock statisticsClock, MBeanProxyFactory proxyFactory, MemberMessenger messenger,
      Supplier<ExecutorService> executorServiceSupplier); @Override synchronized void startManager(); @Override synchronized void stopManager(); @Override boolean isRunning(); MemberMessenger getMessenger(); @VisibleForTesting MBeanProxyFactory getProxyFactory();  }
@Test public void removeMemberArtifactsLocallyDestroysMonitoringRegion() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(monitoringRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsLocallyDestroysNotificationRegion() { InternalDistributedMember member = member(); Region notificationRegion = mock(Region.class); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(notificationRegion); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(notificationRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsDoesNotThrowIfMonitoringRegionIsAlreadyDestroyed() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); doThrow(new RegionDestroyedException("test", "monitoringRegion")) .when(monitoringRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(monitoringRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsDoesNotThrowIfNotificationRegionIsAlreadyDestroyed() { InternalDistributedMember member = member(); Region notificationRegion = mock(Region.class); doThrow(new RegionDestroyedException("test", "notificationRegion")) .when(notificationRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(notificationRegion); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(notificationRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsDoesNotThrowIfMBeanProxyFactoryThrowsRegionDestroyedException() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); MBeanProxyFactory proxyFactory = mock(MBeanProxyFactory.class); doThrow(new RegionDestroyedException("test", "monitoringRegion")) .when(proxyFactory).removeAllProxies(member, monitoringRegion); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(proxyFactory) .removeAllProxies(member, monitoringRegion); }
@Test public void removeMemberArtifactsProxyFactoryDoesNotThrowIfCacheClosed() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); MBeanProxyFactory proxyFactory = mock(MBeanProxyFactory.class); doThrow(new CacheClosedException("test")) .when(proxyFactory).removeAllProxies(member, monitoringRegion); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(proxyFactory) .removeAllProxies(member, monitoringRegion); }
@Test public void removeMemberArtifactsNotificationRegionDoesNotThrowIfCacheClosed() { InternalDistributedMember member = member(); Region notificationRegion = mock(Region.class); doThrow(new CacheClosedException("test")) .when(notificationRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(notificationRegion); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(notificationRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsMonitoringRegionDoesNotThrowIfCacheClosed() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); doThrow(new CacheClosedException("test")) .when(monitoringRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(monitoringRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsProxyFactoryDoesNotThrowIfSystemDisconnected() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); MBeanProxyFactory proxyFactory = mock(MBeanProxyFactory.class); doThrow(new DistributedSystemDisconnectedException("test")) .when(proxyFactory).removeAllProxies(member, monitoringRegion); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(proxyFactory) .removeAllProxies(member, monitoringRegion); }
@Test public void removeMemberArtifactsNotificationRegionDoesNotThrowIfSystemDisconnected() { InternalDistributedMember member = member(); Region notificationRegion = mock(Region.class); doThrow(new DistributedSystemDisconnectedException("test")) .when(notificationRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(notificationRegion); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(notificationRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsMonitoringRegionDoesNotThrowIfSystemDisconnected() { InternalDistributedMember member = member(); Region monitoringRegion = mock(Region.class); doThrow(new DistributedSystemDisconnectedException("test")) .when(monitoringRegion).localDestroyRegion(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(monitoringRegion); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verify(monitoringRegion) .localDestroyRegion(); }
@Test public void removeMemberArtifactsDoesNotThrowIfNotificationRegionIsNull() { InternalDistributedMember member = member(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(null); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); Throwable thrown = catchThrowable(() -> federatingManager.removeMemberArtifacts(member, false)); assertThat(thrown) .isNull(); }
@Test public void removeMemberArtifactsDoesNotThrowIfMonitoringRegionIsNull() { InternalDistributedMember member = member(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(null); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); Throwable thrown = catchThrowable(() -> federatingManager.removeMemberArtifacts(member, false)); assertThat(thrown) .isNull(); }
@Test public void removeMemberArtifactsDoesNotRemoveAllProxiesIfMonitoringRegionIsNull() { InternalDistributedMember member = member(); when(repo.getEntryFromMonitoringRegionMap(eq(member))) .thenReturn(null); when(repo.getEntryFromNotifRegionMap(eq(member))) .thenReturn(mock(Region.class)); when(system.getDistributedMember()) .thenReturn(member); FederatingManager federatingManager = new FederatingManager(repo, system, service, cache, statisticsFactory, statisticsClock, proxyFactory, messenger, executorService); federatingManager.removeMemberArtifacts(member, false); verifyNoMoreInteractions(proxyFactory); }