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

The following examples show how to use com.gemstone.gemfire.cache.Region#close() . 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: PRQueryJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the execution of query on a PartitionedRegion created on a single
 * data store. <br>
 * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects
 * in cache. 3. Fires queries on the data and verifies the result.
 * 
 * @throws Exception
 */
public void testQueryOnSingleDataStore() throws Exception
{
  Region region = PartitionedRegionTestHelper.createPartitionedRegion(
      regionName, "100", 0);
  PortfolioData[] portfolios = new PortfolioData[100];
  for (int j = 0; j < 100; j++) {
    portfolios[j] = new PortfolioData(j);
  }
  try {
    populateData(region, portfolios);

    String queryString = "ID < 5";
    SelectResults resSet = region.query(queryString);
    Assert.assertTrue(resSet.size() == 5);

    queryString = "ID > 5 and ID <=15";
    resSet = region.query(queryString);
    Assert.assertTrue(resSet.size() == 10);
  } finally { 
    region.close();
  }
}
 
Example 2
Source File: PRQueryJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the execution of query on a PartitionedRegion created on a single
 * data store. <br>
 * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects
 * in cache. 3. Fires queries on the data and verifies the result.
 * 
 * @throws Exception
 */
public void testQueryOnSingleDataStore() throws Exception
{
  Region region = PartitionedRegionTestHelper.createPartitionedRegion(
      regionName, "100", 0);
  PortfolioData[] portfolios = new PortfolioData[100];
  for (int j = 0; j < 100; j++) {
    portfolios[j] = new PortfolioData(j);
  }
  try {
    populateData(region, portfolios);

    String queryString = "ID < 5";
    SelectResults resSet = region.query(queryString);
    Assert.assertTrue(resSet.size() == 5);

    queryString = "ID > 5 and ID <=15";
    resSet = region.query(queryString);
    Assert.assertTrue(resSet.size() == 10);
  } finally { 
    region.close();
  }
}
 
Example 3
Source File: HDFSRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void tearDown() throws Exception {
  for (Region r : cache.rootRegions()) {
    if (r != null) {
      r.close();
    }
  }

  if (cache.getRegion(getName()) != null) {
    cache.getRegion(getName()).destroyRegion();
  }
  DiskStore ds = cache.findDiskStore(null);
  if (ds != null) {
    ds.destroy();
  }
  
  ((HDFSStoreImpl)hdfsStore).getFileSystem().delete(new Path(hdfsStore.getHomeDir()), true);
}
 
Example 4
Source File: PRQueryNumThreadsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testOrderByQuery() throws Exception
{
  Region region = PartitionedRegionTestHelper.createPartitionedRegion(
      regionName, "100", 0);
  String[] values = new String[100];
  for (int j = 0; j < 100; j++) {
    values[j] = new String(""+ j);
  }
  PRQueryProcessor.TEST_NUM_THREADS = 10;
  try {
    populateData(region, values);

    String queryString = "Select distinct p from /" + region.getName() + " p order by p";
    Query query = region.getCache().getQueryService().newQuery(queryString);
    SelectResults sr = (SelectResults)query.execute();

    Assert.assertTrue(sr.size() == 100);
  } finally {
    PRQueryProcessor.TEST_NUM_THREADS = 0;
    region.close();
  }
}
 
Example 5
Source File: RegionManagementDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Closes Fixed Partition region
 *
 * @param vm
 */
protected void closeFixedPartitionRegion(final VM vm) {
  SerializableRunnable closeParRegion = new SerializableRunnable(
      "Close Fixed Partition region") {
    public void run() {
      GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
      ManagementService service = getManagementService();
      getLogWriter().info("Closing Fixed Par Region");
      Region region = cache.getRegion(FIXED_PR_PATH);
      region.close();
      RegionMXBean bean = null;
      try {
        bean = service.getLocalRegionMBean(FIXED_PR_PATH);
      } catch (ManagementException mgtEx) {
        getLogWriter().info(
            "<ExpectedString> Expected Exception  "
                + mgtEx.getLocalizedMessage() + "</ExpectedString> ");
      }
      assertNull(bean);
    }
  };
  vm.invoke(closeParRegion);
}
 
Example 6
Source File: QueryFunctionExecTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void HydraTask_close_rebalancePR() {
  Region aRegion = CacheFactory.getAnyInstance().getRegion(REGION_NAME + 1);

  RegionAttributes attrs = aRegion.getAttributes();
  PartitionAttributes pAttrs = attrs.getPartitionAttributes();
  
  int oldLocalMaxMem = pAttrs.getLocalMaxMemory();
  
  Log.getLogWriter().info("Initial local max memory = " + oldLocalMaxMem);
  
  AttributesFactory factory = new AttributesFactory(attrs);
  factory.setPartitionAttributes(attrs.getPartitionAttributes());
  PartitionAttributesFactory paFactory = new PartitionAttributesFactory(attrs.getPartitionAttributes());
  
  paFactory.setLocalMaxMemory(0);
  
  aRegion.close();
  factory.setPartitionAttributes(paFactory.create());
  aRegion = RegionHelper.createRegion(REGION_NAME + 1, factory.create());
  Log.getLogWriter().info(
      "Created partitioned region " + REGION_NAME + 1);
  
  ParRegUtil.doRebalance();
  
  aRegion.close();
  paFactory.setLocalMaxMemory(oldLocalMaxMem);
  factory.setPartitionAttributes(paFactory.create());
  aRegion = RegionHelper.createRegion(REGION_NAME + 1, factory.create());
  Log.getLogWriter().info(
      "Created partitioned region " + REGION_NAME + 1);

}
 
Example 7
Source File: SingleWriteSingleReadRegionQueue.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  Region r = getRegion();
  if (r != null && !r.isDestroyed()) {
    try {
      r.close();
    } catch (RegionDestroyedException e) {
    }
  }
}
 
Example 8
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testTxDistributedRegion() throws Exception {
  AttributesFactory attr = new AttributesFactory();
  attr.setScope(Scope.DISTRIBUTED_ACK);
  Region region = cache.createRegion("DistributedRegion", attr.create());
  checkOpRejection(region, true, true);
  region.close();
  assertEquals(0 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
 
Example 9
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testPutsLocalRegion() throws Exception{
  AttributesFactory attr = new AttributesFactory();
  attr.setScope(Scope.LOCAL);
  Region region = cache.createRegion("localRegion", attr.create());
  checkOpRejection(region, false, true);
  region.close();
  assertEquals(0 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
 
Example 10
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testPutsRejectedSubRegion() throws Exception {
  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.LOCAL);
  Region subRegion = cache.createRegion("local1", factory.create())
          .createSubregion("sub1", factory.create());
  checkOpRejection(subRegion, false, true);
  subRegion.close();
  assertEquals(1 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());      //root region is still present
}
 
Example 11
Source File: PersistentPartitionedRegionTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void closePR(VM vm0) {
  SerializableRunnable close = new SerializableRunnable("Close Cache") {
    public void run() {
      Cache cache = getCache();
      Region region = cache.getRegion(PR_REGION_NAME);
      region.close();
    }
  };
  
  vm0.invoke(close);
}
 
Example 12
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testPutsPartitionedRegion() throws Exception{
  PartitionAttributes pa = new PartitionAttributesFactory().
      setRedundantCopies(0).setTotalNumBuckets(3).create();    
  Region region = new RegionFactory().setPartitionAttributes(pa).create("parReg");
  checkOpRejection(region, false, true);
  region.close();
  assertEquals(0 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
 
Example 13
Source File: ShutdownAllDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void closeRegion(VM vm, final String regionName) {
  SerializableRunnable close = new SerializableRunnable() {
    public void run() {
      Cache cache = getCache();
      Region region = cache.getRegion(regionName);
      region.close();
    }
  };
  
  vm.invoke(close);
}
 
Example 14
Source File: PartitionedRegionAsSubRegionDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void run2() throws CacheException
{
  Cache cache = getCache();
  Region parentRegion = cache.getRegion(Region.SEPARATOR + parentRegionName
      + Region.SEPARATOR + childRegionName);
  parentRegion.close();
}
 
Example 15
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testTxLocalRegion() throws Exception {
  AttributesFactory attr = new AttributesFactory();
  attr.setScope(Scope.LOCAL);
  Region region = cache.createRegion("localRegion", attr.create());
  checkOpRejection(region, true, true);
  region.close();
  assertEquals(0 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
 
Example 16
Source File: MemoryMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * creates a distributed region and invokes criticalThresholdReached
 * then does a put to verify that the put is rejected
 */
public void testPutsRejectionDistributedRegion() throws Exception {
  AttributesFactory attr = new AttributesFactory();
  attr.setScope(Scope.DISTRIBUTED_ACK);
  Region region = cache.createRegion("DistributedRegion", attr.create());
  checkOpRejection(region, false, true);
  region.close();
  assertEquals(0 + SYSTEM_LISTENERS, cache.getResourceManager(false).
      getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
 
Example 17
Source File: rmdir.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void remove_local(String regionPath)
{
	if (regionPath == null) {
		return;
	}
	
	String currentPath = gfsh.getCurrentPath();
	String fullPath = gfsh.getFullPath(regionPath, currentPath);
	if (fullPath == null) {
		gfsh.println("Error: invalid region path");
	} else if (fullPath.equals("/")) {
		gfsh.println("Error: cannot remove top level");
	} else {
		Region region = gfsh.getCache().getRegion(fullPath);
		if (region == null) {
			gfsh.println("Error: undefined region path " + fullPath);
			return;
		} 
		region.close();
		
		// correct the current path if the removed region path
		// lies in the current path
		String currentSplit[] = currentPath.split("/");
		Cache cache = gfsh.getCache();
		Region currentRegion = null;
		if (currentSplit.length > 1) {
			currentRegion = region = cache.getRegion(currentSplit[1]);
			if (region != null) {
				for (int i = 2; i < currentSplit.length; i++) {
					region = region.getSubregion(currentSplit[i]);
					if (region == null) {
						break;
					}
					currentRegion = region;
				}
			}
		}
		if (currentRegion == null) {
			gfsh.setCurrentPath("/");
		} else {
			gfsh.setCurrentPath(currentRegion.getFullPath());
		}
		gfsh.setCurrentRegion(currentRegion);
		
		gfsh.println("Region removed from local VM: " + regionPath);
	}
}
 
Example 18
Source File: ParallelGatewaySenderOperationsDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void closeRegion(String regionName) {
  Region r = cache.getRegion(Region.SEPARATOR + regionName);
  assertNotNull(r);
  r.close();
}
 
Example 19
Source File: ConcurrentParallelGatewaySenderOperation_2_DUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void closeRegion(String regionName) {
  Region r = cache.getRegion(Region.SEPARATOR + regionName);
  assertNotNull(r);
  r.close();
}
 
Example 20
Source File: rmdir.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void remove_local(String regionPath)
{
	if (regionPath == null) {
		return;
	}
	
	String currentPath = gfsh.getCurrentPath();
	String fullPath = gfsh.getFullPath(regionPath, currentPath);
	if (fullPath == null) {
		gfsh.println("Error: invalid region path");
	} else if (fullPath.equals("/")) {
		gfsh.println("Error: cannot remove top level");
	} else {
		Region region = gfsh.getCache().getRegion(fullPath);
		if (region == null) {
			gfsh.println("Error: undefined region path " + fullPath);
			return;
		} 
		region.close();
		
		// correct the current path if the removed region path
		// lies in the current path
		String currentSplit[] = currentPath.split("/");
		Cache cache = gfsh.getCache();
		Region currentRegion = null;
		if (currentSplit.length > 1) {
			currentRegion = region = cache.getRegion(currentSplit[1]);
			if (region != null) {
				for (int i = 2; i < currentSplit.length; i++) {
					region = region.getSubregion(currentSplit[i]);
					if (region == null) {
						break;
					}
					currentRegion = region;
				}
			}
		}
		if (currentRegion == null) {
			gfsh.setCurrentPath("/");
		} else {
			gfsh.setCurrentPath(currentRegion.getFullPath());
		}
		gfsh.setCurrentRegion(currentRegion);
		
		gfsh.println("Region removed from local VM: " + regionPath);
	}
}