use of org.apache.geode.internal.cache.execute.InternalRegionFunctionContext in project geode by apache.
the class PartitionedRepositoryManagerJUnitTest method getMissingBucketByRegion.
/**
* Test that we get the expected exception when a user bucket is missing
*/
@Test(expected = BucketNotFoundException.class)
public void getMissingBucketByRegion() throws BucketNotFoundException {
setUpMockBucket(0);
Set<Integer> buckets = new LinkedHashSet<Integer>(Arrays.asList(0, 1));
InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
repoManager.getRepositories(ctx);
}
use of org.apache.geode.internal.cache.execute.InternalRegionFunctionContext in project geode by apache.
the class LuceneGetPageFunctionJUnitTest method shouldReturnMapWithKeyAndValue.
@Test
public void shouldReturnMapWithKeyAndValue() {
PartitionedRegion region = mock(PartitionedRegion.class);
InternalRegionFunctionContext context = mock(InternalRegionFunctionContext.class);
when(context.getDataSet()).thenReturn(region);
ResultSender resultSender = mock(ResultSender.class);
when(context.getResultSender()).thenReturn(resultSender);
LuceneGetPageFunction function = new LuceneGetPageFunction();
when(context.getLocalDataSet(any())).thenReturn(region);
final EntrySnapshot entry = mock(EntrySnapshot.class);
when(region.getEntry(any())).thenReturn(entry);
final RegionEntry regionEntry = mock(RegionEntry.class);
when(entry.getRegionEntry()).thenReturn(regionEntry);
when(regionEntry.getValue(any())).thenReturn("value");
when(context.getFilter()).thenReturn((Set) Collections.singleton("key"));
function.execute(context);
PageResults expectedResults = new PageResults();
expectedResults.add(new PageEntry("key", "value"));
verify(resultSender).lastResult(eq(expectedResults));
}
use of org.apache.geode.internal.cache.execute.InternalRegionFunctionContext in project geode by apache.
the class PartitionRegionHelper method getColocatedRegions.
/**
* Given a partitioned Region, return a map of
* {@linkplain PartitionAttributesFactory#setColocatedWith(String) colocated Regions}. Given a
* local data reference to a partitioned region, return a map of local
* {@linkplain PartitionAttributesFactory#setColocatedWith(String) colocated Regions}. If there
* are no colocated regions, return an empty map.
*
* @param r a partitioned Region
* @throws IllegalStateException if the Region is not a {@linkplain DataPolicy#PARTITION
* partitioned Region}
* @return an unmodifiable map of {@linkplain Region#getFullPath() region name} to {@link Region}
* @since GemFire 6.0
*/
public static Map<String, Region<?, ?>> getColocatedRegions(final Region<?, ?> r) {
Map ret;
if (isPartitionedRegion(r)) {
final PartitionedRegion pr = (PartitionedRegion) r;
ret = ColocationHelper.getAllColocationRegions(pr);
if (ret.isEmpty()) {
ret = Collections.emptyMap();
}
} else if (r instanceof LocalDataSet) {
LocalDataSet lds = (LocalDataSet) r;
InternalRegionFunctionContext fc = lds.getFunctionContext();
if (fc != null) {
ret = ColocationHelper.getAllColocatedLocalDataSets(lds.getProxy(), fc);
if (ret.isEmpty()) {
ret = Collections.emptyMap();
}
} else {
ret = ColocationHelper.getColocatedLocalDataSetsForBuckets(lds.getProxy(), lds.getBucketSet());
}
} else {
throw new IllegalArgumentException(LocalizedStrings.PartitionManager_REGION_0_IS_NOT_A_PARTITIONED_REGION.toLocalizedString(r.getFullPath()));
}
return Collections.unmodifiableMap(ret);
}
use of org.apache.geode.internal.cache.execute.InternalRegionFunctionContext in project geode by apache.
the class PartitionRegionHelper method getLocalDataForContext.
/**
* Given a RegionFunctionContext {@linkplain RegionFunctionContext#getDataSet() for a partitioned
* Region}, return a Region providing read access limited to the function context.<br>
* Returned Region provides only one copy of the data although
* {@link PartitionAttributes#getRedundantCopies() redundantCopies} configured is more than 0. If
* the invoking Function is configured to have {@link Function#optimizeForWrite()
* optimizeForWrite} as true,the returned Region will only contain primary copy of the data.
* <p>
* Writes using this Region have no constraints and behave the same as a partitioned Region.
*
* @param c a functions context
* @throws IllegalStateException if {@link RegionFunctionContext#getDataSet()} returns something
* other than a {@linkplain DataPolicy#PARTITION partitioned Region}
* @return a Region for efficient reads
* @since GemFire 6.0
*/
public static <K, V> Region<K, V> getLocalDataForContext(final RegionFunctionContext c) {
final Region r = c.getDataSet();
isPartitionedCheck(r);
InternalRegionFunctionContext rfci = (InternalRegionFunctionContext) c;
return rfci.getLocalDataSet(r);
}
use of org.apache.geode.internal.cache.execute.InternalRegionFunctionContext in project geode by apache.
the class PartitionRegionHelper method getLocalColocatedRegions.
/**
* Given a RegionFunctionContext {@linkplain RegionFunctionContext#getDataSet() for a partitioned
* Region}, return a map of {@linkplain PartitionAttributesFactory#setColocatedWith(String)
* colocated Regions} with read access limited to the context of the function.
* <p>
* Writes using these Region have no constraints and behave the same as a partitioned Region.
* <p>
* If there are no colocated regions, return an empty map.
*
* @param c the region function context
* @throws IllegalStateException if the Region is not a {@linkplain DataPolicy#PARTITION
* partitioned Region}
* @return an unmodifiable map of {@linkplain Region#getFullPath() region name} to {@link Region}
* @since GemFire 6.0
*/
public static Map<String, Region<?, ?>> getLocalColocatedRegions(final RegionFunctionContext c) {
final Region r = c.getDataSet();
isPartitionedCheck(r);
final InternalRegionFunctionContext rfci = (InternalRegionFunctionContext) c;
Map ret = rfci.getColocatedLocalDataSets();
return ret;
}
Aggregations