@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()); }
@Test public void invokeClientOperationsOnInternalRegion() { serverVM.invoke(() -> { // we need to use internal APIs to create an "internal" region GemFireCacheImpl serverCache = (GemFireCacheImpl) cache; InternalRegionArguments internalRegionArguments = new InternalRegionArguments(); internalRegionArguments.setIsUsedForPartitionedRegionAdmin(true); RegionAttributes<String, String> attributes = serverCache.getRegionAttributes(RegionShortcut.REPLICATE.toString()); LocalRegion region = (LocalRegion) serverCache.createVMRegion("internalRegion", attributes, internalRegionArguments); assertThat(region.isInternalRegion()).isTrue(); }); clientVM.invoke(this::testAllOperations); }
when(prRoot.getDistributionAdvisor()).thenReturn(cda); doNothing().when(cda).addMembershipListener(any()); when(cache.createVMRegion(eq(PR_ROOT_REGION_NAME), any(), any())).thenReturn(prRoot);
@Test public void createFileRegionWithPartitionShortcutCreatesRegionUsingCreateVMRegion() throws Exception { String name = "indexName"; String regionPath = "regionName"; GemFireCacheImpl cache = Fakes.cache(); RegionAttributes regionAttributes = mock(RegionAttributes.class); when(regionAttributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION); PartitionAttributes partitionAttributes = initializeAttributes(cache); LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath, cache); LuceneIndexForPartitionedRegion indexSpy = spy(index); indexSpy.createRegion(index.createFileRegionName(), RegionShortcut.PARTITION, regionPath, partitionAttributes, regionAttributes, null); String fileRegionName = index.createFileRegionName(); verify(indexSpy).createRegion(fileRegionName, RegionShortcut.PARTITION, regionPath, partitionAttributes, regionAttributes, null); verify(cache).createVMRegion(eq(fileRegionName), any(), any()); }
@Override public <K, V> Region<K, V> basicCreateRegion(String name, RegionAttributes<K, V> attrs) throws RegionExistsException, TimeoutException { try { InternalRegionArguments ira = new InternalRegionArguments().setDestroyLockFlag(true) .setRecreateFlag(false).setSnapshotInputStream(null).setImageTarget(null); if (attrs instanceof UserSpecifiedRegionAttributes) { ira.setIndexes(((UserSpecifiedRegionAttributes) attrs).getIndexes()); } return createVMRegion(name, attrs, ira); } catch (IOException | ClassNotFoundException e) { // only if loading snapshot, not here throw new InternalGemFireError( "unexpected exception", e); } }
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() { // a sessionFactory in hibernate could have been re-started // so, it is possible that this region exists already Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION); if (r != null) { return r; } GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache; InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true); AttributesFactory af = new AttributesFactory(); af.setDataPolicy(DataPolicy.REPLICATE); af.setScope(Scope.DISTRIBUTED_ACK); af.addCacheListener(new RegionConfigurationCacheListener()); RegionAttributes ra = af.create(); try { return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira); } catch (IOException | ClassNotFoundException e) { InternalGemFireError assErr = new InternalGemFireError( "unexpected exception"); assErr.initCause(e); throw assErr; } }
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() { // a sessionFactory in hibernate could have been re-started // so, it is possible that this region exists already Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION); if (r != null) { return r; } GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache; InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true); AttributesFactory af = new AttributesFactory(); af.setScope(Scope.LOCAL); af.addCacheListener(new RegionConfigurationCacheListener()); RegionAttributes ra = af.create(); try { return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira); } catch (IOException | ClassNotFoundException e) { InternalGemFireError assErr = new InternalGemFireError( LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString()); assErr.initCause(e); throw assErr; } }