use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
queryUpdateExecuted = false;
queryDestroyExecuted = false;
notADeltaInstanceObj = false;
isFailed = false;
procced = false;
numValidCqEvents = 0;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
if (subscriptionEnable.booleanValue()) {
deltaPR.registerInterest("ALL_KEYS");
}
pool = p;
if (isCq.booleanValue()) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
@SuppressWarnings("synthetic-access")
public void onEvent(CqEvent cqEvent) {
if (LAST_KEY.equals(cqEvent.getKey().toString())) {
lastKeyReceived = true;
} else if (!(cqEvent.getNewValue() instanceof Delta)) {
notADeltaInstanceObj = true;
} else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryUpdateExecuted = true;
} else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryDestroyExecuted = true;
}
if (forOldNewCQVarification) {
if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
procced = true;
} else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
// this tell us that every thing is fine
isFailed = true;
}
}
}
numValidCqEvents++;
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
cq.execute();
}
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class LuceneRegionListener method beforeCreate.
@Override
public RegionAttributes beforeCreate(Region parent, String regionName, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) {
RegionAttributes updatedRA = attrs;
String path = parent == null ? "/" + regionName : parent.getFullPath() + "/" + regionName;
if (path.equals(this.regionPath)) {
if (!attrs.getDataPolicy().withPartitioning()) {
// replicated region
throw new UnsupportedOperationException("Lucene indexes on replicated regions are not supported");
}
// For now we cannot support eviction with local destroy.
// Eviction with overflow to disk still needs to be supported
EvictionAttributes evictionAttributes = attrs.getEvictionAttributes();
EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm();
if (evictionAlgorithm != EvictionAlgorithm.NONE && evictionAttributes.getAction().isLocalDestroy()) {
throw new UnsupportedOperationException("Lucene indexes on regions with eviction and action local destroy are not supported");
}
String aeqId = LuceneServiceImpl.getUniqueIndexName(this.indexName, this.regionPath);
if (!attrs.getAsyncEventQueueIds().contains(aeqId)) {
AttributesFactory af = new AttributesFactory(attrs);
af.addAsyncEventQueueId(aeqId);
updatedRA = af.create();
}
// Add index creation profile
internalRegionArgs.addCacheServiceProfile(new LuceneIndexCreationProfile(this.indexName, this.regionPath, this.fields, this.analyzer, this.fieldAnalyzers));
luceneIndex = this.service.beforeDataRegionCreated(this.indexName, this.regionPath, attrs, this.analyzer, this.fieldAnalyzers, aeqId, this.fields);
// Add internal async event id
internalRegionArgs.addInternalAsyncEventQueueId(aeqId);
}
return updatedRA;
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class CacheClientNotifierDUnitTest method checkCacheServer.
private void checkCacheServer(VM vm, final int serverPort, final boolean withCSC, final int capacity) {
SerializableRunnable checkCacheServer = new SerializableRunnable() {
@Override
public void run() throws Exception {
List<CacheServer> cacheServers = ((GemFireCacheImpl) cache).getCacheServersAndGatewayReceiver();
CacheServerImpl server = null;
for (CacheServer cs : cacheServers) {
if (cs.getPort() == serverPort) {
server = (CacheServerImpl) cs;
break;
}
}
assertNotNull(server);
CacheClientNotifier ccn = server.getAcceptor().getCacheClientNotifier();
HAContainerRegion haContainer = (HAContainerRegion) ccn.getHaContainer();
if (server.getAcceptor().isGatewayReceiver()) {
assertNull(haContainer);
return;
}
Region internalRegion = haContainer.getMapForTest();
RegionAttributes ra = internalRegion.getAttributes();
EvictionAttributes ea = ra.getEvictionAttributes();
if (withCSC) {
assertNotNull(ea);
assertEquals(capacity, ea.getMaximum());
assertEquals(EvictionAction.OVERFLOW_TO_DISK, ea.getAction());
} else {
assertNull(ea);
}
}
};
vm.invoke(checkCacheServer);
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class TestClientIdsDUnitTest method createServerCache.
private int createServerCache() throws IOException {
Cache cache = this.managementTestRule.getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
CacheServer cacheServer = cache.addCacheServer();
cacheServer.setPort(0);
cacheServer.setNotifyBySubscription(true);
cacheServer.start();
return cacheServer.getPort();
}
use of org.apache.geode.cache.RegionAttributes 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;
}
}
}
Aggregations