ColocationHelper { public static PartitionedRegion getColocatedRegion(final PartitionedRegion partitionedRegion) { Assert.assertTrue(partitionedRegion != null); String colocatedWith = partitionedRegion.getPartitionAttributes().getColocatedWith(); if (colocatedWith == null) { return null; } Region prRoot = PartitionedRegionHelper.getPRRoot(partitionedRegion.getCache()); PartitionRegionConfig prConf = (PartitionRegionConfig) prRoot.get(getRegionIdentifier(colocatedWith)); if (prConf == null) { partitionedRegion.getCache().getCancelCriterion().checkCancelInProgress(null); throw new IllegalStateException( String.format( "Region specified in 'colocated-with' (%s) for region %s does not exist. It should be created before setting 'colocated-with' attribute for this region.", new Object[] {colocatedWith, partitionedRegion.getFullPath()})); } int prID = prConf.getPRId(); PartitionedRegion colocatedPR = null; try { colocatedPR = PartitionedRegion.getPRFromId(prID); if (colocatedPR != null) { colocatedPR.waitOnBucketMetadataInitialization(); } else { partitionedRegion.getCache().getCancelCriterion().checkCancelInProgress(null); throw new IllegalStateException( String.format( "Region specified in 'colocated-with' (%s) for region %s does not exist. It should be created before setting 'colocated-with' attribute for this region.", new Object[] {colocatedWith, partitionedRegion.getFullPath()})); } } catch (PRLocallyDestroyedException e) { if (logger.isDebugEnabled()) { logger.debug( "PRLocallyDestroyedException : Region with prId={} is locally destroyed on this node", prID, e); } } return colocatedPR; }  static PartitionedRegion getColocatedRegion(final PartitionedRegion partitionedRegion); static boolean checkMembersColocation(PartitionedRegion partitionedRegion,
      InternalDistributedMember member); static boolean isColocationComplete(PartitionedRegion region); static Map<String, PartitionedRegion> getAllColocationRegions(
      PartitionedRegion partitionedRegion); static Map<String, Region> getAllColocatedLocalDataSets(
      PartitionedRegion partitionedRegion, InternalRegionFunctionContext context); static Map<String, LocalDataSet> constructAndGetAllColocatedLocalDataSet(
      PartitionedRegion region, int[] bucketArray); static Map<String, LocalDataSet> getColocatedLocalDataSetsForBuckets(
      PartitionedRegion region, Set<Integer> bucketSet); static List<PartitionedRegion> getColocatedChildRegions(
      PartitionedRegion partitionedRegion); static Function getFunctionInstance(Serializable function); static PartitionedRegion getLeaderRegion(PartitionedRegion prRegion); static boolean hasPersistentChildRegion(PartitionedRegion region); @MutableForTesting
  static boolean IGNORE_UNRECOVERED_QUEUE; }
@Test public void getColocatedRegion_throwsIllegalStateException_ifNotColocated() { when(partitionedRegion.getFullPath()).thenReturn(SEPARATOR + "region1"); Throwable thrown = catchThrowable(() -> ColocationHelper.getColocatedRegion(partitionedRegion)); assertThat(thrown) .as("Expected IllegalStateException for missing colocated parent region") .isInstanceOf(IllegalStateException.class) .hasMessageMatching("Region specified in 'colocated-with' .* does not exist.*"); }
@Test public void getColocatedRegion_logsWarning_ifMissingRegion_whenPRConfigHasRegion() { when(partitionedRegion.getFullPath()).thenReturn(SEPARATOR + "region1"); when(prRoot.get(eq("#region2"))).thenReturn(partitionRegionConfig); Throwable thrown = catchThrowable(() -> ColocationHelper.getColocatedRegion(partitionedRegion)); assertThat(thrown) .as("Expected IllegalStateException for missing colocated parent region") .isInstanceOf(IllegalStateException.class) .hasMessageMatching("Region specified in 'colocated-with' .* does not exist.*"); }
@Test public void getColocatedRegion_throwsCacheClosedException_whenCacheIsClosed() { doThrow(new CacheClosedException("test")).when(cancelCriterion).checkCancelInProgress(any()); when(prRoot.get(any())).thenReturn(partitionRegionConfig); Throwable thrown = catchThrowable(() -> ColocationHelper.getColocatedRegion(partitionedRegion)); assertThat(thrown) .isInstanceOf(CacheClosedException.class); }