Search in sources :

Example 1 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class JUnit4CacheTestCase method createRegion.

public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException {
    Region root = getRootRegion(rootName);
    if (root == null) {
        // don't put listeners on root region
        RegionAttributes rootAttrs = attributes;
        AttributesFactory fac = new AttributesFactory(attributes);
        ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
        // fac.setCacheListener(null);
        fac.setCacheLoader(null);
        fac.setCacheWriter(null);
        fac.setPoolName(null);
        fac.setPartitionAttributes(null);
        fac.setRegionTimeToLive(expiration);
        fac.setEntryTimeToLive(expiration);
        fac.setRegionIdleTimeout(expiration);
        fac.setEntryIdleTimeout(expiration);
        rootAttrs = fac.create();
        root = createRootRegion(rootName, rootAttrs);
    }
    InternalRegionArguments internalArgs = getInternalRegionArguments();
    if (internalArgs == null) {
        return root.createSubregion(name, attributes);
    } else {
        try {
            LocalRegion lr = (LocalRegion) root;
            return lr.createSubregion(name, attributes, internalArgs);
        } catch (IOException ioe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(ioe);
            throw assErr;
        } catch (ClassNotFoundException cnfe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(cnfe);
            throw assErr;
        }
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 2 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.

private void createBucketRegionQueue() {
    // Create InternalRegionArguments
    InternalRegionArguments ira = new InternalRegionArguments();
    ira.setPartitionedRegion(this.queueRegion);
    ira.setPartitionedRegionBucketRedundancy(1);
    BucketAdvisor ba = mock(BucketAdvisor.class);
    ira.setBucketAdvisor(ba);
    InternalRegionArguments pbrIra = new InternalRegionArguments();
    RegionAdvisor ra = mock(RegionAdvisor.class);
    when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
    pbrIra.setPartitionedRegionAdvisor(ra);
    PartitionAttributes pa = mock(PartitionAttributes.class);
    when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
    when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
        }
    });
    when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
    when(pa.getColocatedWith()).thenReturn(null);
    // classes cannot be mocked
    ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
    when(ba.getProxyBucketRegion()).thenReturn(pbr);
    // Create RegionAttributes
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
    RegionAttributes attributes = factory.create();
    // Create BucketRegionQueue
    BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    this.bucketRegionQueue = spy(realBucketRegionQueue);
    // (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
    doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
    // when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
    this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) BucketRegionQueueHelper(org.apache.geode.internal.cache.BucketRegionQueueHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 3 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class RestAgent method createParameterizedQueryRegion.

/**
   * This method will create a REPLICATED region named _ParameterizedQueries__. In developer REST
   * APIs, this region will be used to store the queryId and queryString as a key and value
   * respectively.
   */
public static void createParameterizedQueryRegion() {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Starting creation of  __ParameterizedQueries__ region");
        }
        InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
        if (cache != null) {
            final InternalRegionArguments regionArguments = new InternalRegionArguments();
            regionArguments.setIsUsedForMetaRegion(true);
            final AttributesFactory<String, String> attributesFactory = new AttributesFactory<String, String>();
            attributesFactory.setConcurrencyChecksEnabled(false);
            attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
            attributesFactory.setKeyConstraint(String.class);
            attributesFactory.setScope(Scope.DISTRIBUTED_ACK);
            attributesFactory.setStatisticsEnabled(false);
            attributesFactory.setValueConstraint(String.class);
            final RegionAttributes<String, String> regionAttributes = attributesFactory.create();
            cache.createVMRegion("__ParameterizedQueries__", regionAttributes, regionArguments);
            if (logger.isDebugEnabled()) {
                logger.debug("Successfully created __ParameterizedQueries__ region");
            }
        } else {
            logger.error("Cannot create ParameterizedQueries Region as no cache found!");
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error creating __ParameterizedQueries__ Region with cause {}", e.getMessage(), e);
        }
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) UnknownHostException(java.net.UnknownHostException)

Example 4 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class GeodeRedisServer method initializeRedis.

private void initializeRedis() {
    synchronized (this.cache) {
        Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
        Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
        Region<String, RedisDataType> redisMetaData;
        InternalCache gemFireCache = (InternalCache) cache;
        try {
            if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
                RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
                stringsRegion = regionFactory.create(STRING_REGION);
            }
            if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
                RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
                hLLRegion = regionFactory.create(HLL_REGION);
            }
            if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
                AttributesFactory af = new AttributesFactory();
                af.addCacheListener(metaListener);
                af.setDataPolicy(DataPolicy.REPLICATE);
                InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
                redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(), ira);
            }
        } catch (IOException | ClassNotFoundException e) {
            // only if loading snapshot, not here
            InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
            assErr.initCause(e);
            throw assErr;
        }
        this.regionCache = new RegionProvider(stringsRegion, hLLRegion, redisMetaData, expirationFutures, expirationExecutor, this.DEFAULT_REGION_TYPE);
        redisMetaData.put(REDIS_META_DATA_REGION, RedisDataType.REDIS_PROTECTED);
        redisMetaData.put(HLL_REGION, RedisDataType.REDIS_PROTECTED);
        redisMetaData.put(STRING_REGION, RedisDataType.REDIS_PROTECTED);
    }
    checkForRegions();
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) RegionProvider(org.apache.geode.redis.internal.RegionProvider) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) AttributesFactory(org.apache.geode.cache.AttributesFactory) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) HyperLogLogPlus(org.apache.geode.internal.hll.HyperLogLogPlus) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 5 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class RegionNameValidationJUnitTest method testExternalRegionNames.

@Test
public void testExternalRegionNames() {
    InternalRegionArguments ira = new InternalRegionArguments();
    ira.setInternalRegion(false);
    validateCharacters(ira);
    try {
        LocalRegion.validateRegionName("__InvalidInternalRegionName", ira);
        fail();
    } catch (IllegalArgumentException ignore) {
    }
}
Also used : InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 IOException (java.io.IOException)13 RegionAttributes (org.apache.geode.cache.RegionAttributes)7 InternalCache (org.apache.geode.internal.cache.InternalCache)6 TimeoutException (org.apache.geode.cache.TimeoutException)4 Test (org.junit.Test)4 InternalGemFireError (org.apache.geode.InternalGemFireError)3 CacheException (org.apache.geode.cache.CacheException)3 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)3 Region (org.apache.geode.cache.Region)3 RegionExistsException (org.apache.geode.cache.RegionExistsException)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 File (java.io.File)2 CancelException (org.apache.geode.CancelException)2 Cache (org.apache.geode.cache.Cache)2 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)2 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)2 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)2 HasCachePerfStats (org.apache.geode.internal.cache.HasCachePerfStats)2