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

The following examples show how to use com.gemstone.gemfire.cache.Region#destroy() . 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: QueryAndJtaTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testIndexOnCommitForDestroy() throws Exception {
  AttributesFactory af = new AttributesFactory();
  af.setDataPolicy(DataPolicy.REPLICATE);
  Region region = cache.createRegion("sample", af.create());
  qs.createIndex("foo", IndexType.FUNCTIONAL, "age", "/sample");
  Context ctx = cache.getJNDIContext();
  UserTransaction utx = (UserTransaction)ctx.lookup("java:/UserTransaction");
  Integer x = new Integer(0);
  utx.begin();
  region.create(x, new Person("xyz", 45));
  utx.commit();
  Query q = qs.newQuery("select * from /sample where age < 50");
  assertEquals(1, ((SelectResults)q.execute()).size());
  Person dsample = (Person)CopyHelper.copy(region.get(x));
  dsample.setAge(55);
  utx.begin();
  region.destroy(x);
  utx.commit();
  System.out.println((region.get(x)));
  assertEquals(0, ((SelectResults) q.execute()).size());
}
 
Example 2
Source File: HAConflationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private CacheSerializableRunnable destroyFromServer(final String key)
{
  CacheSerializableRunnable performDestroy = new CacheSerializableRunnable(
      "performDestroy") {
    public void run2() throws CacheException
    {
      Region region = cache.getRegion(Region.SEPARATOR + regionName);
      assertNotNull(region);
      region.destroy(key);
      cache.getLogger().info("done destroy successfully");

    }
  };

  return performDestroy;
}
 
Example 3
Source File: ConflationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * destroy marker
 *
 */
public static void destroyMarker()
{
  try {
    Region region1 = cache.getRegion(Region.SEPARATOR +REGION_NAME1);
    Region region2 = cache.getRegion(Region.SEPARATOR +REGION_NAME2);
    region1.destroy(MARKER);
    region2.destroy(MARKER);
    count =0;

  }
  catch (Exception e) {
    e.printStackTrace();
    fail("test failed due to exception in destroy ");
  }
}
 
Example 4
Source File: PersistentPartitionedRegionTestBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void invalidateData(VM vm, final int startKey, final int endKey) {
  SerializableRunnable createData = new SerializableRunnable() {
    
    public void run() {
      Cache cache = getCache();
      Region region = cache.getRegion(PR_REGION_NAME);
      
      for(int i =startKey; i < endKey; i++) {
        region.destroy(i);
        region.create(i, null);
        region.invalidate(i);
      }
    }
  };
  vm.invoke(createData);
}
 
Example 5
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reader wan site destroys all the keys in its region
 */
public static void readerDestroyAllKeysTask() {

  Region region = RegionHelper.getRegion(REGION_NAME);

  Iterator iterator = region.entrySet(false).iterator();
  Region.Entry entry = null;
  Object key = null;

  while (iterator.hasNext()) {
    entry = (Region.Entry)iterator.next();
    key = entry.getKey();

    try {
      region.destroy(key);
    }
    catch (EntryNotFoundException e) {
      Log.getLogWriter().info("Entry Not found.");
    }
  }

  if (region.isEmpty()) {
    Log.getLogWriter().info(
        "Completed the destroy operation for all the keys in the region");
  }
  else {
    throw new TestException(
        "Region is supposed to be empty but that is not the case");
  }

}
 
Example 6
Source File: WANTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void doDestroys(String regionName, int keyNum) {
  Region r = cache.getRegion(Region.SEPARATOR + regionName);
  assertNotNull(r);
  for (long i = 0; i < keyNum; i++) {
    r.destroy(i);
  }
}
 
Example 7
Source File: HDFSRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void test150ContainsValue() {
  Region<Integer, String> r = createRegion(getName());
  for (int i=0; i<100; i++) {
    r.put(i, "value"+i);
  }
  clearBackingCHM(r);
  assertTrue(r.containsValue("value45"));
  r.destroy(45);
  assertFalse(r.containsValue("value45"));
  r.invalidate(64);
  assertFalse(r.containsValue("value64"));
}
 
Example 8
Source File: HDFSRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void test140ContainsKey() {
  Region<Integer, String> r = createRegion(getName());
  for (int i=0; i<100; i++) {
    r.put(i, "value"+i);
  }
  clearBackingCHM(r);
  assertTrue(r.containsKey(80));
  r.destroy(80);
  assertFalse(r.containsKey(80));
  r.invalidate(64);
  assertTrue(r.containsKey(64));
}
 
Example 9
Source File: IndexCreationTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creation of index on a path derived from Region.Entry object obtained
 * via entrySet , fails as that function was not supported in the
 * QRegion & DummyQRegion
 * @author Asif
 */
public void testBug43519() {
  QueryService qs;
  qs = CacheUtils.getQueryService();
  try{
      Index index = qs.createIndex("shortIndex", IndexType.FUNCTIONAL, "p.shortID","/portfolios p");         
      Region rgn = CacheUtils.getRegion("/portfolios");
      for (int i=1; i <= 10; i++) {
        String key ="" + i;
        Portfolio p = new Portfolio(i);
        p.shortID = new Short(key);
        // addToIndex
        rgn.put(key, p);
        // updateIndex
        rgn.put(key, p);
        if (i %2 == 0) {
          // destroy from index.
          rgn.destroy(key);
        }
      }
      Query qr = qs.newQuery("Select p.shortID from /portfolios p where p.shortID < 5");
      SelectResults sr = (SelectResults)qr.execute();
      assertEquals(sr.size(),2);
  }catch(Exception e) {
    CacheUtils.getLogger().error(e);
    fail("Test failed because of exception. e="+e);        
  }     
}
 
Example 10
Source File: CQStatisticsTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void deleteValues(int size) {
  Region region1 = testInstance.aRegion;
  for (int i = 1; i <= size; i++) {
    region1.destroy(KEY+i);
  }
  Log.getLogWriter().info("### Number of Entries in Region :" + region1.keys().size());
}
 
Example 11
Source File: NewRegionAttributesDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Performs DESTROY operations on the test-region and fails if any Exception
 * occurs during the DESTROYs
 */
public static void doDestroy()
{
  Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  for (int i = 0; i < TOTAL_PUTS; i++) {
    try {
      region1.destroy("key-" + i);
    }
    catch (Exception e) {
      fail("Test failed due to unexpected exception during DESTROYs : " + e);
    }
  }
}
 
Example 12
Source File: OffHeapManagementDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a destroy operation.
 * @param key the region entry to destroy.
 * @param regionName a region name.
 */
protected void doDestroy(Object key, String regionName) {
  Region region =  getCache().getRegion(regionName);
  assertNotNull(region);
  
  region.destroy(key);
}
 
Example 13
Source File: OffHeapStressTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void makeRoom(int percent) {
  Log.getLogWriter().info("Destroying " + percent + " percent of entries in each region");
  Set<Region<?, ?>> regionSet = getAllRegions();
  for (Region aRegion: regionSet) {
    int numToDestroy = (int) (aRegion.size() * (percent * 0.01));
    Log.getLogWriter().info("Destroying " + numToDestroy + " in " + aRegion.getFullPath() + " of size " + aRegion.size());
    for (Object key: aRegion.keySet()) {
      aRegion.destroy(key);
    }
  }
}
 
Example 14
Source File: HDFSRegionOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void test150ContainsValue() {
  Region<Integer, String> r = createRegion(getName());
  for (int i=0; i<100; i++) {
    r.put(i, "value"+i);
  }
  clearBackingCHM(r);
  assertTrue(r.containsValue("value45"));
  r.destroy(45);
  assertFalse(r.containsValue("value45"));
  r.invalidate(64);
  assertFalse(r.containsValue("value64"));
}
 
Example 15
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reader wan site destroys all the keys in its region
 */
public static void readerDestroyAllKeysTask() {

  Region region = RegionHelper.getRegion(REGION_NAME);

  Iterator iterator = region.entrySet(false).iterator();
  Region.Entry entry = null;
  Object key = null;

  while (iterator.hasNext()) {
    entry = (Region.Entry)iterator.next();
    key = entry.getKey();

    try {
      region.destroy(key);
    }
    catch (EntryNotFoundException e) {
      Log.getLogWriter().info("Entry Not found.");
    }
  }

  if (region.isEmpty()) {
    Log.getLogWriter().info(
        "Completed the destroy operation for all the keys in the region");
  }
  else {
    throw new TestException(
        "Region is supposed to be empty but that is not the case");
  }

}
 
Example 16
Source File: QueryIndexDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void doDestroy() {
  Region region = CacheUtil.getRegion("portfolios");
  if(region == null) {
    hydra.Log.getLogWriter().info("REGION IS NULL");
  }
  try {
    region.destroy("2");
    region.destroy("3");
    region.destroy("4");
  } catch(Exception e) {
    fail("Caught exception while trying to do put operation", e);
  }
}
 
Example 17
Source File: SnapshotTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Destroy an entry in the given region.
 *
 *  @param aRegion The region to use for destroying an entry.
 *  @param key The key to destroy.
 *  @param isLocalDestroy True if the destroy should be local, false otherwise.
 */
protected void destroyEntry(Region aRegion, Object key, boolean isLocalDestroy) {
  String callback = destroyCallbackPrefix + ProcessMgr.getProcessId();
  if (isLocalDestroy) { // do a local destroy
    if (TestConfig.tab().getRandGen().nextBoolean()) { // local destroy with callback
      Log.getLogWriter().info("destroyEntry: local destroy for " + key + " callback is " + callback
          + ", region is " + aRegion.getFullPath());
      aRegion.localDestroy(key, callback);
      Log.getLogWriter().info("destroyEntry: done with local destroy for " + key);
    } else { // local destroy without callback
      Log.getLogWriter().info("destroyEntry: local destroy for " + key + ", region is " + aRegion.getFullPath());
      aRegion.localDestroy(key);
      Log.getLogWriter().info("destroyEntry: done with local destroy for " + key);
    }
  } else { // do a distributed destroy
    if (TestConfig.tab().getRandGen().nextBoolean()) { // destroy with callback
      Log.getLogWriter().info("destroyEntry: destroying key " + key + " callback is " + callback
          + ", region is " + aRegion.getFullPath());
      aRegion.destroy(key, callback);
      Log.getLogWriter().info("destroyEntry: done destroying key " + key);
    } else { // destroy without callback
      Log.getLogWriter().info("destroyEntry: destroying key " + key + ", region is " + aRegion.getFullPath());
      aRegion.destroy(key);
      Log.getLogWriter().info("destroyEntry: done destroying key " + key);
    }
  }
}
 
Example 18
Source File: QueryIndexDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void createAndLoadOverFlowRegions(String vmName, final Boolean createRegions, final Boolean loadRegions) throws Exception {
  Cache cache = null;
  String[] regionNames = new String[] {
      "replicateOverFlowRegion",
      "replicatePersistentOverFlowRegion",
      "prOverFlowRegion",
      "prPersistentOverFlowRegion",
  };

  if ((cache = CacheUtil.getCache()) == null) {
    QueryIndexDUnitTest qidt = new QueryIndexDUnitTest("temp");
    cache = qidt.createCache();
  }
  
  hydra.Log.getLogWriter().info("CreateAndLoadOverFlowRegions() with vmName " + vmName 
      + " createRegions: " + createRegions + " And LoadRegions: " + loadRegions);
  
  if (createRegions.booleanValue()) {
    for (int i=0; i < regionNames.length; i++){
      hydra.Log.getLogWriter().info("Started creating region :" + regionNames[i]);
      String diskStore = regionNames[i] + vmName + "DiskStore";
      hydra.Log.getLogWriter().info("Setting disk store to: " + diskStore);
      cache.createDiskStoreFactory().create(diskStore);
      try {
        AttributesFactory attributesFactory = new AttributesFactory();
        //attributesFactory.setValueConstraint(Portfolio.class);
        attributesFactory.setDiskStoreName(diskStore);
        attributesFactory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(
            10, EvictionAction.OVERFLOW_TO_DISK));
        if (i == 0){
          attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
        } else if(i == 1){
          attributesFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
        } else if (i == 2){
          attributesFactory.setDataPolicy(DataPolicy.PARTITION);
        } else {
          attributesFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
        }
        cache.createRegion(regionNames[i], attributesFactory.create());
        hydra.Log.getLogWriter().info("Completed creating region :" + regionNames[i]);
      }
      catch (Exception e) {
        fail("Could not create region" + regionNames[i], e);
      }
    }
  }
  Region region = null;
  int numObjects = 50;
  if (loadRegions.booleanValue()) {      
    for (int i=0; i < regionNames.length; i++){
      region = cache.getRegion(regionNames[i]);
      // If its just load, try destroy some entries and reload.
      if (!createRegions.booleanValue()){
        hydra.Log.getLogWriter().info("Started destroying region entries:" + regionNames[i]);
        for (int cnt=0; cnt < numObjects/3; cnt++){
          region.destroy(new Portfolio(cnt * 2));
        } 
      }
      
      hydra.Log.getLogWriter().info("Started Loading region :" + regionNames[i]);
      for (int cnt=0; cnt < numObjects; cnt++){
        region.put(new Portfolio(cnt), new Portfolio(cnt));
      }
      hydra.Log.getLogWriter().info("Completed loading region :" + regionNames[i]);
    }
  }    
}
 
Example 19
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Destroys numEntries randomKeys in REGION_NAME */
public static void destroyRandomEntriesTask() {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set aSet = region.keys();

  if (aSet.size() == 0) {
     Log.getLogWriter().info("destroyRandomEntryTask: No keys in region");
     return;
  }

  int numEntries = CacheClientPrms.getNumEntries();
  for (int i = 0; i < numEntries; i++) {
    aSet = region.keys();
    if (aSet.size() == 0) {
      Log.getLogWriter().info("destroyRandomEntriesTask: No keys remain to destroy");
      return;
    }

    Object[] keyList = aSet.toArray();
    int index = rand.nextInt(aSet.size() - 1);
    Log.getLogWriter().info("Number of keys in region = " + aSet.size());
    try {
       Object key = keyList[index];
       Log.getLogWriter().info("Destroying key " + key + " from region " + region.getName());
       if (TestConfig.tab().getRandGen().nextBoolean()) {
       region.destroy(key);
       } else {
         boolean removed = region.remove(key, region.get(key));
         if (!removed) { // might happen with concurrent execution, force destroy
           region.destroy(key);
         }
       }
       Log.getLogWriter().info("Done destroying key " + key + " from region " + region.getName());
    } catch (Exception e) {
       throw new TestException("destroyRandomEntryTask throws " + e + " " + TestHelper.getStackTrace(e));
    }
  }

  // allow time for distribution
  int sleepMs = CacheClientPrms.getSleepSec() * 1000;
  MasterController.sleepForMs( sleepMs );
}
 
Example 20
Source File: TransactionTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test commit with conflict.
 */
public void testCommitWithConflicts() throws Exception {
  Connection conn = getConnection();
  Statement st = conn.createStatement();
  st.execute("create schema tran");
  st.execute("Create table tran.t1 (c1 int not null , c2 int not null, "
      + "primary key(c1)) replicate" +getSuffix());
  conn.commit();
  conn.setTransactionIsolation(getIsolationLevel());
  conn.setAutoCommit(false);
  st.execute("insert into tran.t1 values (10, 1)");
  Cache cache = Misc.getGemFireCache();
  final TXManagerImpl txMgrImpl = (TXManagerImpl)cache
      .getCacheTransactionManager();
  // Region r= cache.getRegion("APP/T1");
  final Region<Object, Object> r = Misc.getRegionForTable("TRAN.T1", true);
  final Object key = getGemFireKey(10, r);
  this.gotConflict = false;
  Thread thread = new Thread(new Runnable() {

    @Override
    public void run() {
      assertNotNull(r);
      txMgrImpl.begin();
      try {
        r.put(key, new SQLInteger(20)); // create a conflict here.
        fail("expected a conflict here");
      } catch (ConflictException ce) {
        gotConflict = true;
      }
      assertNull(r.get(key));
      TXStateInterface txi = txMgrImpl.internalSuspend();
      assertNotNull(txi);

      txMgrImpl.resume(txi);
      txMgrImpl.commit();
    }
  });
  thread.start();
  thread.join();

  conn.commit();
  st.close();

  assertTrue("expected conflict", this.gotConflict);
  this.gotConflict = false;

  // Important : Remove the key - value pair.
  r.destroy(key);

  Statement st2 = conn.createStatement();
  st2.execute("insert into tran.t1 values (10, 10)");
  conn.commit();
  ResultSet rs = st2.executeQuery("select * from tran.t1");
  int numRow = 0;
  while (rs.next()) {
    numRow++;
    assertEquals("Primary Key coloumns should be 10 ", 10, rs.getInt(1));
    assertEquals("Second columns should be 10 , ", 10, rs.getInt(2));
  }
  assertEquals("ResultSet should have two rows ", 1, numRow);

  rs.close();
  st2.close();
  conn.commit();
  conn.close();
}