@Override public String toString() { return new StringBuffer().append("Partitioned Region ").append("@") .append(Integer.toHexString(hashCode())).append(" [").append("path='").append(getFullPath()) .append("'; dataPolicy=").append(this.getDataPolicy()).append("; prId=") .append(this.partitionedRegionId).append("; isDestroyed=").append(this.isDestroyed) .append("; isClosed=").append(this.isClosed).append("; retryTimeout=") .append(this.retryTimeout).append("; serialNumber=").append(getSerialNumber()) .append("; partition attributes=").append(getPartitionAttributes().toString()) .append("; on VM ").append(getMyId()).append("]").toString(); }
public boolean isRedundancyImpaired() { int numBuckets = this.prRegion.getPartitionAttributes().getTotalNumBuckets(); int targetRedundancy = this.prRegion.getPartitionAttributes().getRedundantCopies(); for (int i = 0; i < numBuckets; i++) { int redundancy = this.prRegion.getRegionAdvisor().getBucketRedundancy(i); if (redundancy < targetRedundancy && redundancy != -1 || redundancy > targetRedundancy) { return true; } } return false; }
if (this.getTotalNumBuckets() != colocatedRegion.getPartitionAttributes() .getTotalNumBuckets()) { throw new IllegalStateException( "Current PartitionedRegion's TotalNumBuckets should be same as TotalNumBuckets of colocated PartitionedRegion"); if (this.getRedundancy() != colocatedRegion.getPartitionAttributes().getRedundantCopies()) { throw new IllegalStateException( "Current PartitionedRegion's redundancy should be same as the redundancy of colocated PartitionedRegion");
private PartitionedRegion mockPR(String name) { PartitionedRegion region = mock(PartitionedRegion.class); when(region.getFullPath()).thenReturn(name); when(region.getPartitionAttributes()).thenReturn(new PartitionAttributesFactory<>().create()); when(region.getTotalNumberOfBuckets()).thenReturn(113); when(region.getDataPolicy()).thenReturn(DataPolicy.PARTITION); return region; }
delay = this.prRegion.getPartitionAttributes().getStartupRecoveryDelay(); movePrimaries = !Boolean .getBoolean(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_MOVE_PRIMARIES_ON_STARTUP"); } else { delay = this.prRegion.getPartitionAttributes().getRecoveryDelay(); movePrimaries = false;
@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); } }
private Region initializeScenario(final boolean withPersistence, final String regionPath, final Cache cache, int localMaxMemory) { PartitionedRegion region = mock(PartitionedRegion.class); PartitionAttributes partitionAttributes = new PartitionAttributesFactory() .setLocalMaxMemory(localMaxMemory).setTotalNumBuckets(103).create(); RegionAttributes regionAttributes = spy(createRegionAttributes(withPersistence, partitionAttributes)); ExtensionPoint extensionPoint = mock(ExtensionPoint.class); when(cache.getRegion(regionPath)).thenReturn(region); when(cache.getRegionAttributes(any())).thenReturn(regionAttributes); when(region.getAttributes()).thenReturn(regionAttributes); when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes); when(region.getPartitionAttributes()).thenReturn(partitionAttributes); when(region.getExtensionPoint()).thenReturn(extensionPoint); return region; }
@Test public void validateColocationWithSimilarPartitionedRegion() { PartitionedRegion region = mock(PartitionedRegion.class); PartitionAttributes prAttributes = mock(PartitionAttributes.class); when(cache.getRegion("PrRegion")).thenReturn(region); when(region.getPartitionAttributes()).thenReturn(prAttributes); PartitionAttributesImpl instance = createPartitionAttributesImpl(); when(prAttributes.getTotalNumBuckets()).thenReturn(instance.getTotalNumBuckets()); when(prAttributes.getRedundantCopies()).thenReturn(instance.getRedundantCopies()); instance.setColocatedWith("PrRegion"); instance.validateColocation(cache); verify(cache, times(1)).getRegion("PrRegion"); }
if (colocatedPR.getPartitionAttributes().getTotalNumBuckets() != userPA .getTotalNumBuckets()) { throw new IllegalStateException( "Colocated regions should have same number of total-num-buckets"); if (colocatedPR.getPartitionAttributes().getRedundantCopies() != userPA .getRedundantCopies()) { throw new IllegalStateException( "Colocated regions should have same number of redundant-copies"); if ((colocatedPR.getPartitionAttributes().getLocalMaxMemory() == 0) && (userPA.getLocalMaxMemory() != 0)) { throw new IllegalStateException("Colocated regions should have accessors at the same node");
/** * 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); }
String colocatedWith = partitionedRegion.getPartitionAttributes().getColocatedWith(); if (colocatedWith == null) {
when(partitionedRegion.getPartitionAttributes()).thenReturn(new PartitionAttributesImpl()); when(partitionedRegion.getRedundancyTracker()) .thenReturn(mock(PartitionedRegionRedundancyTracker.class));
protected PartitionedRegionBridge(Region<K, V> region) { super(region); this.parRegion = (PartitionedRegion) region; this.prStats = parRegion.getPrStats(); PartitionAttributes<K, V> partAttrs = parRegion.getPartitionAttributes(); this.parRegionMonitor = new MBeanStatsMonitor(PAR_REGION_MONITOR); this.configurePartitionRegionMetrics(); this.configuredRedundancy = partAttrs.getRedundantCopies(); this.partitionAttributesData = RegionMBeanCompositeDataFactory.getPartitionAttributesData(partAttrs); if (partAttrs.getFixedPartitionAttributes() != null) { this.fixedPartitionAttributesTable = RegionMBeanCompositeDataFactory.getFixedPartitionAttributesData(partAttrs); } parRegionMonitor.addStatisticsToMonitor(prStats.getStats()); }
pbrIra.setPartitionedRegionAdvisor(ra); PartitionAttributes pa = mock(PartitionAttributes.class); when(queueRegion.getPartitionAttributes()).thenReturn(pa);
pfact.setLocalMaxMemory(localMaxMemory); pfact.setStartupRecoveryDelay(userPR.getPartitionAttributes().getStartupRecoveryDelay()); pfact.setRecoveryDelay(userPR.getPartitionAttributes().getRecoveryDelay());