Search in sources :

Example 1 with InternalRegionFunctionContext

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with InternalRegionFunctionContext

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));
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) RegionEntry(org.apache.geode.internal.cache.RegionEntry) ResultSender(org.apache.geode.cache.execute.ResultSender) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with InternalRegionFunctionContext

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);
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) Map(java.util.Map)

Example 4 with InternalRegionFunctionContext

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);
}
Also used : Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext)

Example 5 with InternalRegionFunctionContext

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;
}
Also used : Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) Map(java.util.Map)

Aggregations

InternalRegionFunctionContext (org.apache.geode.internal.cache.execute.InternalRegionFunctionContext)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Region (org.apache.geode.cache.Region)2 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)2 ArrayList (java.util.ArrayList)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 IndexRepositoryImpl (org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)1 Query (org.apache.geode.cache.query.Query)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 BucketNotFoundException (org.apache.geode.internal.cache.BucketNotFoundException)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)1 LocalDataSet (org.apache.geode.internal.cache.LocalDataSet)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 RegionEntry (org.apache.geode.internal.cache.RegionEntry)1