public boolean isPartitionedRegionReady(PartitionedRegion partitionedRegion, final int bucketId) { List<PartitionedRegion> colocatedWithList = getColocatedChildRegions(partitionedRegion); if (colocatedWithList.size() == 0) { return partitionedRegion.isInitialized(); } return areAllColocatedPartitionedRegionsReady(bucketId, colocatedWithList); }
private void setupColocatedRegions(PartitionedRegionDataStore partitionedRegionDataStore) { List<PartitionedRegion> colocatedChildRegions = new ArrayList<PartitionedRegion>(); colocatedChildRegions.add(childRegion1); colocatedChildRegions.add(childRegion2); doReturn(colocatedChildRegions).when(partitionedRegionDataStore) .getColocatedChildRegions(partitionedRegion); List<PartitionedRegion> childRegion1ColocatedRegions = new ArrayList<PartitionedRegion>(); colocatedChildRegions.add(grandChildRegion1_1); colocatedChildRegions.add(grandChildRegion1_2); doReturn(childRegion1ColocatedRegions).when(partitionedRegionDataStore) .getColocatedChildRegions(childRegion1); List<PartitionedRegion> childRegion2ColocatedRegions = new ArrayList<PartitionedRegion>(); colocatedChildRegions.add(grandChildRegion2_1); colocatedChildRegions.add(grandChildRegion2_2); colocatedChildRegions.add(grandChildRegion2_3); doReturn(childRegion2ColocatedRegions).when(partitionedRegionDataStore) .getColocatedChildRegions(childRegion2); List<PartitionedRegion> emptyList = new ArrayList<PartitionedRegion>(); doReturn(emptyList).when(partitionedRegionDataStore) .getColocatedChildRegions(grandChildRegion1_1); doReturn(emptyList).when(partitionedRegionDataStore) .getColocatedChildRegions(grandChildRegion1_2); doReturn(emptyList).when(partitionedRegionDataStore) .getColocatedChildRegions(grandChildRegion2_1); doReturn(emptyList).when(partitionedRegionDataStore) .getColocatedChildRegions(grandChildRegion2_2); doReturn(emptyList).when(partitionedRegionDataStore) .getColocatedChildRegions(grandChildRegion2_3); }
private boolean isColocatedPartitionedRegionInitialized(PartitionedRegion partitionedRegion, final int bucketId) { if (!partitionedRegion.isInitialized()) { return false; } if (!partitionedRegion.getDataStore().isColocationComplete(bucketId)) { return false; } List<PartitionedRegion> colocatedWithList = getColocatedChildRegions(partitionedRegion); return areAllColocatedPartitionedRegionsReady(bucketId, colocatedWithList); }
@Test public void initializedPartitionedRegionWithoutColocationReturnsRegionReady() { PartitionedRegionDataStore partitionedRegionDataStore = spy(new PartitionedRegionDataStore()); List<PartitionedRegion> colocatedChildRegions = new ArrayList<PartitionedRegion>(); doReturn(colocatedChildRegions).when(partitionedRegionDataStore) .getColocatedChildRegions(partitionedRegion); assertThat(partitionedRegionDataStore.isPartitionedRegionReady(partitionedRegion, bucketId)) .isTrue(); }
@Test public void notInitializedPartitionedRegionWithoutColocationReturnsRegionNotReady() { PartitionedRegionDataStore partitionedRegionDataStore = spy(new PartitionedRegionDataStore()); List<PartitionedRegion> colocatedChildRegions = new ArrayList<PartitionedRegion>(); doReturn(colocatedChildRegions).when(partitionedRegionDataStore) .getColocatedChildRegions(partitionedRegion); when(partitionedRegion.isInitialized()).thenReturn(false); assertThat(partitionedRegionDataStore.isPartitionedRegionReady(partitionedRegion, bucketId)) .isFalse(); }