use of org.apache.geode.cache.MembershipAttributes in project geode by apache.
the class RegionReliabilityTestCase method testReinitialization.
@Test
public void testReinitialization() throws Exception {
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);
getCache();
// create region in controller...
MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.REINITIALIZE);
AttributesFactory fac = new AttributesFactory();
fac.setMembershipAttributes(ra);
fac.setScope(getRegionScope());
fac.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attr = fac.create();
Region region = createRootRegion(name, attr);
assertTrue(((AbstractRegion) region).requiresReliabilityCheck());
assertFalse(RequiredRoles.checkForRequiredRoles(region).isEmpty());
final String key = "KEY-testReinitialization";
final String val = "VALUE-testReinitialization";
Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("Create Data") {
public void run2() throws CacheException {
createConnection(new String[] {});
AttributesFactory fac = new AttributesFactory();
fac.setScope(getRegionScope());
fac.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attr = fac.create();
Region region = createRootRegion(name, attr);
region.put(key, val);
}
});
final Region finalRegion = region;
Thread thread = new Thread(new Runnable() {
public void run() {
try {
RequiredRoles.waitForRequiredRoles(finalRegion, -1);
} catch (InterruptedException e) {
fail("interrupted");
} catch (RegionReinitializedException e) {
}
}
});
thread.start();
// create role and verify reinitialization took place
Host.getHost(0).getVM(1).invokeAsync(new CacheSerializableRunnable("Create Role") {
public void run2() throws CacheException {
createConnection(new String[] { roleA });
AttributesFactory fac = new AttributesFactory();
fac.setScope(getRegionScope());
RegionAttributes attr = fac.create();
createRootRegion(name, attr);
}
});
ThreadUtils.join(thread, 30 * 1000);
assertTrue(region.isDestroyed());
try {
region.put("fee", "fi");
fail("Should have thrown RegionReinitializedException");
} catch (RegionReinitializedException e) {
// pass
}
try {
RequiredRoles.checkForRequiredRoles(region);
fail("Should have thrown RegionReinitializedException");
} catch (RegionReinitializedException e) {
// pass
}
try {
Role role = (Role) requiredRolesSet.iterator().next();
RequiredRoles.isRoleInRegionMembership(region, role);
fail("Should have thrown RegionReinitializedException");
} catch (RegionReinitializedException e) {
// pass
}
region = getRootRegion(name);
assertNotNull(region);
assertTrue(((AbstractRegion) region).requiresReliabilityCheck());
assertTrue(RequiredRoles.checkForRequiredRoles(region).isEmpty());
assertNotNull(region.getEntry(key));
assertEquals(val, region.getEntry(key).getValue());
}
use of org.apache.geode.cache.MembershipAttributes in project geode by apache.
the class DistributedRegion method isNoDistributionOk.
/**
* Called when we do a distributed operation and don't have anyone to distributed it too. Since
* this is only called when no distribution was done (i.e. no recipients) we do not check
* isMissingRequiredRoles because it might not longer be true due to race conditions
*
* @return false if this region has at least one required role and queuing is configured. Returns
* true if sending to no one is ok.
* @throws RoleException if a required role is missing and the LossAction is either NO_ACCESS or
* LIMITED_ACCESS.
* @since GemFire 5.0
*/
boolean isNoDistributionOk() {
if (this.requiresReliabilityCheck) {
MembershipAttributes ra = getMembershipAttributes();
Set<Role> failedRoles = ra.getRequiredRoles();
throw new RegionDistributionException(LocalizedStrings.DistributedRegion_OPERATION_DISTRIBUTION_WAS_NOT_DONE_TO_THESE_REQUIRED_ROLES_0.toLocalizedString(failedRoles), getFullPath(), failedRoles);
}
return true;
}
use of org.apache.geode.cache.MembershipAttributes in project geode by apache.
the class DistributedRegion method handleReliableDistribution.
private void handleReliableDistribution(Set successfulRecipients, Set otherRecipients1, Set otherRecipients2) {
if (this.requiresReliabilityCheck) {
MembershipAttributes ra = getMembershipAttributes();
// determine the successful roles
Set roles = new HashSet();
for (Object successfulRecipient : successfulRecipients) {
InternalDistributedMember mbr = (InternalDistributedMember) successfulRecipient;
if (mbr != null) {
roles.addAll(mbr.getRoles());
}
}
for (Object anOtherRecipients1 : otherRecipients1) {
InternalDistributedMember mbr = (InternalDistributedMember) anOtherRecipients1;
if (mbr != null) {
roles.addAll(mbr.getRoles());
}
}
for (Object anOtherRecipients2 : otherRecipients2) {
InternalDistributedMember mbr = (InternalDistributedMember) anOtherRecipients2;
if (mbr != null) {
roles.addAll(mbr.getRoles());
}
}
// determine the missing roles
Set failedRoles = new HashSet(ra.getRequiredRoles());
failedRoles.removeAll(roles);
if (failedRoles.isEmpty()) {
return;
}
throw new RegionDistributionException(LocalizedStrings.DistributedRegion_OPERATION_DISTRIBUTION_MAY_HAVE_FAILED_TO_NOTIFY_THESE_REQUIRED_ROLES_0.toLocalizedString(failedRoles), getFullPath(), failedRoles);
}
}
use of org.apache.geode.cache.MembershipAttributes in project geode by apache.
the class RequiredRolesDUnitTest method testRequiredRolesInLoss.
/**
* Tests that RequiredRoles detects missing roles.
*/
@Test
public void testRequiredRolesInLoss() throws Exception {
String name = this.getUniqueName();
final String roleA = name + "-A";
final String roleC = name + "-C";
final String roleD = name + "-D";
// assign names to 4 vms...
final String[] requiredRoles = { roleA, roleC, roleD };
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);
// create region in controller...
MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.FULL_ACCESS, ResumptionAction.NONE);
AttributesFactory fac = new AttributesFactory();
fac.setMembershipAttributes(ra);
fac.setScope(Scope.DISTRIBUTED_ACK);
RegionAttributes attr = fac.create();
Region region = createRootRegion(name, attr);
RegionAttributes rattr = region.getAttributes();
assertEquals(true, rattr.getMembershipAttributes().hasRequiredRoles());
Set roles = rattr.getMembershipAttributes().getRequiredRoles();
assertNotNull(roles);
assertEquals(false, roles.isEmpty());
assertEquals(requiredRolesSet.size(), roles.size());
assertEquals(true, roles.containsAll(requiredRolesSet));
// wait for memberTimeout to expire
waitForMemberTimeout();
// assert all are missing according to RequiredRoles...
Set missingRoles = RequiredRoles.checkForRequiredRoles(region);
assertNotNull(missingRoles);
assertEquals(requiredRolesSet.size(), missingRoles.size());
assertEquals(true, missingRoles.containsAll(requiredRolesSet));
// assert isPresent is false on each missing role...
for (Iterator iter = missingRoles.iterator(); iter.hasNext(); ) {
Role role = (Role) iter.next();
assertEquals(false, role.isPresent());
}
}
Aggregations