@Override public Region getRegion(String path) { return getRegion(path, false); }
/** * return the cq/interest information for a given region name, creating one if it doesn't exist */ @Override public FilterProfile getFilterProfile(String regionName) { InternalRegion r = (InternalRegion) getRegion(regionName, true); if (r != null) { return r.getFilterProfile(); } return null; }
private SortedMap<String, PartitionedRegion> getPartitionedRegionMap() { SortedMap<String, PartitionedRegion> prMap = new TreeMap<>(); for (Entry<String, InternalRegion> entry : this.pathToRegion.entrySet()) { String regionName = entry.getKey(); InternalRegion region = entry.getValue(); // Don't wait for non partitioned regions if (!(region instanceof PartitionedRegion)) { continue; } // Do a getRegion to ensure that we wait for the partitioned region // to finish initialization try { Region pr = getRegion(regionName); if (pr instanceof PartitionedRegion) { prMap.put(regionName, (PartitionedRegion) pr); } } catch (CancelException ignore) { // if some region throws cancel exception during initialization, // then no need to shutDownAll them gracefully } } return prMap; }
private void createRootRegion() { // Mock root region this.rootRegion = mock(PartitionedRegion.class); when(this.rootRegion.getFullPath()) .thenReturn(Region.SEPARATOR + PartitionedRegionHelper.PR_ROOT_REGION_NAME); when(this.cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, true)) .thenReturn(this.rootRegion); when(this.cache.getRegion(ParallelGatewaySenderHelper.getRegionQueueName(GATEWAY_SENDER_ID))) .thenReturn(this.queueRegion); }
/** Return true if this region is initializing */ @Override public boolean isGlobalRegionInitializing(String fullPath) { this.stopper.checkCancelInProgress(null); int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT); // go through // initialization latches try { return isGlobalRegionInitializing((InternalRegion) getRegion(fullPath)); } finally { LocalRegion.setThreadInitLevelRequirement(oldLevel); } }
private Object getSynchronizationEvents() { List<Map<String, GatewayQueueEvent>> results = new ArrayList<>(); // Get the region GemFireCacheImpl gfci = (GemFireCacheImpl) getCache(); LocalRegion region = (LocalRegion) gfci.getRegion(this.regionPath); // Add the appropriate GatewaySenderEventImpl from each GatewaySender for each entry Set<String> allGatewaySenderIds = region.getAllGatewaySenderIds(); for (GatewaySender sender : gfci.getAllGatewaySenders()) { if (allGatewaySenderIds.contains(sender.getId())) { for (GatewaySenderQueueEntrySynchronizationEntry entry : this.entriesToSynchronize) { Map<String, GatewayQueueEvent> resultForOneEntry = new HashMap<>(); GatewayQueueEvent event = ((AbstractGatewaySender) sender) .getSynchronizationEvent(entry.key, entry.entryVersion.getVersionTimeStamp()); if (event != null) { resultForOneEntry.put(sender.getId(), event); } results.add(resultForOneEntry); } } } return results; }
@Override @Before public void setUp() { cache = Fakes.cache(); userRegion = Mockito.mock(PartitionedRegion.class); userDataStore = Mockito.mock(PartitionedRegionDataStore.class); when(userRegion.getDataStore()).thenReturn(userDataStore); when(cache.getRegion("/testRegion")).thenReturn(userRegion); serializer = new HeterogeneousLuceneSerializer(); createIndexAndRepoManager(); }
@Test public void testGetColocatedRegionThrowsCacheClosedExceptionWhenCacheIsClosed() { when(pr.getCache()).thenReturn(cache); DistributedRegion prRoot = mock(DistributedRegion.class); when(cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, true)) .thenReturn(prRoot); when(pr.getPartitionAttributes()).thenReturn(pa); when(pa.getColocatedWith()).thenReturn("region2"); PartitionRegionConfig partitionRegionConfig = mock(PartitionRegionConfig.class); when(prRoot.get(any())).thenReturn(partitionRegionConfig); CancelCriterion cancelCriterion = mock(CancelCriterion.class); when(cache.getCancelCriterion()).thenReturn(cancelCriterion); doThrow(CacheClosedException.class).when(cancelCriterion).checkCancelInProgress(any()); assertThatThrownBy(() -> ColocationHelper.getColocatedRegion(pr)) .isInstanceOf(CacheClosedException.class); } }
@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(); }); }
Region dynamicMetaRegion = getRegion(DynamicRegionFactory.DYNAMIC_REGION_LIST_NAME); if (dynamicMetaRegion == null) { if (logger.isDebugEnabled()) {
@Before public void setUp() throws Exception { cache = Fakes.cache(); userRegion = Mockito.mock(PartitionedRegion.class); userDataStore = Mockito.mock(PartitionedRegionDataStore.class); when(userRegion.getDataStore()).thenReturn(userDataStore); when(cache.getRegion("/testRegion")).thenReturn(userRegion); serializer = new HeterogeneousLuceneSerializer(); DLockService lockService = mock(DLockService.class); when(lockService.lock(any(), anyLong(), anyLong())).thenReturn(true); when(userRegion.getRegionService()).thenReturn(cache); DLockService.addLockServiceForTests(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME, lockService); createIndexAndRepoManager(); }
@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); }
/** * Test method for * {@link org.apache.geode.internal.cache.ColocationHelper#getColocatedRegion(org.apache.geode.internal.cache.PartitionedRegion)}. */ @Test public void testGetColocatedRegionThrowsIllegalStateExceptionForMissingParentRegion() { when(pr.getCache()).thenReturn(cache); when(cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, true)) .thenReturn(mock(DistributedRegion.class)); when(pr.getPartitionAttributes()).thenReturn(pa); when(pr.getFullPath()).thenReturn("/region1"); when(pa.getColocatedWith()).thenReturn("region2"); PartitionedRegion colocatedPR; boolean caughtIllegalStateException = false; try { colocatedPR = ColocationHelper.getColocatedRegion(pr); } catch (Exception e) { assertEquals("Expected IllegalStateException for missing colocated parent region", IllegalStateException.class, e.getClass()); assertTrue("Expected IllegalStateException to be thrown for missing colocated region: " + e.getMessage(), e.getMessage().matches("Region specified in 'colocated-with' .* does not exist.*")); caughtIllegalStateException = true; } assertTrue(caughtIllegalStateException); }
/** * Test method for * {@link org.apache.geode.internal.cache.ColocationHelper#getColocatedRegion(org.apache.geode.internal.cache.PartitionedRegion)}. */ @Test public void testGetColocatedRegionLogsWarningForMissingRegionWhenPRConfigHasRegion() { when(pr.getCache()).thenReturn(cache); when(cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, true)).thenReturn(prRoot); when(pr.getPartitionAttributes()).thenReturn(pa); when(pr.getFullPath()).thenReturn("/region1"); when(pa.getColocatedWith()).thenReturn("region2"); when(((Region) prRoot).get("#region2")).thenReturn(prc); PartitionedRegion colocatedPR = null; boolean caughtIllegalStateException = false; try { colocatedPR = ColocationHelper.getColocatedRegion(pr); } catch (Exception e) { assertEquals("Expected IllegalStateException for missing colocated parent region", IllegalStateException.class, e.getClass()); assertTrue("Expected IllegalStateException to be thrown for missing colocated region", e.getMessage().matches("Region specified in 'colocated-with' .* does not exist.*")); caughtIllegalStateException = true; } assertTrue(caughtIllegalStateException); }
when(cache.getRegion(index1.getRegionPath())).thenReturn(userRegion);
@Test @SuppressWarnings("unchecked") public void testExecute() throws LuceneQueryException { FunctionContext context = mock(FunctionContext.class); ResultSender resultSender = mock(ResultSender.class); GemFireCacheImpl cache = Fakes.cache(); LuceneQueryInfo queryInfo = createMockQueryInfo("index", "region", "field1:region1", "field1", 1); InternalLuceneService service = getMockLuceneService("A", "Value", "1.2"); Region mockRegion = mock(Region.class); LuceneSearchIndexFunction function = new LuceneSearchIndexFunction(); doReturn(queryInfo).when(context).getArguments(); doReturn(resultSender).when(context).getResultSender(); doReturn(cache).when(context).getCache(); when(cache.getService(eq(InternalLuceneService.class))).thenReturn(service); when(cache.getRegion(queryInfo.getRegionPath())).thenReturn(mockRegion); function.execute(context); ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class); verify(resultSender).lastResult(resultCaptor.capture()); Set<LuceneSearchResults> result = resultCaptor.getValue(); assertEquals(1, result.size()); for (LuceneSearchResults searchResult : result) { assertEquals("A", searchResult.getKey()); assertEquals("Value", searchResult.getValue()); assertEquals(1.2, searchResult.getScore(), .1); } }
localRegion = (LocalRegion) GemFireCacheImpl.getInstance().getRegion(this.region); } catch (Exception ignore) {