Search in sources :

Example 1 with MembershipAttributes

use of org.apache.geode.cache.MembershipAttributes in project geode by apache.

the class RegionMBeanCompositeDataFactory method getMembershipAttributesData.

public static MembershipAttributesData getMembershipAttributesData(RegionAttributes regAttrs) {
    MembershipAttributes memAttrs = regAttrs.getMembershipAttributes();
    Set<String> requiredRoles = new HashSet<String>();
    Iterator<Role> it = memAttrs.getRequiredRoles().iterator();
    while (it.hasNext()) {
        requiredRoles.add(it.next().getName());
    }
    String lossAction = memAttrs.getLossAction().toString();
    String resumptionAction = memAttrs.getResumptionAction().toString();
    MembershipAttributesData membershipAttributesData = new MembershipAttributesData(requiredRoles, lossAction, resumptionAction);
    return membershipAttributesData;
}
Also used : Role(org.apache.geode.distributed.Role) MembershipAttributesData(org.apache.geode.management.MembershipAttributesData) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) HashSet(java.util.HashSet)

Example 2 with MembershipAttributes

use of org.apache.geode.cache.MembershipAttributes in project geode by apache.

the class CacheXmlGenerator method generate.

/**
   * Generates XML for region attributes.
   *
   * @param id The id of the named region attributes (may be <code>null</code>)
   */
private void generate(String id, RegionAttributes attrs) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    if (id != null) {
        atts.addAttribute("", "", ID, "", id);
    }
    // point, the refid information is lost.
    if (attrs instanceof RegionAttributesCreation) {
        String refId = ((RegionAttributesCreation) attrs).getRefid();
        if (refId != null) {
            atts.addAttribute("", "", REFID, "", refId);
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasScope())) {
        String scopeString;
        Scope scope = attrs.getScope();
        if (scope.equals(Scope.LOCAL)) {
            scopeString = LOCAL;
        } else if (scope.equals(Scope.DISTRIBUTED_NO_ACK)) {
            scopeString = DISTRIBUTED_NO_ACK;
        } else if (scope.equals(Scope.DISTRIBUTED_ACK)) {
            scopeString = DISTRIBUTED_ACK;
        } else if (scope.equals(Scope.GLOBAL)) {
            scopeString = GLOBAL;
        } else {
            throw new InternalGemFireException(LocalizedStrings.CacheXmlGenerator_UNKNOWN_SCOPE_0.toLocalizedString(scope));
        }
        final boolean isPartitionedRegion;
        if (attrs instanceof RegionAttributesCreation) {
            RegionAttributesCreation rac = (RegionAttributesCreation) attrs;
            isPartitionedRegion = rac.getPartitionAttributes() != null || (rac.hasDataPolicy() && rac.getDataPolicy().withPartitioning());
        } else {
            isPartitionedRegion = attrs.getPartitionAttributes() != null || attrs.getDataPolicy().withPartitioning();
        }
        if (!isPartitionedRegion) {
            // Partitioned Region don't support setting scope
            if (generateDefaults() || !scope.equals(AbstractRegion.DEFAULT_SCOPE))
                atts.addAttribute("", "", SCOPE, "", scopeString);
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEarlyAck())) {
        if (generateDefaults() || attrs.getEarlyAck())
            atts.addAttribute("", "", EARLY_ACK, "", String.valueOf(attrs.getEarlyAck()));
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasMulticastEnabled())) {
        if (generateDefaults() || attrs.getMulticastEnabled())
            atts.addAttribute("", "", MULTICAST_ENABLED, "", String.valueOf(attrs.getMulticastEnabled()));
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPublisher())) {
        if (generateDefaults() || attrs.getPublisher())
            atts.addAttribute("", "", PUBLISHER, "", String.valueOf(attrs.getPublisher()));
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEnableAsyncConflation())) {
        if (generateDefaults() || attrs.getEnableAsyncConflation())
            atts.addAttribute("", "", ENABLE_ASYNC_CONFLATION, "", String.valueOf(attrs.getEnableAsyncConflation()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEnableSubscriptionConflation())) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
                // starting with 5.7 it is enable-subscription-conflation
                if (generateDefaults() || attrs.getEnableSubscriptionConflation())
                    atts.addAttribute("", "", ENABLE_SUBSCRIPTION_CONFLATION, "", String.valueOf(attrs.getEnableSubscriptionConflation()));
            } else {
                // before 5.7 it was enable-bridge-conflation
                if (generateDefaults() || attrs.getEnableSubscriptionConflation())
                    atts.addAttribute("", "", ENABLE_BRIDGE_CONFLATION, "", String.valueOf(attrs.getEnableSubscriptionConflation()));
            }
        }
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDataPolicy())) {
            String dpString;
            DataPolicy dp = attrs.getDataPolicy();
            if (dp.isEmpty()) {
                dpString = EMPTY_DP;
            } else if (dp.isNormal()) {
                dpString = NORMAL_DP;
            } else if (dp.isPreloaded()) {
                dpString = PRELOADED_DP;
            } else if (dp.isReplicate()) {
                dpString = REPLICATE_DP;
            } else if (dp == DataPolicy.PERSISTENT_REPLICATE) {
                dpString = PERSISTENT_REPLICATE_DP;
            } else if (dp == DataPolicy.PERSISTENT_PARTITION) {
                dpString = PERSISTENT_PARTITION_DP;
            } else if (dp.isPartition()) {
                if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
                    dpString = PARTITION_DP;
                } else {
                    // prior to 5.1 the data policy for partitioned regions was EMPTY
                    dpString = EMPTY_DP;
                }
            } else {
                throw new InternalGemFireException(LocalizedStrings.CacheXmlGenerator_UNKNOWN_DATA_POLICY_0.toLocalizedString(dp));
            }
            if (generateDefaults() || !dp.equals(DataPolicy.DEFAULT))
                atts.addAttribute("", "", DATA_POLICY, "", dpString);
        }
    // hasDataPolicy
    } else // GEMFIRE_5_0 >= 0
    {
        // GEMFIRE_5_0 < 0
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEnableSubscriptionConflation())) {
            if (generateDefaults() || attrs.getEnableSubscriptionConflation())
                atts.addAttribute("", "", "enable-conflation", "", String.valueOf(attrs.getEnableSubscriptionConflation()));
        }
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasMirrorType())) {
            String mirrorString;
            MirrorType mirror = attrs.getMirrorType();
            if (mirror.equals(MirrorType.NONE))
                mirrorString = NONE;
            else if (mirror.equals(MirrorType.KEYS))
                mirrorString = KEYS;
            else if (mirror.equals(MirrorType.KEYS_VALUES))
                mirrorString = KEYS_VALUES;
            else
                throw new InternalGemFireException(LocalizedStrings.CacheXmlGenerator_UNKNOWN_MIRROR_TYPE_0.toLocalizedString(mirror));
            atts.addAttribute("", "", MIRROR_TYPE, "", mirrorString);
        }
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPersistBackup())) {
            atts.addAttribute("", "", PERSIST_BACKUP, "", String.valueOf(attrs.getDataPolicy() == DataPolicy.PERSISTENT_REPLICATE));
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasInitialCapacity())) {
        if (generateDefaults() || attrs.getInitialCapacity() != 16)
            atts.addAttribute("", "", INITIAL_CAPACITY, "", String.valueOf(attrs.getInitialCapacity()));
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasLoadFactor())) {
        if (generateDefaults() || attrs.getLoadFactor() != 0.75f)
            atts.addAttribute("", "", LOAD_FACTOR, "", String.valueOf(attrs.getLoadFactor()));
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasConcurrencyLevel())) {
        if (generateDefaults() || attrs.getConcurrencyLevel() != 16)
            atts.addAttribute("", "", CONCURRENCY_LEVEL, "", String.valueOf(attrs.getConcurrencyLevel()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasConcurrencyChecksEnabled())) {
            if (generateDefaults() || attrs.getConcurrencyChecksEnabled() != true)
                /* fixes bug 46654 */
                atts.addAttribute("", "", CONCURRENCY_CHECKS_ENABLED, "", String.valueOf(attrs.getConcurrencyChecksEnabled()));
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasStatisticsEnabled())) {
        if (generateDefaults() || attrs.getStatisticsEnabled())
            atts.addAttribute("", "", STATISTICS_ENABLED, "", String.valueOf(attrs.getStatisticsEnabled()));
    }
    if (!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasIgnoreJTA()) {
        if (generateDefaults() || attrs.getIgnoreJTA())
            atts.addAttribute("", "", IGNORE_JTA, "", String.valueOf(attrs.getIgnoreJTA()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasIsLockGrantor())) {
            if (generateDefaults() || attrs.isLockGrantor())
                atts.addAttribute("", "", IS_LOCK_GRANTOR, "", String.valueOf(attrs.isLockGrantor()));
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPoolName())) {
            String cpVal = attrs.getPoolName();
            if (cpVal == null) {
                cpVal = "";
            }
            if (generateDefaults() || !cpVal.equals(""))
                atts.addAttribute("", "", POOL_NAME, "", cpVal);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskStoreName())) {
            String dsVal = attrs.getDiskStoreName();
            if (dsVal != null) {
                atts.addAttribute("", "", DISK_STORE_NAME, "", dsVal);
            }
        }
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskSynchronous())) {
            if (generateDefaults() || attrs.isDiskSynchronous() != AttributesFactory.DEFAULT_DISK_SYNCHRONOUS)
                atts.addAttribute("", "", DISK_SYNCHRONOUS, "", String.valueOf(attrs.isDiskSynchronous()));
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0)
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCloningEnabled())) {
            if (generateDefaults() || attrs.getCloningEnabled())
                atts.addAttribute("", "", CLONING_ENABLED, "", String.valueOf(attrs.getCloningEnabled()));
        }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasGatewaySenderId())) {
            Set<String> senderIds = new HashSet<String>(attrs.getGatewaySenderIds());
            StringBuilder senderStringBuff = new StringBuilder();
            if (senderIds != null && senderIds.size() != 0) {
                for (String senderId : senderIds) {
                    if (!(senderStringBuff.length() == 0)) {
                        senderStringBuff.append(",");
                    }
                    senderStringBuff.append(senderId);
                }
            }
            if (generateDefaults() || senderStringBuff.length() > 0)
                atts.addAttribute("", "", GATEWAY_SENDER_IDS, "", senderStringBuff.toString());
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasAsyncEventListeners())) {
            Set<String> asyncEventQueueIds = new HashSet<String>(attrs.getAsyncEventQueueIds());
            StringBuilder asyncEventQueueStringBuff = new StringBuilder();
            if (asyncEventQueueIds != null && asyncEventQueueIds.size() != 0) {
                for (String asyncEventQueueId : asyncEventQueueIds) {
                    if (!(asyncEventQueueStringBuff.length() == 0)) {
                        asyncEventQueueStringBuff.append(",");
                    }
                    asyncEventQueueStringBuff.append(asyncEventQueueId);
                }
            }
            if (generateDefaults() || asyncEventQueueStringBuff.length() > 0)
                atts.addAttribute("", "", ASYNC_EVENT_QUEUE_IDS, "", asyncEventQueueStringBuff.toString());
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasOffHeap())) {
            if (generateDefaults() || attrs.getOffHeap()) {
                atts.addAttribute("", "", OFF_HEAP, "", String.valueOf(attrs.getOffHeap()));
            }
        }
    }
    handler.startElement("", REGION_ATTRIBUTES, REGION_ATTRIBUTES, atts);
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasKeyConstraint())) {
        generate(attrs.getKeyConstraint(), KEY_CONSTRAINT);
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasValueConstraint())) {
        generate(attrs.getValueConstraint(), VALUE_CONSTRAINT);
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasRegionTimeToLive())) {
        if (generateDefaults() || !attrs.getRegionTimeToLive().equals(ExpirationAttributes.DEFAULT))
            generate(REGION_TIME_TO_LIVE, attrs.getRegionTimeToLive(), null);
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasRegionIdleTimeout())) {
        if (generateDefaults() || !attrs.getRegionIdleTimeout().equals(ExpirationAttributes.DEFAULT))
            generate(REGION_IDLE_TIME, attrs.getRegionIdleTimeout(), null);
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEntryTimeToLive() || ((RegionAttributesCreation) attrs).hasCustomEntryTimeToLive())) {
        if (generateDefaults() || !attrs.getEntryTimeToLive().equals(ExpirationAttributes.DEFAULT) || attrs.getCustomEntryTimeToLive() != null)
            generate(ENTRY_TIME_TO_LIVE, attrs.getEntryTimeToLive(), attrs.getCustomEntryTimeToLive());
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEntryIdleTimeout() || ((RegionAttributesCreation) attrs).hasCustomEntryIdleTimeout())) {
        if (generateDefaults() || !attrs.getEntryIdleTimeout().equals(ExpirationAttributes.DEFAULT) || attrs.getCustomEntryIdleTimeout() != null)
            generate(ENTRY_IDLE_TIME, attrs.getEntryIdleTimeout(), attrs.getCustomEntryIdleTimeout());
    }
    if (attrs.getDiskStoreName() == null && (generateDefaults() || this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) < 0)) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskWriteAttributes())) {
            generate(attrs.getDiskWriteAttributes());
        }
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskDirs())) {
            File[] diskDirs = attrs.getDiskDirs();
            int[] diskSizes = attrs.getDiskDirSizes();
            if (diskDirs != null && diskDirs.length > 0) {
                handler.startElement("", DISK_DIRS, DISK_DIRS, EMPTY);
                for (int i = 0; i < diskDirs.length; i++) {
                    AttributesImpl diskAtts = new AttributesImpl();
                    if (diskSizes[i] != DiskStoreFactory.DEFAULT_DISK_DIR_SIZE) {
                        diskAtts.addAttribute("", "", DIR_SIZE, "", String.valueOf(diskSizes[i]));
                    }
                    handler.startElement("", DISK_DIR, DISK_DIR, diskAtts);
                    File dir = diskDirs[i];
                    String name = generateDefaults() ? dir.getAbsolutePath() : dir.getPath();
                    handler.characters(name.toCharArray(), 0, name.length());
                    handler.endElement("", DISK_DIR, DISK_DIR);
                }
                handler.endElement("", DISK_DIRS, DISK_DIRS);
            }
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPartitionAttributes())) {
            PartitionAttributes p = attrs.getPartitionAttributes();
            if (p != null) {
                generate(p);
            }
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) {
        MembershipAttributes p = attrs.getMembershipAttributes();
        if (p != null && p.hasRequiredRoles()) {
            generate(p);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasSubscriptionAttributes())) {
            SubscriptionAttributes sa = attrs.getSubscriptionAttributes();
            if (sa != null) {
                if (generateDefaults() || !sa.equals(new SubscriptionAttributes()))
                    generate(sa);
            }
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCacheLoader())) {
        generate(CACHE_LOADER, attrs.getCacheLoader());
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCacheWriter())) {
        generate(CACHE_WRITER, attrs.getCacheWriter());
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCacheListeners())) {
        CacheListener[] listeners = attrs.getCacheListeners();
        for (int i = 0; i < listeners.length; i++) {
            generate(CACHE_LISTENER, listeners[i]);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) {
        if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCompressor())) {
            generate(COMPRESSOR, attrs.getCompressor());
        }
    }
    if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEvictionAttributes())) {
        generate(attrs.getEvictionAttributes());
    }
    handler.endElement("", REGION_ATTRIBUTES, REGION_ATTRIBUTES);
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) CacheListener(org.apache.geode.cache.CacheListener) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Scope(org.apache.geode.cache.Scope) MirrorType(org.apache.geode.cache.MirrorType) DataPolicy(org.apache.geode.cache.DataPolicy) File(java.io.File) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 3 with MembershipAttributes

use of org.apache.geode.cache.MembershipAttributes in project geode by apache.

the class CacheXmlParser method endMembershipAttributes.

/**
   * When a <code>membership-attributes</code> element is finished, the arguments for constructing
   * the MembershipAttributes are on the stack.
   */
private void endMembershipAttributes() {
    Set roles = new HashSet();
    Object obj = null;
    while (!(obj instanceof Object[])) {
        obj = stack.pop();
        if (obj instanceof String) {
            // found a required-role name
            roles.add(obj);
        }
    }
    Object[] attrs = (Object[]) obj;
    String laName = ((String) attrs[0]).toUpperCase().replace('-', '_');
    String raName = ((String) attrs[1]).toUpperCase().replace('-', '_');
    LossAction laction = LossAction.fromName(laName);
    ResumptionAction raction = ResumptionAction.fromName(raName);
    MembershipAttributes ra = new MembershipAttributes((String[]) roles.toArray(new String[roles.size()]), laction, raction);
    RegionAttributesCreation rattrs = (RegionAttributesCreation) stack.peek();
    rattrs.setMembershipAttributes(ra);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LossAction(org.apache.geode.cache.LossAction) ResumptionAction(org.apache.geode.cache.ResumptionAction) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes)

Example 4 with MembershipAttributes

use of org.apache.geode.cache.MembershipAttributes in project geode by apache.

the class RegionReliabilityTestCase method testCommitDistributionException.

@Test
public void testCommitDistributionException() throws Exception {
    if (getRegionScope().isGlobal())
        // skip test under Global
        return;
    if (getRegionScope().isDistributedNoAck())
        // skip test under DistributedNoAck
        return;
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
    RegionMembershipListener listener = new RegionMembershipListenerAdapter() {

        public void afterRemoteRegionDeparture(RegionEvent event) {
            synchronized (detectedDeparture_testCommitDistributionException) {
                detectedDeparture_testCommitDistributionException[0] = Boolean.TRUE;
                detectedDeparture_testCommitDistributionException.notify();
            }
        }
    };
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.addCacheListener(listener);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    // use vm1 to create role
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    // define the afterReleaseLocalLocks callback
    SerializableRunnableIF removeRequiredRole = new SerializableRunnableIF() {

        public void run() {
            Host.getHost(0).getVM(1).invoke(new SerializableRunnable("Close Region") {

                public void run() {
                    getRootRegion(name).close();
                }
            });
            try {
                synchronized (detectedDeparture_testCommitDistributionException) {
                    while (detectedDeparture_testCommitDistributionException[0] == Boolean.FALSE) {
                        detectedDeparture_testCommitDistributionException.wait();
                    }
                }
            } catch (InterruptedException e) {
                fail("interrupted");
            }
        }
    };
    // define the add and remove expected exceptions
    final String expectedExceptions = "org.apache.geode.internal.cache.CommitReplyException";
    SerializableRunnable addExpectedExceptions = new CacheSerializableRunnable("addExpectedExceptions") {

        public void run2() throws CacheException {
            getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
        }
    };
    SerializableRunnable removeExpectedExceptions = new CacheSerializableRunnable("removeExpectedExceptions") {

        public void run2() throws CacheException {
            getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
        }
    };
    // perform the actual test...
    CacheTransactionManager ctm = cache.getCacheTransactionManager();
    ctm.begin();
    TXStateInterface txStateProxy = ((TXManagerImpl) ctm).getTXState();
    ((TXStateProxyImpl) txStateProxy).forceLocalBootstrap();
    TXState txState = (TXState) ((TXStateProxyImpl) txStateProxy).getRealDeal(null, null);
    txState.setBeforeSend(() -> {
        try {
            removeRequiredRole.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    // now start a transaction and commit it
    region.put("KEY", "VAL");
    addExpectedExceptions.run();
    Host.getHost(0).getVM(1).invoke(addExpectedExceptions);
    try {
        ctm.commit();
        fail("Should have thrown CommitDistributionException");
    } catch (CommitDistributionException e) {
    // pass
    } finally {
        removeExpectedExceptions.run();
        Host.getHost(0).getVM(1).invoke(removeExpectedExceptions);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent) SerializableRunnableIF(org.apache.geode.test.dunit.SerializableRunnableIF) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TXState(org.apache.geode.internal.cache.TXState) AttributesFactory(org.apache.geode.cache.AttributesFactory) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RegionMembershipListener(org.apache.geode.cache.RegionMembershipListener) TXStateInterface(org.apache.geode.internal.cache.TXStateInterface) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) RegionAccessException(org.apache.geode.cache.RegionAccessException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheException(org.apache.geode.cache.CacheException) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionMembershipListenerAdapter(org.apache.geode.cache.util.RegionMembershipListenerAdapter) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 5 with MembershipAttributes

use of org.apache.geode.cache.MembershipAttributes in project geode by apache.

the class RegionReliabilityTestCase method testLimitedAccessWithLocalEntryExpiration.

/**
   * Tests affect of LIMITED_ACCESS on local entry expiration actions.
   */
@Test
public void testLimitedAccessWithLocalEntryExpiration() throws Exception {
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    // assign names to 4 vms...
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    getCache();
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.LIMITED_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.setStatisticsEnabled(true);
    RegionAttributes attr = fac.create();
    final Region region = createExpiryRootRegion(name, attr);
    // wait for memberTimeout to expire
    waitForMemberTimeout();
    // use vm1 to create role
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    // test to make sure expiration is suspended
    region.put("expireMe", "expireMe");
    assertTrue(region.size() == 1);
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Close Region") {

        public void run2() throws CacheException {
            Region region = getRootRegion(name);
            region.close();
        }
    });
    // TODO: waitForMemberTimeout(); ?
    // set expiration and sleep
    AttributesMutator mutator = region.getAttributesMutator();
    mutator.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
    WaitCriterion wc1 = new WaitCriterion() {

        public boolean done() {
            return ((LocalRegion) region).basicEntries(false).size() == 0;
        }

        public String description() {
            return "expected zero entries but have " + ((LocalRegion) region).basicEntries(false).size();
        }
    };
    Wait.waitForCriterion(wc1, 30 * 1000, 10, true);
    // create region again
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    region.put("expireMe", "expireMe");
    waitForEntryDestroy(region, "expireMe");
    assertTrue(region.size() == 0);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

MembershipAttributes (org.apache.geode.cache.MembershipAttributes)24 HashSet (java.util.HashSet)18 Properties (java.util.Properties)18 RegionAttributes (org.apache.geode.cache.RegionAttributes)18 Test (org.junit.Test)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)17 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)17 Set (java.util.Set)16 Region (org.apache.geode.cache.Region)16 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)12 LocalRegion (org.apache.geode.internal.cache.LocalRegion)12 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 CacheException (org.apache.geode.cache.CacheException)9 Role (org.apache.geode.distributed.Role)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 AttributesMutator (org.apache.geode.cache.AttributesMutator)6 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)6 InternalRole (org.apache.geode.distributed.internal.membership.InternalRole)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 RegionDistributionException (org.apache.geode.cache.RegionDistributionException)4