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;
}
}
}
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);
}
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);
}
}
}
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();
}
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) {
}
}
Aggregations