private void throwIfClient() { if (isClient()) { throw new UnsupportedOperationException("operation is not supported on a client cache"); } }
when(config.getDeployWorkingDir()).thenReturn(new File(".")); when(cache.getDistributedSystem()).thenReturn(system); when(cache.getInternalDistributedSystem()).thenReturn(system); when(cache.getSystem()).thenReturn(system); when(cache.getMyId()).thenReturn(member); when(cache.getDistributionManager()).thenReturn(distributionManager); when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion); when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class)); when(cache.getSecurityService()).thenReturn(mock(SecurityService.class)); when(cache.createPdxInstanceFactory(any())).thenReturn(pdxInstanceFactory); when(cache.getPdxRegistry()).thenReturn(pdxRegistryMock); when(cache.getTxManager()).thenReturn(txManager); when(cache.getLogger()).thenReturn(logger); when(cache.getQueryMonitor()).thenReturn(queryMonitor);
private static final void closeCache() { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); if (cache != null && !cache.isClosed()) { destroyRegions(cache); cache.close(); } }
public void closeAnyPollutedCache() { if (GemFireCacheImpl.getInstance() != null) { GemFireCacheImpl.getInstance().close(); } }
/** * Called by notifier when a client goes away * * @since GemFire 5.7 */ @Override public void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client) { try { if (isClosed()) { return; } for (Object region : rootRegions(false, false)) { InternalRegion internalRegion = (InternalRegion) region; internalRegion.cleanupForClient(ccn, client); } } catch (DistributedSystemDisconnectedException ignore) { } }
this.configurationResponse = requestSharedConfiguration(); command.run(); }, EVENT_THREAD_LIMIT, this.cachePerfStats.getEventPoolHelper(), 1000, getThreadMonitorObj(), EVENT_QUEUE_LIMIT); } else { .createJmxManagerAdvisor(new JmxManagerAdvisee(getCacheForProcessingClientRequests())); getInternalResourceManager().addResourceListener(ResourceType.HEAP_MEMORY, getHeapEvictor()); if (null != getOffHeapStore()) { getInternalResourceManager().addResourceListener(ResourceType.OFFHEAP_MEMORY, getOffHeapEvictor()); this.recordedEventSweeper = createEventTrackerExpiryTask(); this.tombstoneService = TombstoneService.initialize(this); basicSetPdxSerializer(this.cacheConfig.getPdxSerializer()); TypeRegistry.open(); if (!isClient()) { addRegionEntrySynchronizationListener(new GatewaySenderQueueEntrySynchronizationListener()); backupService = new BackupService(this); if (!this.isClient) {
if (isClosed()) { return; if (isClosed()) { return; destroyGatewaySenderLockService(); this.stopServers(); stopMemcachedServer(); stopRedisServer(); int prSize = -this.partitionedRegions.size(); this.partitionedRegions.clear(); getCachePerfStats().incPartitionedRegions(prSize); prepareDiskStoresForClose(); if (this.forcedDisconnect) { op = Operation.FORCED_DISCONNECT; } else if (isReconnecting()) { op = Operation.CACHE_RECONNECT; } else { destroyPartitionedRegionLockService(); closeDiskStores();
URL url = getCacheXmlURL(); String cacheXmlDescription = this.cacheConfig.getCacheXMLDescription(); if (url == null && cacheXmlDescription == null) { if (isClient()) { initializeClientRegionShortcuts(this); } else { initializeRegionShortcuts(this); initializePdxRegistry(); readyDynamicRegionFactory(); return; // nothing needs to be done logCacheXML(url, cacheXmlDescription); if (cacheXmlDescription != null) { if (logger.isTraceEnabled()) { stream = url.openStream(); loadCacheXml(stream); closeQuietly(stream);
@Test public void userRegionShouldNotBeSetBeforeIndexInitialized() throws Exception { TestLuceneServiceImpl testService = new TestLuceneServiceImpl(); Field f = LuceneServiceImpl.class.getDeclaredField("cache"); f.setAccessible(true); f.set(testService, cache); AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class); when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory); DistributedSystem ds = mock(DistributedSystem.class); Statistics luceneIndexStats = mock(Statistics.class); when(cache.getDistributedSystem()).thenReturn(ds); when(((StatisticsFactory) ds).createAtomicStatistics(any(), anyString())) .thenReturn(luceneIndexStats); when(cache.getRegion(anyString())).thenReturn(region); when(cache.getDistributionManager()).thenReturn(mock(DistributionManager.class)); when(cache.getDistributionManager().getWaitingThreadPool()) .thenReturn(Executors.newSingleThreadExecutor()); RegionAttributes ratts = mock(RegionAttributes.class); when(region.getAttributes()).thenReturn(ratts); when(ratts.getDataPolicy()).thenReturn(DataPolicy.PARTITION); EvictionAttributes evictionAttrs = mock(EvictionAttributes.class); when(ratts.getEvictionAttributes()).thenReturn(evictionAttrs); when(evictionAttrs.getAlgorithm()).thenReturn(EvictionAlgorithm.NONE); Map<String, Analyzer> fieldMap = new HashMap<String, Analyzer>(); fieldMap.put("field1", null); fieldMap.put("field2", null); testService.createIndex("index", "region", fieldMap, null, true); }
@Override public String cancelInProgress() { String reason = getDistributedSystem().getCancelCriterion().cancelInProgress(); if (reason != null) { return reason; } if (GemFireCacheImpl.this.disconnectCause != null) { return GemFireCacheImpl.this.disconnectCause.getMessage(); } if (GemFireCacheImpl.this.isClosing) { return "The cache is closed."; // this + ": closed"; } return null; }
@Test public void testLocalSize() throws Exception { ParallelGatewaySenderQueueMetaRegion mockMetaRegion = mock(ParallelGatewaySenderQueueMetaRegion.class); PartitionedRegionDataStore dataStore = mock(PartitionedRegionDataStore.class); when(mockMetaRegion.getDataStore()).thenReturn(dataStore); when(dataStore.getSizeOfLocalPrimaryBuckets()).thenReturn(3); when(metaRegionFactory.newMetataRegion(any(), any(), any(), any())).thenReturn(mockMetaRegion); when(cache.createVMRegion(any(), any(), any())).thenReturn(mockMetaRegion); queue.addShadowPartitionedRegionForUserPR(mockPR("region1")); assertEquals(3, queue.localSize()); }
initializeServices(); applyJarAndXmlFromClusterConfig(); initializeDeclarativeCache(); completedCacheXml = true; } catch (RuntimeException e) { close(); // fix for bug 34041 } catch (Throwable ignore) { startColocatedJmxManagerLocator(); startMemcachedServer(); startRedisServer(); startRestAgentServer(this);
regions.add(mockR2); when(mockCache.isClosed()).thenReturn(false); when(mockCache.getPartitionedRegions()).thenReturn(regions); when(mockCache.getResourceManager()).thenReturn(mockRM); when(mockCache.getInternalResourceManager()).thenReturn(mockRM); when(mockRM.getLoadProbe()).thenReturn(mockProbe); when(mockR1.getRedundancyProvider()).thenReturn(mockRedundancyProviderR1);
throws RegionExistsException, TimeoutException, IOException, ClassNotFoundException { if (getMyId().getVmKind() == ClusterDistributionManager.LOCATOR_DM_TYPE) { if (!internalRegionArgs.isUsedForMetaRegion() && internalRegionArgs.getInternalMetaRegion() == null) { RegionNameValidation.validate(name, internalRegionArgs); RegionAttributes<K, V> attrs = p_attrs; attrs = invokeRegionBefore(null, name, attrs, internalRegionArgs); if (attrs == null) { throw new IllegalArgumentException( getCancelCriterion().checkCancelInProgress(null); determineDefaultPool(); regionReinitialized(region); setRegionByPath(region.getFullPath(), region); region.preInitialize(); region.initialize(snapshotInputStream, imageTarget, internalRegionArgs); setRegionByPath(region.getFullPath(), null); synchronized (this.rootRegions) { Region rootRegion = this.rootRegions.get(name); invokeRegionAfter(region);
@Before public void before() throws Exception { System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "statsDisabled", "true"); getRegionsFunction = new GetRegionsFunction(); MockitoAnnotations.initMocks(this); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.cache.getDistributedSystem()).thenReturn(mock(InternalDistributedSystem.class)); when(this.cache.getResourceManager()).thenReturn(this.internalResourceManager); when(functionContext.getResultSender()).thenReturn(testResultSender); when(functionContext.getCache()).thenReturn(cache); }
@Override public Region getRegion(String path) { return getRegion(path, false); }
if (!isClient()) { throw new UnsupportedOperationException(); Map<String, Pool> pools = PoolManager.getAll(); if (pools.isEmpty()) { defaultPoolFactory = createDefaultPF(); } else if (pools.size() == 1) { pool = findFirstCompatiblePool(pools); if (pool == null) { addLocalHostAsServer(defaultPoolFactory);
ResourceManager rm = cache.getResourceManager(); for (Enumeration<String> e = config.getInitParameterNames(); e.hasMoreElements();) { String param = e.nextElement(); sessionCache = cache.isClient() ? new ClientServerSessionCache(cache, properties) : new PeerToPeerSessionCache(cache, properties);
@Override public InternalQueryService getQueryService() { if (!isClient()) { return new DefaultQueryService(this); } Pool defaultPool = getDefaultPool(); if (defaultPool == null) { throw new IllegalStateException( "Client cache does not have a default pool. Use getQueryService(String poolName) instead."); } return (InternalQueryService) defaultPool.getQueryService(); }
@Test public void exportLogsRegionIsCleanedUpProperly() throws IOException, ClassNotFoundException { locator.invoke(() -> { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); ExportLogsFunction.createOrGetExistingExportLogsRegion(true, cache); assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNotNull(); }); server1.invoke(() -> { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); ExportLogsFunction.createOrGetExistingExportLogsRegion(false, cache); assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNotNull(); }); locator.invoke(() -> { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); ExportLogsFunction.destroyExportLogsRegion(cache); assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNull(); }); server1.invoke(() -> { Cache cache = GemFireCacheImpl.getInstance(); assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNull(); }); }