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

The following examples show how to use com.gemstone.gemfire.cache.Region#clear() . 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: MapInterfaceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testBasicMapClearTrnxn() {
  Region rgn = CacheUtils.getRegion("Portfolios");
  int size = rgn.size();
  assertTrue(
      "MapInterfaceTest::basicMapClearNonTranxn: The init size of region is zero",
      size > 0);
  CacheTransactionManager tm = CacheUtils.getCacheTranxnMgr();
  tm.begin();
  rgn.put("6", new Portfolio(6));
  assertTrue(rgn.size() == 5);
  rgn.clear();
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  try {
    tm.commit();
  }
  catch (ConflictException cce) {
    //Ignore
  }
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
}
 
Example 2
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void clearRegion(String regionName) {
  try {
    Region region = cache.getRegion(regionName);
    if (region != null) {
      region.clear();
      Log.getLogWriter().info(
          "----performed clear operation on region" + regionName);
    }

  } catch (RegionDestroyedException rdex) {
    Log
        .getLogWriter()
        .info(
            "RegionDestroyedException...may occur in concurrent environment. Continuing with test.");
    recoverRegion(regionName);
  } catch (Exception ex) {
    throw new TestException(TestHelper.getStackTrace(ex));
  }
}
 
Example 3
Source File: MemberInfoWithStatsMBeanGFEValidationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void  destroyWanQueues() {
  try{
    Cache cache = com.gemstone.gemfire.cache.CacheFactory.getAnyInstance();
    for (Iterator i = cache.getGatewayHubs().iterator(); i.hasNext();) {
      GatewayHub hub = (GatewayHub) i.next();
      for (Iterator i1 = hub.getGateways().iterator(); i1.hasNext();) {
        Gateway gateway = (Gateway) i1.next();
        String rq= new StringBuffer(gateway.getGatewayHubId()).append('_').append(gateway.getId()).append("_EVENT_QUEUE").toString();
        Region wbcl = cache.getRegion(rq);
        if(wbcl != null) {
          wbcl.localDestroyRegion();
        }         
      }  
    }
    Set<Region<?, ?>> rootRegions = cache.rootRegions();
    if (rootRegions != null) {
      for (Region<?, ?> region : rootRegions) {
        region.clear();
      }
    }
  } catch (CancelException cce) {
    //Ignore
  }
}
 
Example 4
Source File: CliUtilDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void verifyExecuteFunction(){
  DunitFunction function = new DunitFunction("myfunction");
  Set<DistributedMember> set;
  try {
    @SuppressWarnings("rawtypes")
    Region region1 = CacheFactory.getAnyInstance().getRegion(COMMON_REGION);
    region1.clear();
    set = CliUtil.findAllMatchingMembers(GROUP1,null);
    assertEquals(2, set.size());
    ResultCollector collector = CliUtil.executeFunction(function, "executeOnGroup", set);
    collector.getResult();
    assertEquals(2, region1.size());
    assertTrue(region1.containsKey(MEMBER_1_GROUP1));
    assertTrue(region1.containsKey(MEMBER_2_GROUP1));
    assertEquals("executeOnGroup", region1.get(MEMBER_1_GROUP1));
    assertEquals("executeOnGroup", region1.get(MEMBER_2_GROUP1));
  } catch (CommandResultException e) {
    fail("Error during querying members",e);
  }        
}
 
Example 5
Source File: ConcurrentFlushingAndRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
void clearBeforeFlush(final Region region)
{
  ((LocalRegion)region).getDiskRegion().pauseFlusherForTesting();
  region.put("Key", "Value1");
  region.clear();
  ((LocalRegion)region).getDiskRegion().flushForTesting();
  boolean entryNotFound = false;
  try {
    getValueOnDisk(region);
  }
  catch (EntryNotFoundException e) {
    entryNotFound = true;
  }
  if (!entryNotFound) {
    fail("EntryNotFoundException was expected but did not get it");
  }
  entryNotFound = false;
  Object obj = ((LocalRegion)region).basicGetEntry("Key");
  if (obj == null) {
    entryNotFound = true;
  }
  if (!entryNotFound) {
    fail("EntryNotFoundException was expected but did not get it");
  }
}
 
Example 6
Source File: ConcurrentFlushingAndRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
void clearBeforeFlush(final Region region)
{
  ((LocalRegion)region).getDiskRegion().pauseFlusherForTesting();
  region.put("Key", "Value1");
  region.clear();
  ((LocalRegion)region).getDiskRegion().flushForTesting();
  boolean entryNotFound = false;
  try {
    getValueOnDisk(region);
  }
  catch (EntryNotFoundException e) {
    entryNotFound = true;
  }
  if (!entryNotFound) {
    fail("EntryNotFoundException was expected but did not get it");
  }
  entryNotFound = false;
  Object obj = ((LocalRegion)region).basicGetEntry("Key");
  if (obj == null) {
    entryNotFound = true;
  }
  if (!entryNotFound) {
    fail("EntryNotFoundException was expected but did not get it");
  }
}
 
Example 7
Source File: MemberInfoWithStatsMBeanGFEValidationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void  destroyWanQueues() {
  try{
    Cache cache = com.gemstone.gemfire.cache.CacheFactory.getAnyInstance();
    for (Iterator i = cache.getGatewayHubs().iterator(); i.hasNext();) {
      GatewayHub hub = (GatewayHub) i.next();
      for (Iterator i1 = hub.getGateways().iterator(); i1.hasNext();) {
        Gateway gateway = (Gateway) i1.next();
        String rq= new StringBuffer(gateway.getGatewayHubId()).append('_').append(gateway.getId()).append("_EVENT_QUEUE").toString();
        Region wbcl = cache.getRegion(rq);
        if(wbcl != null) {
          wbcl.localDestroyRegion();
        }         
      }  
    }
    Set<Region<?, ?>> rootRegions = cache.rootRegions();
    if (rootRegions != null) {
      for (Region<?, ?> region : rootRegions) {
        region.clear();
      }
    }
  } catch (CancelException cce) {
    //Ignore
  }
}
 
Example 8
Source File: QueryIndexUpdateRIDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private SerializableRunnable getSRClearRegion(final String regionName) {
  SerializableRunnable sr = new CacheSerializableRunnable("Destroy entries") {
    @Override
    public void run2() throws CacheException {
      getLogWriter().info("### Clearing Region. ###");
      Region region1;
      if(!"root".equals(regionName)){
        region1 = getRootRegion().getSubregion(regionName);
      } else {
        region1 = getRootRegion();
      }
      region1.clear();
      getLogWriter().info("### Number of Entries in Region :" + region1.keys().size());
    }
  };
  return sr;
}
 
Example 9
Source File: MultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * clearRegion will be used in serial test to clear all the entries in the specified region
 * there will be only one region operation in any single test run
 * @param regionName - specified region to be cleared
 */
protected void clearRegion(String regionName) {
  Region region = RegionHelper.getRegion(regionName);    
  
  if (region != null) {
    if (region.entrySet().size() < 100) {
      Log.getLogWriter().info("Not enough entries in the region to be cleared.");
      return;
    } // wait until there are some entries in the region to be cleared
    else {
      int destroyed = region.entrySet().size();
      region.clear();
      Log.getLogWriter().info("clearRegion destroys " + destroyed + " entries in region " + regionName);
      MapBB.getBB().getSharedCounters().increment(MapBB.NUM_REGION_DESTROY); //update num of clearRegion
    }
  }
}
 
Example 10
Source File: MultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * clearRegion will be used in serial test to clear all the entries in the specified region
 * there will be only one region operation in any single test run
 * @param regionName - specified region to be cleared
 */
protected void clearRegion(String regionName) {
  Region region = RegionHelper.getRegion(regionName);    
  
  if (region != null) {
    if (region.entrySet().size() < 100) {
      Log.getLogWriter().info("Not enough entries in the region to be cleared.");
      return;
    } // wait until there are some entries in the region to be cleared
    else {
      int destroyed = region.entrySet().size();
      region.clear();
      Log.getLogWriter().info("clearRegion destroys " + destroyed + " entries in region " + regionName);
      MapBB.getBB().getSharedCounters().increment(MapBB.NUM_REGION_DESTROY); //update num of clearRegion
    }
  }
}
 
Example 11
Source File: RegionClearTask.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public CommandResults runTask(Object userData)
{
	CommandResults results = new CommandResults();

	MemberInfo memberInfo = new MemberInfo();

	try {
		Cache cache = CacheFactory.getAnyInstance();
		Region region = cache.getRegion(regionFullPath);
		DistributedMember member = cache.getDistributedSystem().getDistributedMember();
		memberInfo.setHost(member.getHost());
		memberInfo.setMemberId(member.getId());
		memberInfo.setMemberName(cache.getName());
		memberInfo.setPid(member.getProcessId());

		results.setDataObject(memberInfo);

		if (region == null) {
			results.setCode(ERROR_REGION_CLEAR);
			results.setCodeMessage("Region undefined: " + regionFullPath);
		} else {
			synchronized (region) {
				region.clear();
			}
		}
	} catch (Exception ex) {
		results.setCode(ERROR_REGION_CLEAR);
		results.setCodeMessage(ex.getMessage());
		results.setException(ex);
	}

	return results;
}
 
Example 12
Source File: RegionClearTask.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public CommandResults runTask(Object userData)
{
	CommandResults results = new CommandResults();

	MemberInfo memberInfo = new MemberInfo();

	try {
		Cache cache = CacheFactory.getAnyInstance();
		Region region = cache.getRegion(regionFullPath);
		DistributedMember member = cache.getDistributedSystem().getDistributedMember();
		memberInfo.setHost(member.getHost());
		memberInfo.setMemberId(member.getId());
		memberInfo.setMemberName(cache.getName());
		memberInfo.setPid(member.getProcessId());

		results.setDataObject(memberInfo);

		if (region == null) {
			results.setCode(ERROR_REGION_CLEAR);
			results.setCodeMessage("Region undefined: " + regionFullPath);
		} else {
			synchronized (region) {
				region.clear();
			}
		}
	} catch (Exception ex) {
		results.setCode(ERROR_REGION_CLEAR);
		results.setCodeMessage(ex.getMessage());
		results.setException(ex);
	}

	return results;
}
 
Example 13
Source File: MapInterfaceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBasicMapAfterClearCalback() {
  Region rgn = CacheUtils.getRegion("Portfolios");
  AttributesMutator atm = rgn.getAttributesMutator();
  atm.setCacheListener(new CacheListenerAdapter() {

    @Override
    public void afterRegionClear(RegionEvent event) {
      synchronized (MapInterfaceTest.this) {
        event.getRegion().getCache().getLogger().info("afterRegionClear call back " + event);
        afterClearCallbackOccured = true;
        MapInterfaceTest.this.notify();
      }
    }
  });
  int size = rgn.size();
  assertTrue(
      "MapInterfaceTest::basicMapClearNonTranxn: The init size of region is zero",
      size > 0);
  rgn.clear();
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  try {
    synchronized (this) {
      if (!this.afterClearCallbackOccured) {
        this.wait(10000);
      }
    }
  }
  catch (InterruptedException ie) {
    fail(ie.toString());
  }
  if (!this.afterClearCallbackOccured) {
    fail("afterClear Callback not issued");
  }
}
 
Example 14
Source File: MapInterfaceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBasicMapClearNonTrnxn() {
  Region rgn = CacheUtils.getRegion("Portfolios");
  int size = rgn.size();
  assertTrue(
      "MapInterfaceTest::basicMapClearNonTranxn: The init size of region is zero",
      size > 0);
  rgn.clear();
  if (rgn.size() != 0) {
    fail("The region size is non zerio even after issuing clear");
  }
}
 
Example 15
Source File: MapInterfaceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBasicMapAfterClearCalback() {
  Region rgn = CacheUtils.getRegion("Portfolios");
  AttributesMutator atm = rgn.getAttributesMutator();
  atm.setCacheListener(new CacheListenerAdapter() {

    @Override
    public void afterRegionClear(RegionEvent event) {
      synchronized (MapInterfaceTest.this) {
        event.getRegion().getCache().getLogger().info("afterRegionClear call back " + event);
        afterClearCallbackOccured = true;
        MapInterfaceTest.this.notify();
      }
    }
  });
  int size = rgn.size();
  assertTrue(
      "MapInterfaceTest::basicMapClearNonTranxn: The init size of region is zero",
      size > 0);
  rgn.clear();
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  try {
    synchronized (this) {
      if (!this.afterClearCallbackOccured) {
        this.wait(10000);
      }
    }
  }
  catch (InterruptedException ie) {
    fail(ie.toString());
  }
  if (!this.afterClearCallbackOccured) {
    fail("afterClear Callback not issued");
  }
}
 
Example 16
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
    * Clears the distributed region.
    * @param region The region to be cleared.
    * @throws CacheException
    */    
   public final static void clearRegion(Region region) throws CacheException
{	
   	if (region == null) {
   		return;
   	}
   	
   	region.clear();
}
 
Example 17
Source File: MapInterfaceTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testSuccessGlobalScopeInSingleVM () {
  CacheUtils.getCache().setLockLease(10);
  CacheUtils.getCache().setLockTimeout(15);
  final Region region = CacheUtils.createRegion ("Global", String.class, Scope.GLOBAL);
  for (int i = 0; i < 10; i++) {
    region.put("" + i, ""+i);
  }
  
  LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER=true;
  CacheObserverHolder.setInstance( new CacheObserverAdapter() {  
    @Override
    public void afterRegionClear ( RegionEvent event) {
      //Allwo main thread to proceed just before sleeping
             
      try {
        synchronized(MapInterfaceTest.this) {
          MapInterfaceTest.this.mainThreadProceed = true;
          MapInterfaceTest.this.notify();
        }
        event.getRegion().getCache().getLogger().info("*******Main THread Notified *********");
      Thread.sleep(1000);       
        event.getRegion().getCache().getLogger().info("******* After Sleeping 5000 *********");
      }catch(InterruptedException ie) {
        fail("interrupted");
      }
    }
  });
  Thread th = new Thread ( new Runnable() {
     public void run() {
        region.clear();
     }
    
  });
  
  th.start();
   try {
     synchronized (this) {
       if(!this.mainThreadProceed) {
         region.getCache().getLogger().info("*******Main THread is going in wait********");
         this.wait();
       }
     }
     region.getCache().getLogger().info("*******Main THread coming out of wait*********");
     region.put("test","test");
     String str = (String)region.get("test");
     assertNotNull("The put operation has succeeded",str);
   }catch (Exception cwe) {
     fail("The test experienced exception "+cwe);   
   }    
   DistributedTestCase.join(th, 30 * 1000, null);
}
 
Example 18
Source File: DiskRegionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
   * Similar test in case of 'update'
   */
  public void testClearInteractionWithUpdateOperation_Bug37606()
  {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setOverflow(false);
    props.setRolling(false);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    props.setRegionName("IGNORE_EXCEPTION_testClearInteractionWithUpdateOperation_Bug37606");
    final Region region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(
        cache, props, Scope.LOCAL);
    region.create("key1", "value1");
    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
    final Thread th = new Thread(new Runnable() {
      public void run()
      {
        region.put("key1", "value2");
      }
    });
    CacheObserver old = CacheObserverHolder
        .setInstance(new CacheObserverAdapter() {
          public void beforeDiskClear()
          {
         	LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
            th.start();
            System.out.println("FIXME: this thread (2) does not terminate--EVER!");
            DistributedTestCase.staticPause(10 * 1000);
//            try {	
//              DistributedTestCase.join(th, 10 * 1000, null);
//            }
//            catch (Exception e) {
//              DiskRegionJUnitTest.this.exceptionOccured = true;
//              DiskRegionJUnitTest.this.failureCause = e.toString();
//            }
          }
        });
    try {
      region.clear();
      DistributedTestCase.join(th, 30 * 1000, null);
      assertFalse(this.failureCause, this.exceptionOccured);
      //We expect 1 entry to exist, because the clear was triggered before
      //the update
      assertEquals(1,region.size());
      region.close();
      assertEquals(1,DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache,
          props, Scope.LOCAL).size());
    }
    catch (Exception e) {
      fail("Exception not expected but did occur due to " + e);
    }
    finally {
      CacheObserverHolder.setInstance(old);
      LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
    }
  }
 
Example 19
Source File: PartitionedRegionSingleNodeOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void test023UnsupportedOps() throws Exception {
    Region pr = null;
    try {
      pr = PartitionedRegionTestHelper.createPartitionedRegion("testUnsupportedOps", String.valueOf(200), 0);
      
      pr.put(new Integer(1), "one" );
      pr.put(new Integer(2), "two" );
      pr.put(new Integer(3), "three" );
      pr.getEntry("key");
      
      try {
        pr.clear();
        fail("PartitionedRegionSingleNodeOperationTest:testUnSupportedOps() operation failed on a blank PartitionedRegion");
      }
      catch (UnsupportedOperationException expected) {
      }
      
//      try {
//        pr.entries(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
//      try {
//        pr.entrySet(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
      try {
        HashMap data = new HashMap();
        data.put("foo", "bar");
        data.put("bing", "bam");
        data.put("supper", "hero");
        pr.putAll(data);
//        fail("testPutAll() does NOT throw UnsupportedOperationException");
      }
      catch (UnsupportedOperationException onse) {
      }
      
      
//      try {
//        pr.values();
//        fail("testValues() does NOT throw UnsupportedOperationException");
//      }
//      catch (UnsupportedOperationException expected) {
//      }

      
      try {
        pr.containsValue("foo");
      }
      catch (UnsupportedOperationException ex) {
        fail("PartitionedRegionSingleNodeOperationTest:testContainsValue() operation failed");
      }
      
    } finally {
      if (pr!=null) {
        pr.destroyRegion();
      }
    }
  }
 
Example 20
Source File: DiskRegionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
   * As in the clear operation, previously the code was such that Htree Ref was
   * first reset & then the underlying region map got cleared, it was possible
   * for the create op to set the new Htree ref in thread local. Now if clear
   * happened, the entry on which create op is going on was no longer valid, but
   * we would not be able to detect the conflict. The fix was to first clear the
   * region map & then reset the Htree Ref.
   * 
   * @author Asif
   */
  public void testClearInteractionWithCreateOperation_Bug37606()
  {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setOverflow(false);
    props.setRolling(false);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    props.setRegionName("IGNORE_EXCEPTION_testClearInteractionWithCreateOperation_Bug37606");
    final Region region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(
        cache, props, Scope.LOCAL);
    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
    final Thread th = new Thread(new Runnable() {
      public void run()
      {
        region.create("key1", "value1");
      }
    });
    CacheObserver old = CacheObserverHolder
        .setInstance(new CacheObserverAdapter() {
          public void beforeDiskClear()
          {
            th.start();
            DistributedTestCase.staticPause(7 * 1000);
            System.out.println("FIXME: this thread does not terminate--EVER!");
//            try {
//              DistributedTestCase.join(th, 7 * 1000, null);
//            }
//            catch (Exception e) {
//              DiskRegionJUnitTest.this.exceptionOccured = true;
//              DiskRegionJUnitTest.this.failureCause = e.toString();
//            }
          }
        });
    try {
      region.clear();
      DistributedTestCase.join(th, 30 * 1000, null);
      assertFalse(this.failureCause, this.exceptionOccured);
      //We expect 1 entry to exist, because the clear was triggered before
      //the update
      assertEquals(1, region.size());
      region.close();
      assertEquals(1, DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache,
          props, Scope.LOCAL).size());
    }
    catch (Exception e) {
      logWriter.error("Test failed", e);
    }
    finally {
      CacheObserverHolder.setInstance(old);
      LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
    }
  }