Java Code Examples for com.gemstone.gemfire.cache.Region#keySet()

The following examples show how to use com.gemstone.gemfire.cache.Region#keySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionEntryOperations.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void invokeRegionEntryInvalidate() {

    int noOfEntity = conftab.intAt(RecyclePrms.numberOfEntitiesInRegion, 0);

    Cache cache = CacheFactory.getInstance(DistributedSystemHelper
        .getDistributedSystem());
    Object[] regionList = cache.rootRegions().toArray();
    int numRegs = regionList.length;

    for (int i = 0; i < numRegs; i++) {
      Region reg = (Region)regionList[i];
      if (!(reg instanceof HARegion)) {
        Set keys = reg.keySet();
        Iterator ite = keys.iterator();
        for (int j = 0; ite.hasNext() && j < noOfEntity; j++) {
          Object key = ite.next();
          reg.invalidate(key);
        }
      }
    }
  }
 
Example 2
Source File: OffHeapStressTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/** Write a snapshot of all regions
 * 
 */
private static void writeSnapshot() {
  Set<Region<?, ?>> allRegions = getAllRegions();
  Log.getLogWriter().info("Preparing to write snapshot for " + allRegions.size() + " regions");
  Map<String, Map> allRegionsSnapshot = new HashMap<String, Map>();
  for (Region aRegion: allRegions) {
    Map regionSnapshot = new HashMap();
    for (Object key: aRegion.keySet()) {
      Object value = null;
      if (aRegion.containsValueForKey(key)) { // won't invoke a loader (if any)
        value = aRegion.get(key);
      }
      byte[] byteArr = (byte[]) value;
      regionSnapshot.put(key, byteArr.length);
    }
    allRegionsSnapshot.put(aRegion.getFullPath(), regionSnapshot);
    Log.getLogWriter().info("Region snapshot for " + aRegion.getFullPath() + " is size " + regionSnapshot.size() + " and contains keys " + regionSnapshot.keySet());
  }
  RecoveryBB.getBB().getSharedMap().put(allRegionsSnapshotKey, allRegionsSnapshot);
  Log.getLogWriter().info("Put snapshot for " + allRegions.size() + " regions into blackboard at key " + allRegionsSnapshotKey);
}
 
Example 3
Source File: OffHeapStressTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/** Write a snapshot of all regions
 * 
 */
private static void writeSnapshot() {
  Set<Region<?, ?>> allRegions = getAllRegions();
  Log.getLogWriter().info("Preparing to write snapshot for " + allRegions.size() + " regions");
  Map<String, Map> allRegionsSnapshot = new HashMap<String, Map>();
  for (Region aRegion: allRegions) {
    Map regionSnapshot = new HashMap();
    for (Object key: aRegion.keySet()) {
      Object value = null;
      if (aRegion.containsValueForKey(key)) { // won't invoke a loader (if any)
        value = aRegion.get(key);
      }
      byte[] byteArr = (byte[]) value;
      regionSnapshot.put(key, byteArr.length);
    }
    allRegionsSnapshot.put(aRegion.getFullPath(), regionSnapshot);
    Log.getLogWriter().info("Region snapshot for " + aRegion.getFullPath() + " is size " + regionSnapshot.size() + " and contains keys " + regionSnapshot.keySet());
  }
  RecoveryBB.getBB().getSharedMap().put(allRegionsSnapshotKey, allRegionsSnapshot);
  Log.getLogWriter().info("Put snapshot for " + allRegions.size() + " regions into blackboard at key " + allRegionsSnapshotKey);
}
 
Example 4
Source File: RecycleSystem.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void getKeys()
{
        Cache cache = CacheFactory.getInstance(DistributedSystemHelper.getDistributedSystem());
        Object [] regionList = cache.rootRegions().toArray();
        logger.info("RecycleSystem:getKeys:: cache" + cache);
        int numRegs = regionList.length;
        
                for(int i =0 ; i < numRegs; i++)
                {
                        Region reg = (Region)regionList[i];
                        if (!(reg instanceof HARegion) ) {
                           Set keys = reg.keySet();
                           logger.info("RecycleSystem:getKeys:: number of keys in  "+ reg.getFullPath() + " is  " + keys.size());
                           for (Iterator iter=keys.iterator(); iter.hasNext() ;) {
                             Object key = iter.next();
                             Object value = reg.get(key);
                             logger.info("RecycleSystem:getKeys:: value for" + key+" is "+value);
                           }
                        }
                }
                 
        int sleepSecs = restart();
    try { Thread.sleep(sleepSecs*1000); } catch(Exception e) { }
}
 
Example 5
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Checking for the security wan sites whether they have received keys not
 * valid to them
 */

public static void checkInvalidKeys(String validKey) {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set keys = region.keySet();

  Iterator iterator = keys.iterator();
  while (iterator.hasNext()) {
    String key = (String)(iterator.next());
    if (!key.startsWith(validKey)) {
      throw new TestException("Invalid key found in the cache " + key);
    }
    else {
      Log.getLogWriter().info("Found valid key " + key);
    }
  }

}
 
Example 6
Source File: QueryFunctionExecTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Read object
 */
@Override
protected void readObject(Region aRegion) {
  Set aSet = aRegion.keySet();
  if (aSet.size() == 0) {
     Log.getLogWriter().info("readObject: No names in region");
     return;
  }
  Iterator it = aSet.iterator();
  Object key = null;
  if (it.hasNext()) {
    key = it.next();
  } else {
     Log.getLogWriter().info("readObject: Unable to get key from region");
     return; 
  }
  aRegion.get(key);
}
 
Example 7
Source File: QueryFunctionExecTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Destroy an entry
 * @param aRegion
 */
protected void destroyObject(Region aRegion) {
  Set aSet = aRegion.keySet();
  if (aSet.size() == 0) {
     Log.getLogWriter().info("destroyObject: No names in region");
     return;
  }
  Iterator it = aSet.iterator();
  Object key = null;
  if (it.hasNext()) {
    key = it.next();
  } else {
     Log.getLogWriter().info("destroyObject: Unable to get key from region");
     return; 
  }
  aRegion.destroy(key);
}
 
Example 8
Source File: RollingUpgradeTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Write snapshot of all the regions into BB
 *
 */
Map writeSnapshot() {
  Map allRegionsSnapshot = new HashMap();
  Set<Region<?,?>>  regions = CacheHelper.getCache().rootRegions();
  Log.getLogWriter().info("Preparing to write snapshot for " + regions.size() + " regions");
  for (Region aRegion: regions) {
    Map regionSnapshot = new HashMap();
    for (Object key: aRegion.keySet()) {
      Object value = null;
      if (aRegion.containsValueForKey(key)) { // won't invoke a loader (if any)
        value = aRegion.get(key);
      }
      if (value instanceof BaseValueHolder) {
        regionSnapshot.put(key, ((BaseValueHolder)value).myValue);
      } else {
        regionSnapshot.put(key, value);
      }
    }
    allRegionsSnapshot.put(aRegion.getFullPath(), regionSnapshot);
    Log.getLogWriter().info("Region snapshot for " + aRegion.getFullPath() + " is size " + regionSnapshot.size() + " and contains keys " + regionSnapshot.keySet());
  }
  RollingUpgradeBB.getBB().getSharedMap().put(allRegionsSnapshotKey, allRegionsSnapshot);
  Log.getLogWriter().info("Put snapshot for " + regions.size() + " regions into blackboard at key " + allRegionsSnapshotKey);
  
  return allRegionsSnapshot;
}
 
Example 9
Source File: RegionEntryOperations.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void invokeRegionEntryInvalidate() {

    int noOfEntity = conftab.intAt(RecyclePrms.numberOfEntitiesInRegion, 0);

    Cache cache = CacheFactory.getInstance(DistributedSystemHelper
        .getDistributedSystem());
    Object[] regionList = cache.rootRegions().toArray();
    int numRegs = regionList.length;

    for (int i = 0; i < numRegs; i++) {
      Region reg = (Region)regionList[i];
      if (!(reg instanceof HARegion)) {
        Set keys = reg.keySet();
        Iterator ite = keys.iterator();
        for (int j = 0; ite.hasNext() && j < noOfEntity; j++) {
          Object key = ite.next();
          reg.invalidate(key);
        }
      }
    }
  }
 
Example 10
Source File: ConcCQMultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * to invalidate the sameKey.
 * @param regionName - region name for the region to perform invalidation
 */
protected void invalidateSameKey(String regionName) {
  MasterController.sleepForMs(20000); //wait for a region to be populated
  Region region = RegionHelper.getRegion(regionName);
  int numOfInvalidateSameKey = 10;
  String key = null;
  if (region != null) {
    Set aSet = region.keySet();
    while (aSet == null) {
      aSet = region.keySet();
    }
    Iterator itr = aSet.iterator();
    if (itr.hasNext()) {
      key = (String)(itr.next());
    }
  }
  if (key != null) {
    for (int i=0; i<numOfInvalidateSameKey; i++) {
      Log.getLogWriter().info("the key to be invalidated is "+key);
      region.invalidate(key);
      MapBB.getBB().getSharedCounters().increment(MapBB.NUM_INVALIDATE);
      MasterController.sleepForMs(5000); //wait to invalidate the same key
    }
  }
}
 
Example 11
Source File: QueryFunctionExecTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Destroy an entry
 * @param aRegion
 */
protected void destroyObject(Region aRegion) {
  Set aSet = aRegion.keySet();
  if (aSet.size() == 0) {
     Log.getLogWriter().info("destroyObject: No names in region");
     return;
  }
  Iterator it = aSet.iterator();
  Object key = null;
  if (it.hasNext()) {
    key = it.next();
  } else {
     Log.getLogWriter().info("destroyObject: Unable to get key from region");
     return; 
  }
  aRegion.destroy(key);
}
 
Example 12
Source File: WANTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void validateRegionSize(String regionName, final int regionSize) {
  ExpectedException exp = addExpectedException(ForceReattemptException.class
      .getName());
  ExpectedException exp1 = addExpectedException(CacheClosedException.class
      .getName());
  try {

    final Region r = cache.getRegion(Region.SEPARATOR + regionName);
    assertNotNull(r);
    WaitCriterion wc = new WaitCriterion() {
      public boolean done() {
        if (r.keySet().size() == regionSize) {
          return true;
        }
        return false;
      }

      public String description() {
        return "Expected region entries: " + regionSize
            + " but actual entries: " + r.keySet().size()
            + " present region keyset " + r.keySet();
      }
    };
    DistributedTestCase.waitForCriterion(wc, 240000, 500, true);
  } finally {
    exp.remove();
    exp1.remove();
  }
}
 
Example 13
Source File: RecycleSystem.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void updateKeys()
{
	if (DistributedSystemHelper.getDistributedSystem() == null
       || CacheHelper.getCache() == null) {
     return;
   }
	Cache cache = CacheFactory.getInstance(DistributedSystemHelper.getDistributedSystem());
	Object [] regionList = cache.rootRegions().toArray();
	logger.info("RecycleSystem:updateKeys:: cache" + cache);
	int numRegs = regionList.length;
	
		for(int i =0 ; i < numRegs; i++)
		{
			Region reg = (Region)regionList[i];
                               if (!(reg instanceof HARegion) ) {
                                  Set keys = reg.keySet();
			   logger.info("RecycleSystem:updateKeys:: number of keys in  "+ reg.getFullPath() + " is  " + keys.size());
			   for (Iterator iter=keys.iterator(); iter.hasNext() ;) {
			     Object key = iter.next();
			     reg.put(key, key);
			     logger.info("RecycleSystem:updateKeys:: updated value for" + key);
			   }
                               }
		}
	
	GemFireMemberStatus status = new GemFireMemberStatus(cache);
		
	logger.info("RecycleSystem:updateKeys:: Status from the existing system " + status.toString());
	
	logger.info("RecycleSystem:updateKeys::" + InternalBridgeMembership.getClientQueueSizes());
	
	int sleepSecs = restart();
    try { Thread.sleep(sleepSecs*1000); } catch(Exception e) { }
}
 
Example 14
Source File: EntryOperations.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void putKeysInBB() {
  Region region = RegionHelper.getRegion(regionName);
  HashSet keySet = new HashSet(region.keySet());
  if (SecurityClientBB.getBB().getSharedMap().get(KEY_SET) == null) {
    SecurityClientBB.getBB().getSharedMap().put(KEY_SET, keySet);
  }
}
 
Example 15
Source File: SnapshotTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Record the region snapshot to the BB
 *
 */
void writeSnapshot() {

  Log.getLogWriter().info("Preparing to write snapshot for " + allRegions.size() + " regions");
  Map allRegionsSnapshot = new HashMap();
  for (Region aRegion: allRegions) {
    Map regionSnapshot = new HashMap();
    for (Object key: aRegion.keySet()) {
      Object value = null;
      if (aRegion.containsValueForKey(key)) { // won't invoke a loader (if any)
        value = aRegion.get(key);
      }
      if (value instanceof BaseValueHolder) {
        regionSnapshot.put(key, ((BaseValueHolder)value).myValue);
      } else if (instanceOfPdxInstance(value)) {
        BaseValueHolder vh = toValueHolder(value);
        regionSnapshot.put(key, vh.myValue);
      } else {
        regionSnapshot.put(key, value);
      }
    }
    allRegionsSnapshot.put(aRegion.getFullPath(), regionSnapshot);
    Log.getLogWriter().info("Region snapshot for " + aRegion.getFullPath() + " is size " + regionSnapshot.size() + " and contains keys " + regionSnapshot.keySet());
  } 
  SnapshotBB.getBB().getSharedMap().put(allRegionsSnapshotKey, allRegionsSnapshot);
  Log.getLogWriter().info("Put snapshot for " + allRegions.size() + " regions into blackboard at key " + allRegionsSnapshotKey);
}
 
Example 16
Source File: ConcResumableTxTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Write a snapshot of all regions to the blackboard
 * 
 */
public static void HydraTask_takeSnapshot() {
  Map<String, Map> masterMap = new HashMap<String, Map>();
  for (Region aRegion: CacheHelper.getCache().rootRegions()) {
    Map snapshot = new HashMap();
    for (Object key: aRegion.keySet()) {
      snapshot.put(key, aRegion.get(key));
    }
    masterMap.put(aRegion.getFullPath(), snapshot);
    Log.getLogWriter().info("Created snapshot for " + aRegion.getFullPath() + " of size " + snapshot.size());
  }
  ResumeTxBB.getBB().getSharedMap().put(snapshotKey, masterMap);
  Log.getLogWriter().info("Snapshots for " + masterMap.keySet() + " have been written to the blackboard");
}
 
Example 17
Source File: ConcResumableTxTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Verify a region against the given expected map
 * 
 * @param aRegion The region to verify.
 * @param expectedMap The expected contents of the region.
 */
private static void verifyFromSnapshot(Region aRegion, Map expectedMap) {
  Log.getLogWriter().info("Verifying " + aRegion.getFullPath() + " against snapshot of size " + expectedMap.size());
  StringBuffer aStr = new StringBuffer();
  int regionSize = aRegion.size();
  int expectedSize = expectedMap.size();
  if (regionSize != expectedSize) {
    aStr.append(aRegion.getFullPath() + " size is " + regionSize + " but expected it to be " + expectedSize + "\n");
  }
  Set expectedKeys = new HashSet(expectedMap.keySet());
  Set actualKeys = new HashSet(aRegion.keySet());
  Set missingKeys = new HashSet(expectedKeys);
  missingKeys.removeAll(actualKeys);
  Set extraKeys = new HashSet(actualKeys);
  extraKeys.removeAll(expectedKeys);
  if (missingKeys.size() > 0) {
    aStr.append("The following " + missingKeys.size() + " expected keys were missing from " + aRegion.getFullPath() + ": " + missingKeys + "\n");
  }
  if (extraKeys.size() > 0) {
    aStr.append("The following " + extraKeys.size() + " extra keys were found in " + aRegion.getFullPath() + ": " + extraKeys + "\n");
  }
  
  // now for those keys that exist in aRegion, verify their values
  for (Object key: aRegion.keySet()) {
    Object value = aRegion.get(key);
    if (expectedMap.containsKey(key)) {
      Object expectedValue = expectedMap.get(key);
      if ((value == null) || (expectedValue == null)) {
        aStr.append("For key " + key + ", expectedValue is " + expectedValue + " and value in region is " +
            value + ", but did not expect null values\n");
      } else {
        if (!value.equals(expectedValue)) {
          aStr.append("Expected value for key " + key + " to be " + expectedValue + " but it is " + value + "\n");
        }
      }
    }
  }
  
  if (aStr.length() > 0) {
    throw new TestException(aStr.toString());
  }
}
 
Example 18
Source File: ParRegExpirationTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Controls the thread that has an expiration action set for the entry in the
 * region TTLDestroy. (custom expiry)
 */
public void customEntryTTLDestroy() {
  String regionName = regionNames[CustomTTLDestroyIndex];
  Region aRegion = CacheHelper.getCache().getRegion(regionName);

  String expiryKeyPrefix = "Expire_" + regionName + "_";
  int expireNumKeys = populateRegion(aRegion, expiryKeyPrefix);
  Object expireKey = regionName + "_expireNumKeys";
  Log.getLogWriter().info(
      "Putting " + expireKey + ", " + expireNumKeys + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(expireKey,
      new Integer(expireNumKeys));

  String noExpiryKeyPrefix = "NotExpire_" + regionName + "_";
  int noExpireNumKeys = populateRegion(aRegion, noExpiryKeyPrefix);
  Object noExpireKey = regionName + "_noExpireNumKeys";
  Log.getLogWriter().info(
      "Putting " + noExpireKey + ", " + noExpireNumKeys
          + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(noExpireKey,
      new Integer(noExpireNumKeys));
  
  int expectedVmsForEvents = 1;

  if (TestConfig.tab()
      .booleanAt(ExpirPrms.isBridgeClientConfiguration, false)) {
    expectedVmsForEvents = TestConfig.tab().intAt(ExpirPrms.numClientVms) + 1;
  }

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomExpiryTTLDestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryTTLDestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomNoExpiryTTLDestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryTTLDestroy,
      noExpireNumKeys * expectedVmsForEvents, true, 600000);

  ParRegExpirationBB.getBB().getSharedCounters().increment(
      ParRegExpirationBB.numPopulationTask_Completed);

  // Wait for remote caches to receive all destroy events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterDestroyEvents_CustomTTLDestroy",
      ParRegExpirationBB.numAfterDestroyEvents_CustomTTLDestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  // Check that all were destroyed

  Set keySet = aRegion.keySet();

  if (keySet.size() != noExpireNumKeys) {
    throw new TestException(
        "Expected the region size after expiration to be the number of non expiry keys put into region "
            + noExpireNumKeys + " but has " + aRegion.size());
  }
  else {
    Log.getLogWriter().info(
        "Got the expected size of region after expiration as "
            + noExpireNumKeys);
  }

  Iterator iterator = keySet.iterator();
  while (iterator.hasNext()) {
    String key = iterator.next().toString();
    if (key.startsWith("Expire_")) {
      throw new TestException("Unexpected key " + key + " in the region "
          + aRegion.getName() + " after expiration");
    }
  }

  ParRegExpirationBB.getBB().printSharedCounters();
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryTTLDestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryTTLDestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterDestroyEvents_CustomTTLDestroy);
}
 
Example 19
Source File: ParRegExpirationTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Controls the thread that has an expiration action set in the entry for
 * region IdleTOInval (custom expiry)
 */
public void customEntryIdleTODestroy() {
  String regionName = regionNames[CustomIdleTODestroyIndex];
  Region aRegion = CacheHelper.getCache().getRegion(regionName);

  String expiryKeyPrefix = "Expire_" + regionName + "_";
  int expireNumKeys = populateRegion(aRegion, expiryKeyPrefix);
  Object expireKey = regionName + "_expireNumKeys";
  Log.getLogWriter().info(
      "Putting " + expireKey + ", " + expireNumKeys + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(expireKey,
      new Integer(expireNumKeys));

  String noExpiryKeyPrefix = "NotExpire_" + regionName + "_";
  int noExpireNumKeys = populateRegion(aRegion, noExpiryKeyPrefix);
  Object noExpireKey = regionName + "_noExpireNumKeys";
  Log.getLogWriter().info(
      "Putting " + noExpireKey + ", " + noExpireNumKeys
          + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(noExpireKey,
      new Integer(noExpireNumKeys));

  
  int expectedVmsForEvents = 1;

  if (TestConfig.tab()
      .booleanAt(ExpirPrms.isBridgeClientConfiguration, false)) {
    expectedVmsForEvents = TestConfig.tab().intAt(ExpirPrms.numClientVms) + 1;
  }

  // Wait for this VM to receive all create events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomExpiryIdleTODestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryIdleTODestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomNoExpiryIdleTODestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryIdleTODestroy,
      noExpireNumKeys * expectedVmsForEvents, true, 600000);

  ParRegExpirationBB.getBB().getSharedCounters().increment(
      ParRegExpirationBB.numPopulationTask_Completed);

  // Wait for this VM to receive all invalidate events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterDestroyEvents_CustomIdleTODestroy",
      ParRegExpirationBB.numAfterDestroyEvents_CustomIdleTODestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  // Check that all entries with prefix Expire_ were destroyed

  Set keySet = aRegion.keySet();

  if (keySet.size() != noExpireNumKeys) {
    throw new TestException(
        "Expected the region size after expiration to be the number of non expiry keys put into region "
            + noExpireNumKeys + " but has " + aRegion.size());
  }
  else {
    Log.getLogWriter().info(
        "Got the expected size of region after expiration as "
            + noExpireNumKeys);
  }

  Iterator iterator = keySet.iterator();
  while (iterator.hasNext()) {
    String key = iterator.next().toString();
    if (key.startsWith("Expire_")) {
      throw new TestException("Unexpected key " + key + " in the region "
          + aRegion.getName() + " after expiration");
    }
  }

  ParRegExpirationBB.getBB().printSharedCounters();
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryIdleTODestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryIdleTODestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterDestroyEvents_CustomIdleTODestroy);
}
 
Example 20
Source File: WanFilterTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void validateDoOpsForEventFilter() {      
  Set rootRegions = CacheHelper.getCache().rootRegions();
  Iterator itr = rootRegions.iterator();
  while (itr.hasNext()) {      
    Region r = (Region)itr.next();
    logger.info("validateDoOpsForEventFilter: validating region " + r.getFullPath());
                
    StringBuilder str = new StringBuilder();
    Set extraFilterKeys = new TreeSet(r.keySet());
    int dsKeyCounter = getDsKeyCounter();
    int totalDs = distributedSystems.size();
    int dsId = DistributedSystemHelper.getDistributedSystemId().intValue();
    if(dsId == -1){// this is client vm
      dsId = EdgeHelper.toWanSite(RemoteTestModule.getMyClientName());
    }
    while (dsKeyCounter >= dsId) {
      String key = new String(FILTER_KEY_PRIFIX + dsKeyCounter);
      Object expVal = new Long(dsKeyCounter);  
      extraFilterKeys.remove(key);
      if(r.containsKey(key)){
        Object val = r.get(key);
        if(val == null || !val.equals(expVal)){
          str.append("  for key " + key + ", expected " + expVal + ", found " + val + "\n");
        }
      }else{
        str.append("  for key " + key + ", expected " + expVal + ", but key does not exists on region \n");          
      }
      dsKeyCounter = dsKeyCounter - totalDs;
    }
    
    //remove all non filter keys
    Iterator i = extraFilterKeys.iterator();
    Set temp = new HashSet();
    while(i.hasNext()){
      String k = (String)i.next();
      if(!k.contains(FILTER_KEY_PRIFIX)){
        temp.add(k);          
      }
    }
    extraFilterKeys.removeAll(temp);
    
    if(extraFilterKeys.size() > 0){
      str.append("Found " + extraFilterKeys.size() + " unexpected filter keys in region " + r.getFullPath() + " : " + extraFilterKeys + "\n");
    }
    
    if(str.length() > 0){
      throw new TestException("Error found in validating region " + r.getFullPath() + "\n" + str.toString());
    }
  }
}