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

The following examples show how to use com.gemstone.gemfire.cache.Region#entrySet() . 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: PeerTypeRegistration.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void initializeGateway(GatewayImpl gatewayImpl) {
  //TODO Dan - make sure that the gateway is already
  //receiving updates by the time we iterate over the region here.
  TXStateInterface currentState = suspendTX();
  Region<Object, Object> r = getIdToType();
  try {
    for(Map.Entry<Object, Object> typeEntry: r.entrySet()) {
      EntryEventImpl event = EntryEventImpl.create(
          (LocalRegion) r, Operation.UPDATE, typeEntry.getKey(),
          typeEntry.getValue(), new GatewayEventCallbackArgument((Object)null), false, cache.getMyId());
      try {
      event.setEventId(new EventID(cache.getSystem()));
      gatewayImpl.distribute(EnumListenerEvent.AFTER_UPDATE, event);
      } finally {
        event.release();
      }
    }
  } finally {
    resumeTX(currentState);
  }
}
 
Example 2
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Validate all the key values are present in the region and it dint reconnected.
 * 
 * @throws Exception.
 * */
private static void validateRegion(Region myRegion) throws Exception{
	//String key = "myKey";
	//String value = "myValue";
	int i =0;
	//HashMap regionKeyValue = (HashMap)region2HashMap.get(myRegion);
	HashMap regionKeyValue = (HashMap)((SustainabilityBB.getBB()).getSharedMap()).get(myRegion.getName());
	Set entrySet = myRegion.entrySet();
	Iterator it = entrySet.iterator();
	Log.getLogWriter().info("Checking integrity for : "+myRegion.getName());
	if (entrySet.size() != regionKeyValue.size()){
		throw new Exception("There should be : "+regionKeyValue.size()+" key-value pairs but found : "+entrySet.size());
	}
	Log.getLogWriter().info("ENTRY KEY SIZE : "+entrySet.size()+" and the hashmap : "+regionKeyValue.size());
	Region.Entry keyValue= null;
	while (it.hasNext()){
		keyValue = (Region.Entry)it.next();
		String value= (String)regionKeyValue.get(keyValue.getKey());
		if(value == null){
			throw new RuntimeException("No key-value pair for the : "+keyValue.getKey()+" in KeyValue HashMap but the key is present in the local region");
		}else if(value.compareTo((String)keyValue.getValue())!= 0){
			throw new RuntimeException("The value for the key : "+keyValue.getKey()+" from entry set :"+keyValue.getKey()+" does not match the value from the hashmap : "+value);
		}
					
	}
}
 
Example 3
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the cache from the xml file specified by xmlFileName.
 * 
 * @throws Exception.
 * */
public static void createCacheAndRegionsWithBackUp() throws Exception{
	Cache cache = CacheUtil.createCache(xmlFileName);
	//Region myRegion = cache.getRegion(regionName);
	try{
		Thread.sleep(60000);
	}catch(InterruptedException ignor){}
	Region myRegion = cache.getRegion(regionName);
	Set entrySet = myRegion.entrySet();
	Region.Entry keyValue = null;
	Iterator it = entrySet.iterator();
	while(it.hasNext()){
			keyValue = (Region.Entry)it.next();
			if ((((String)keyValue.getKey()).compareTo(key)) != 0){
			throw new Exception("The key doesnt match the orignal key : "+keyValue.getKey()+" Orignal Key : "+key);
			}
		
			if(((((String)keyValue.getValue()).compareTo(value)) != 0)){
				throw new Exception("The value doesnt match the orignal value for the key : "+keyValue.getValue()+" Orignal Key : "+value);
			}
		}
			
}
 
Example 4
Source File: LimitClauseTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testLikeWithLimitWithParameter() throws Exception {
  String queryString = "SELECT DISTINCT entry FROM $1 entry WHERE entry.key like $2 ORDER BY entry.key LIMIT $3 ";
  SelectResults result;
  Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
  for (int i = 0; i < 100; i++) {
    region.put( "p"+i, new Portfolio(i));
  }
  
  Object[] params = new Object[3];
  params[0] = region.entrySet();
  params[1] = "p%";
  params[2] = 5;

  SelectResults results = (SelectResults)qs.newQuery(queryString).execute(params);
  assertEquals(5, results.size());
}
 
Example 5
Source File: RegionEntryFlagsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testUpdateInProgressFlag() {
  Region region = CacheUtils.createRegion("testRegion", null,
      Scope.DISTRIBUTED_ACK);
  // Put one entry in the region.
  region.put(1, 1);
  Set entries = region.entrySet();
  assertEquals(1, entries.size());

  Region.Entry nonTxEntry = (Entry) entries.iterator().next();
  RegionEntry entry = ((NonTXEntry) nonTxEntry).getRegionEntry();
  assertFalse(entry.isUpdateInProgress());
  entry.setUpdateInProgress(true);
  assertTrue(entry.isUpdateInProgress());
  entry.setUpdateInProgress(false);
  assertFalse(entry.isUpdateInProgress());
}
 
Example 6
Source File: HARQueueNewImplDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void makeValuesOfSomeKeysNullInClientMsgsRegion(Integer port,
    String[] keys) {
  Region msgsRegion = cache.getRegion(BridgeServerImpl
      .generateNameForClientMsgsRegion(port.intValue()));
  assertNotNull(msgsRegion);

  Set entries = msgsRegion.entrySet();
  Iterator iter = entries.iterator();
  deletedValues = new Object[keys.length];
  while (iter.hasNext()) {
    Region.Entry entry = (Region.Entry)iter.next();
    ClientUpdateMessage cum = (ClientUpdateMessage)entry.getValue();
    for (int i = 0; i < keys.length; i++) {
      if (keys[i].equals(cum.getKeyToConflate())) {
        logger.fine("HARQueueNewImplDUnit: Removing "
            + cum.getKeyOfInterest());
        deletedValues[i] = msgsRegion.remove(entry.getKey());
      }
    }
  }
}
 
Example 7
Source File: ConcurrentRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
void validate(Region r1, Region r2)
{
  if (!this.validate) return;

  Collection entrySet = r2.entrySet();
  Iterator iterator = entrySet.iterator();
  Map.Entry mapEntry = null;
  Object key, value = null;
  while (iterator.hasNext()) {
    mapEntry = (Map.Entry)iterator.next();
    key = mapEntry.getKey();
    value = mapEntry.getValue();
    if (!(r1.containsKey(key))) {
      fail(" region1 does not contain Key " + key
          + " but was expected to be there");
    }
    if (!(r1.get(key).equals(value))) {
      fail(" value for key " + key + " is " + r1.get(key)
          + " which is not consistent, it is supposed to be " + value);
    }
  }
  assertEquals(r2.size(), r1.size());

  r1.destroyRegion();
  r2.destroyRegion();
}
 
Example 8
Source File: LocalExporter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
  LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);
  
  long count = 0;
  for (Entry<K, V> entry : region.entrySet()) {
    try {
      if (options.getFilter() == null || options.getFilter().accept(entry)) {
        sink.write(new SnapshotRecord(local, entry));
        count++;
      }
    } catch (EntryDestroyedException e) {
      // continue to next entry
    }
  }
  return count;
}
 
Example 9
Source File: PeerTypeRegistration.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void initializeGateway(GatewayImpl gatewayImpl) {
  //TODO Dan - make sure that the gateway is already
  //receiving updates by the time we iterate over the region here.
  TXStateInterface currentState = suspendTX();
  Region<Object, Object> r = getIdToType();
  try {
    for(Map.Entry<Object, Object> typeEntry: r.entrySet()) {
      EntryEventImpl event = EntryEventImpl.create(
          (LocalRegion) r, Operation.UPDATE, typeEntry.getKey(),
          typeEntry.getValue(), new GatewayEventCallbackArgument((Object)null), false, cache.getMyId());
      try {
      event.setEventId(new EventID(cache.getSystem()));
      gatewayImpl.distribute(EnumListenerEvent.AFTER_UPDATE, event);
      } finally {
        event.release();
      }
    }
  } finally {
    resumeTX(currentState);
  }
}
 
Example 10
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Validate all the key values are present in the region and it dint reconnected.
 * 
 * @throws Exception.
 * */
private static void validateRegion(Region myRegion) throws Exception{
	//String key = "myKey";
	//String value = "myValue";
	int i =0;
	//HashMap regionKeyValue = (HashMap)region2HashMap.get(myRegion);
	HashMap regionKeyValue = (HashMap)((SustainabilityBB.getBB()).getSharedMap()).get(myRegion.getName());
	Set entrySet = myRegion.entrySet();
	Iterator it = entrySet.iterator();
	Log.getLogWriter().info("Checking integrity for : "+myRegion.getName());
	if (entrySet.size() != regionKeyValue.size()){
		throw new Exception("There should be : "+regionKeyValue.size()+" key-value pairs but found : "+entrySet.size());
	}
	Log.getLogWriter().info("ENTRY KEY SIZE : "+entrySet.size()+" and the hashmap : "+regionKeyValue.size());
	Region.Entry keyValue= null;
	while (it.hasNext()){
		keyValue = (Region.Entry)it.next();
		String value= (String)regionKeyValue.get(keyValue.getKey());
		if(value == null){
			throw new RuntimeException("No key-value pair for the : "+keyValue.getKey()+" in KeyValue HashMap but the key is present in the local region");
		}else if(value.compareTo((String)keyValue.getValue())!= 0){
			throw new RuntimeException("The value for the key : "+keyValue.getKey()+" from entry set :"+keyValue.getKey()+" does not match the value from the hashmap : "+value);
		}
					
	}
}
 
Example 11
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the cache from the xml file specified by xmlFileName.
 * 
 * @throws Exception.
 * */
public static void createCacheAndRegionsWithBackUp() throws Exception{
	Cache cache = CacheUtil.createCache(xmlFileName);
	//Region myRegion = cache.getRegion(regionName);
	try{
		Thread.sleep(60000);
	}catch(InterruptedException ignor){}
	Region myRegion = cache.getRegion(regionName);
	Set entrySet = myRegion.entrySet();
	Region.Entry keyValue = null;
	Iterator it = entrySet.iterator();
	while(it.hasNext()){
			keyValue = (Region.Entry)it.next();
			if ((((String)keyValue.getKey()).compareTo(key)) != 0){
			throw new Exception("The key doesnt match the orignal key : "+keyValue.getKey()+" Orignal Key : "+key);
			}
		
			if(((((String)keyValue.getValue()).compareTo(value)) != 0)){
				throw new Exception("The value doesnt match the orignal value for the key : "+keyValue.getValue()+" Orignal Key : "+value);
			}
		}
			
}
 
Example 12
Source File: LimitClauseTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testLikeWithLimitWithParameter() throws Exception {
  String queryString = "SELECT DISTINCT entry FROM $1 entry WHERE entry.key like $2 ORDER BY entry.key LIMIT $3 ";
  SelectResults result;
  Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
  for (int i = 0; i < 100; i++) {
    region.put( "p"+i, new Portfolio(i));
  }
  
  Object[] params = new Object[3];
  params[0] = region.entrySet();
  params[1] = "p%";
  params[2] = 5;

  SelectResults results = (SelectResults)qs.newQuery(queryString).execute(params);
  assertEquals(5, results.size());
}
 
Example 13
Source File: RegionEntryFlagsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testUpdateInProgressFlag() {
  Region region = CacheUtils.createRegion("testRegion", null,
      Scope.DISTRIBUTED_ACK);
  // Put one entry in the region.
  region.put(1, 1);
  Set entries = region.entrySet();
  assertEquals(1, entries.size());

  Region.Entry nonTxEntry = (Entry) entries.iterator().next();
  RegionEntry entry = ((NonTXEntry) nonTxEntry).getRegionEntry();
  assertFalse(entry.isUpdateInProgress());
  entry.setUpdateInProgress(true);
  assertTrue(entry.isUpdateInProgress());
  entry.setUpdateInProgress(false);
  assertFalse(entry.isUpdateInProgress());
}
 
Example 14
Source File: HARQueueNewImplDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void makeValuesOfSomeKeysNullInClientMsgsRegion(Integer port,
    String[] keys) {
  Region msgsRegion = cache.getRegion(BridgeServerImpl
      .generateNameForClientMsgsRegion(port.intValue()));
  assertNotNull(msgsRegion);

  Set entries = msgsRegion.entrySet();
  Iterator iter = entries.iterator();
  deletedValues = new Object[keys.length];
  while (iter.hasNext()) {
    Region.Entry entry = (Region.Entry)iter.next();
    ClientUpdateMessage cum = (ClientUpdateMessage)entry.getValue();
    for (int i = 0; i < keys.length; i++) {
      if (keys[i].equals(cum.getKeyToConflate())) {
        logger.fine("HARQueueNewImplDUnit: Removing "
            + cum.getKeyOfInterest());
        deletedValues[i] = msgsRegion.remove(entry.getKey());
      }
    }
  }
}
 
Example 15
Source File: ConcurrentRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
void validate(Region r1, Region r2)
{
  if (!this.validate) return;

  Collection entrySet = r2.entrySet();
  Iterator iterator = entrySet.iterator();
  Map.Entry mapEntry = null;
  Object key, value = null;
  while (iterator.hasNext()) {
    mapEntry = (Map.Entry)iterator.next();
    key = mapEntry.getKey();
    value = mapEntry.getValue();
    if (!(r1.containsKey(key))) {
      fail(" region1 does not contain Key " + key
          + " but was expected to be there");
    }
    if (!(r1.get(key).equals(value))) {
      fail(" value for key " + key + " is " + r1.get(key)
          + " which is not consistent, it is supposed to be " + value);
    }
  }
  assertEquals(r2.size(), r1.size());

  r1.destroyRegion();
  r2.destroyRegion();
}
 
Example 16
Source File: LocalExporter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
  LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);
  
  long count = 0;
  for (Entry<K, V> entry : region.entrySet()) {
    try {
      if (options.getFilter() == null || options.getFilter().accept(entry)) {
        sink.write(new SnapshotRecord(local, entry));
        count++;
      }
    } catch (EntryDestroyedException e) {
      // continue to next entry
    }
  }
  return count;
}
 
Example 17
Source File: HARQueueNewImplDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyNullValuesInCMR(final Integer numOfEntries, 
    final Integer port,
    String[] keys) {
  final Region msgsRegion = cache.getRegion(BridgeServerImpl
      .generateNameForClientMsgsRegion(port.intValue()));
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      int sz = msgsRegion.size();
      return sz == numOfEntries.intValue();
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 60 * 1000, 1000, true);

  Set entries = msgsRegion.entrySet();
  Iterator iter = entries.iterator();
  for (; iter.hasNext();) {
    Region.Entry entry = (Region.Entry)iter.next();
    ClientUpdateMessage cum = (ClientUpdateMessage)entry.getValue();
    for (int i = 0; i < keys.length; i++) {
      logger.fine("cum.key: " + cum.getKeyToConflate());
      // assert that the keys are not present in entries set
      assertTrue(!keys[i].equals(cum.getKeyToConflate()));
    }
  }
}
 
Example 18
Source File: HARQueueNewImplDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyNullValuesInCMR(final Integer numOfEntries, 
    final Integer port,
    String[] keys) {
  final Region msgsRegion = cache.getRegion(BridgeServerImpl
      .generateNameForClientMsgsRegion(port.intValue()));
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      int sz = msgsRegion.size();
      return sz == numOfEntries.intValue();
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 60 * 1000, 1000, true);

  Set entries = msgsRegion.entrySet();
  Iterator iter = entries.iterator();
  for (; iter.hasNext();) {
    Region.Entry entry = (Region.Entry)iter.next();
    ClientUpdateMessage cum = (ClientUpdateMessage)entry.getValue();
    for (int i = 0; i < keys.length; i++) {
      logger.fine("cum.key: " + cum.getKeyToConflate());
      // assert that the keys are not present in entries set
      assertTrue(!keys[i].equals(cum.getKeyToConflate()));
    }
  }
}
 
Example 19
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
	 * Checks the integrity of all the regions by making sure there are 
	 * seven regions defined and all the regions have 20000 key-value pair. 
	 * If not then is throws an exception with appropriate message.
	 * 
	 * @throw Exception 
	 * */
	
	public static void checkGetInitialImageStats() throws Exception {
		//MasterController.sleepForMs(20000);
		Cache aCache = null;
		long time = System.currentTimeMillis();
		while (aCache == null){
			try{
				aCache = CacheFactory.getAnyInstance();
			}
			catch (CancelException ignor){
				if ((System.currentTimeMillis()-time) >240000 )
					throw new Exception("Waited 3 mins for the system to reconnect porperly");
				try{
					Thread.sleep(10000);
				}catch(InterruptedException ignor2){
					
				}
			}
		}
		try{
			Thread.sleep(60000);
		}catch(InterruptedException wait){}
                if ( ((GemFireCacheImpl)aCache).isClosed() ) {
                  Log.getLogWriter().severe("obtained closing cache from CacheFactory");
                }
		CachePerfStats stats = ((GemFireCacheImpl) aCache).getCachePerfStats();
		Log.getLogWriter().info("THE INITIMAGE STAT : "+ stats.getGetInitialImageKeysReceived());
		Log.getLogWriter().info("THE Number of Regions :"+stats.getRegions());
		if (stats.getRegions() != 7)
			throw new Exception("There should be 7 regions defined after reconnect");
		Set regions = aCache.rootRegions();
		Iterator it = regions.iterator();
		while(it.hasNext()){
			Region r = (Region)it.next();
			Set s = r.entrySet();
			if(s.size() != 20000){
				throw new Exception("There should be 20000 keys but found : "+s.size()+" in region : "+r);
			}
		Log.getLogWriter().info("Region : "+r+" contains : "+s.size()+" keys and value pairs");
		}
		
		//		System.out.println("The INITIMAGE STAT XXXXX  : "+TestHelper.getStat_getInitialImageKeysReceived());
//		Cache cache = CacheFactory.getAnyInstance();
		
	}
 
Example 20
Source File: SustainabilityTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
	 * Checks the integrity of all the regions by making sure there are 
	 * seven regions defined and all the regions have 20000 key-value pair. 
	 * If not then is throws an exception with appropriate message.
	 * 
	 * @throw Exception 
	 * */
	
	public static void checkGetInitialImageStats() throws Exception {
		//MasterController.sleepForMs(20000);
		Cache aCache = null;
		long time = System.currentTimeMillis();
		while (aCache == null){
			try{
				aCache = CacheFactory.getAnyInstance();
			}
			catch (CancelException ignor){
				if ((System.currentTimeMillis()-time) >240000 )
					throw new Exception("Waited 3 mins for the system to reconnect porperly");
				try{
					Thread.sleep(10000);
				}catch(InterruptedException ignor2){
					
				}
			}
		}
		try{
			Thread.sleep(60000);
		}catch(InterruptedException wait){}
                if ( ((GemFireCacheImpl)aCache).isClosed() ) {
                  Log.getLogWriter().severe("obtained closing cache from CacheFactory");
                }
		CachePerfStats stats = ((GemFireCacheImpl) aCache).getCachePerfStats();
		Log.getLogWriter().info("THE INITIMAGE STAT : "+ stats.getGetInitialImageKeysReceived());
		Log.getLogWriter().info("THE Number of Regions :"+stats.getRegions());
		if (stats.getRegions() != 7)
			throw new Exception("There should be 7 regions defined after reconnect");
		Set regions = aCache.rootRegions();
		Iterator it = regions.iterator();
		while(it.hasNext()){
			Region r = (Region)it.next();
			Set s = r.entrySet();
			if(s.size() != 20000){
				throw new Exception("There should be 20000 keys but found : "+s.size()+" in region : "+r);
			}
		Log.getLogWriter().info("Region : "+r+" contains : "+s.size()+" keys and value pairs");
		}
		
		//		System.out.println("The INITIMAGE STAT XXXXX  : "+TestHelper.getStat_getInitialImageKeysReceived());
//		Cache cache = CacheFactory.getAnyInstance();
		
	}