use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class ClientToServerDeltaDUnitTest method createServerCache.
/*
* create server cache
*/
public static Integer createServerCache(Boolean attachListener, Boolean isEmpty, Boolean clone, Boolean enableDelta) throws Exception {
// for validation
updates = 0;
create = 0;
firstUpdate = null;
secondUpdate = null;
error = false;
Properties props = new Properties();
props.setProperty(DELTA_PROPAGATION, enableDelta.toString());
new ClientToServerDeltaDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.REPLICATE);
}
factory.setCloningEnabled(clone);
RegionAttributes attrs = factory.create();
region = cache.createRegion(REGION_NAME, attrs);
AttributesMutator am = region.getAttributesMutator();
if (attachListener) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
create++;
}
@Override
public void afterUpdate(EntryEvent event) {
switch(updates) {
case 0:
// first delta
validateUpdates(event, firstUpdate, "FIRST");
updates++;
break;
case 1:
// combine delta
validateUpdates(event, firstUpdate, "FIRST");
validateUpdates(event, secondUpdate, "SECOND");
updates++;
break;
default:
break;
}
}
});
} else if (!isEmpty) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
switch(create) {
case 1:
validateUpdates(event, firstUpdate, "FIRST");
create++;
break;
case 2:
validateUpdates(event, secondUpdate, "SECOND");
create++;
break;
default:
create++;
break;
}
}
});
}
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
// ensures updates to be sent instead of invalidations
server.setNotifyBySubscription(true);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class ClientRegionFactoryImpl method initAttributeFactoryDefaults.
private void initAttributeFactoryDefaults() {
this.attrsFactory.setScope(Scope.LOCAL);
this.attrsFactory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
// this.attrsFactory.setIgnoreJTA(true); in 6.6 and later releases client regions support JTA
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testREPLICATE_HEAP_LRU.
@Test
public void testREPLICATE_HEAP_LRU() throws Exception, IOException {
CacheCreation cache = new CacheCreation();
RegionCreation root = (RegionCreation) cache.createRegion("replicatelru", "REPLICATE_HEAP_LRU");
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
Region r = c.getRegion("replicatelru");
assertNotNull(r);
RegionAttributes ra = r.getAttributes();
assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope());
assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes());
assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class CachedAllEventsDUnitTest method remoteCreate.
/**
* make sure a remote create will be done in a NORMAL+ALL region
*
* @param rmtCreate is true if create should happen in remote region
*/
private void remoteCreate(DataPolicy dp, InterestPolicy ip, boolean rmtCreate) throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(dp);
af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
af.setScope(Scope.DISTRIBUTED_ACK);
Region r1 = createRootRegion("r1", af.create());
assertEquals(false, r1.containsKey("key"));
doCreateOtherVm();
if (rmtCreate) {
assertEquals(true, r1.containsKey("key"));
assertEquals("value", r1.getEntry("key").getValue());
} else {
assertEquals(false, r1.containsKey("key"));
}
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testPreloadDataPolicy.
@Test
public void testPreloadDataPolicy() throws Exception {
CacheCreation cache = new CacheCreation();
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
cache.createRegion("rootNORMAL", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
cache.createRegion("rootNORMAL_ALL", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setMirrorType(MirrorType.KEYS_VALUES);
cache.createRegion("rootREPLICATE", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
cache.createRegion("rootPERSISTENT_REPLICATE", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.EMPTY);
cache.createRegion("rootEMPTY", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.EMPTY);
attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
cache.createRegion("rootEMPTY_ALL", attrs);
}
{
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.PRELOADED);
attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
cache.createRegion("rootPRELOADED_ALL", attrs);
}
testXml(cache);
}
Aggregations