Java Code Examples for com.gemstone.gemfire.cache.Region#invalidate()
The following examples show how to use
com.gemstone.gemfire.cache.Region#invalidate() .
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: HAConflationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private CacheSerializableRunnable invalidateFromServer(final String key) { CacheSerializableRunnable performInvalidate = new CacheSerializableRunnable( "invalidateFromServer") { public void run2() throws CacheException { Region region = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(region); region.invalidate(key); cache.getLogger().info("done invalidate() successfully"); } }; return performInvalidate; }
Example 2
Source File: RegionEntryOperations.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
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 3
Source File: QueryFunctionExecTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Invalidate object * @param aRegion */ protected void invalidateObject(Region aRegion) { Set aSet = aRegion.keySet(); if (aSet.size() == 0) { Log.getLogWriter().info("invalidateObject: No names in region"); return; } Iterator it = aSet.iterator(); Object key = null; if (it.hasNext()) { key = it.next(); } else { // has been destroyed cannot continue Log.getLogWriter().info("invalidateObject: Unable to get key from region"); return; } boolean containsValue = aRegion.containsValueForKey(key); boolean alreadyInvalidated = !containsValue; if (!alreadyInvalidated) { aRegion.invalidate(key); } }
Example 4
Source File: ConcCQMultRegionsClient.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: DiskRegionJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * If IOException occurs while invalidating an entry in a persist only synch mode, * DiskAccessException should occur & region should be destroyed * * @throws Exception */ private void entryInvalidateInSynchPersistTypeForIOExceptionCase(Region region) throws Exception { try { region.create("key1", "value1"); // Get the oplog handle & hence the underlying file & close it FileChannel oplogFileChannel = ((LocalRegion)region).getDiskRegion() .testHook_getChild().getFileChannel(); oplogFileChannel.close(); try { region.invalidate("key1"); fail("Should have encountered DiskAccessException"); } catch (DiskAccessException dae) { // OK } assertTrue(region.isDestroyed()); region = null; } finally { if (region != null) { region.destroyRegion(); } } }
Example 6
Source File: PersistentPartitionedRegionTestBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
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 7
Source File: CacheServerTransactionsDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void invalidateInTransaction(String server) throws Exception { Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r1); cache.getCacheTransactionManager().begin(); if (server.equals("server1")) { r1.invalidate(k1); assertNull(r1.getEntry(k1).getValue()); //assertEquals(r1.getEntry(k2).getValue(), server1_k2); } else if (server.equals("server2")) { r1.invalidate(k1); assertNull(r1.getEntry(k1).getValue()); //assertEquals(r1.getEntry(k2).getValue(), server2_k3); } }
Example 8
Source File: PersistentPartitionedRegionWithTransactionDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * @param vm0 * @param i * @param numBuckets * @param string */ private void createDataWithRollback(VM vm, final int startKey, final int endKey, final String value) { SerializableRunnable createData = new SerializableRunnable() { public void run() { Cache cache = getCache(); CacheTransactionManager tx = cache.getCacheTransactionManager(); Region region = cache.getRegion(PR_REGION_NAME); for(int i =startKey; i < endKey; i++) { tx.begin(); region.put(i, value); region.destroy(i + 113, value); region.invalidate(i + 113 * 2, value); tx.rollback(); } } }; vm.invoke(createData); }
Example 9
Source File: ClientSnapshotDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testInvalidate() throws Exception { SerializableCallable invalid = new SerializableCallable() { @Override public Object call() throws Exception { Region<Integer, MyObject> r = getCache().getRegion("clienttest"); r.put(1, new MyObject(1, "invalidate")); r.invalidate(1); File f = new File(getDiskDirs()[0], "client-invalidate.snapshot"); r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE); return null; } }; Host.getHost(0).getVM(3).invoke(invalid); assertTrue(region.containsKey(1)); assertFalse(region.containsValueForKey(1)); assertNull(region.get(1)); }
Example 10
Source File: ClientInterestNotifyDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Do 2 puts, 1 invalidate and 1 destroy for a key "key-1" */ public static void doEntryOps() { try { getLogWriter().info("Putting entries..."); Cache cacheClient = GemFireCacheImpl.getInstance(); Region r1 = cacheClient.getRegion(Region.SEPARATOR +REGION_NAME1); Region r2 = cacheClient.getRegion(Region.SEPARATOR +REGION_NAME2); Region r3 = cacheClient.getRegion(Region.SEPARATOR +REGION_NAME3); r1.put("key-1", "11"); r2.put("key-1", "11"); r3.put("key-1", "11"); r1.put("key-1", "22"); r2.put("key-1", "22"); r3.put("key-1", "22"); r1.invalidate("key-1"); r2.invalidate("key-1"); r3.invalidate("key-1"); r1.destroy("key-1"); r2.destroy("key-1"); r3.destroy("key-1"); } catch (Exception ex) { ex.printStackTrace(); fail("failed while region doing ops", ex); } }
Example 11
Source File: HDFSRegionOperationsJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void test110Size() { Region<Integer, String> r = createRegion(getName()); for (int i=0; i<100; i++) { r.put(i, "value"+i); } clearBackingCHM(r); assertEquals(100, r.size()); r.destroy(45); assertEquals(99, r.size()); r.invalidate(55); r.invalidate(65); assertEquals(99, r.size()); }
Example 12
Source File: BridgeWriterMiscDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Test for bug 43407, where LRU in the client caused an entry to be * evicted with DESTROY(), then the client invalidated the entry and * did a get(). After the get() the entry was not seen to be in the * client's cache. This turned out to be expected behavior, but we * now have this test to guarantee that the product behaves as expected. */ public void testBug43407() throws Exception { // start server first PORT1 = initServerCache(false); createClientCache(getServerHostName(Host.getHost(0)), PORT1); registerInterestForInvalidatesInBothTheRegions(); Region region = static_cache.getRegion(REGION_NAME1); populateCache(); region.put("invalidationKey", "invalidationValue"); region.localDestroy("invalidationKey"); if (region.containsKey("invalidationKey")) { fail("region still contains invalidationKey"); } region.invalidate("invalidationKey"); if (region.containsKey("invalidationKey")) { fail("this test expects the entry is not created on invalidate() if not there before the operation"); } Object value = region.get("invalidationKey"); if (value != null) { fail("this test expected a null response to get('invalidationKey')"); } if (!region.containsKeyOnServer("invalidationKey")) { fail("expected an entry on the server after invalidation"); } // bug 43407 asserts that there should be an entry, but the product does not // do this. This verifies that the product does not behave as asserted in that bug if (region.containsKey("invalidationKey")) { fail("expected no entry after invalidation when entry was not in client but was on server"); } }
Example 13
Source File: HAEventIdPropagationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * does an invalidate and return the eventid generated. Eventid is caught in * the listener and stored in a static variable* */ public static Object invalidateKey1() { try { Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(region); region.invalidate("key1"); return eventId; } catch (Exception e) { fail("put failed due to " + e); } return null; }
Example 14
Source File: NewRegionAttributesDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Performs INVALIDATES operations on the test-region and fails if any * Exception occurs during the INVALIDATESs */ public static void doInvalidates() { Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME); for (int i = 0; i < TOTAL_PUTS; i++) { try { region1.invalidate("key-" + i); } catch (Exception e) { fail("Test failed due to unexpected exception during INVALIDATESs : " + e); } } }
Example 15
Source File: HDFSRegionOperationsJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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 16
Source File: KeyCallbackResolverTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void invalidate(Region aRegion, Object keyName) { Object key = getKeyWrapper(keyName); Object callbackArg = getCallBackWrapper(keyName); Log.getLogWriter().info( "Invalidating " + key + " in the region " + aRegion.getName()); aRegion.invalidate(key, callbackArg); }
Example 17
Source File: DeltaPropagationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static void invalidateDelta() { try { Region r = cache.getRegion("/" + regionName); assertNotNull(r); r.invalidate(DELTA_KEY); } catch (Exception ex) { fail("failed in invalidateDelta()", ex); } }
Example 18
Source File: ParRegColocation.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void invalidate(Region aRegion, Object key) { Log.getLogWriter().info( "Invalidating " + key + "in the region " + aRegion.getName()); checkContainsValueForKey(aRegion, key, true, "before invalidate"); aRegion.invalidate(key); }
Example 19
Source File: DiskRegionAsyncRecoveryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private void invalidateEntries(Region region, int start, int end) { for(int i = start; i < end ; i++) { region.invalidate(i); } }
Example 20
Source File: DeltaTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** Invalidate an entry in the given region. * * @param aRegion The region to use for invalidating an entry. * @param isLocalInvalidate True if the invalidate should be local, false otherwise. */ protected void invalidateEntry(Region aReg, boolean isLocalInvalidate) { int beforeSize = aReg.size(); Object key = getExistingKey(aReg, uniqueKeys, numThreadsInClients); if (key == null) { if (isSerialExecution && (beforeSize != 0)) throw new TestException("getExistingKey returned " + key + ", but region size is " + beforeSize); Log.getLogWriter().info("invalidateEntry: No keys in region"); return; } boolean containsKey = aReg.containsKey(key); boolean containsValueForKey = aReg.containsValueForKey(key); Log.getLogWriter().info("containsKey for " + key + ": " + containsKey); Log.getLogWriter().info("containsValueForKey for " + key + ": " + containsValueForKey); try { String callback = invalidateCallbackPrefix + ProcessMgr.getProcessId(); if (isLocalInvalidate) { // do a local invalidate if (TestConfig.tab().getRandGen().nextBoolean()) { // local invalidate with callback Log.getLogWriter().info("operation for " + key + ", invalidateEntry: local invalidate for " + key + " callback is " + callback); aReg.localInvalidate(key, callback); Log.getLogWriter().info("operation for " + key + ", invalidateEntry: done with local invalidate for " + key); } else { // local invalidate without callback Log.getLogWriter().info("operation for " + key + ", invalidateEntry: local invalidate for " + key); aReg.localInvalidate(key); Log.getLogWriter().info("operation for " + key + ", invalidateEntry: done with local invalidate for " + key); } } else { // do a distributed invalidate if (TestConfig.tab().getRandGen().nextBoolean()) { // invalidate with callback Log.getLogWriter().info("operation for " + key + ", invalidateEntry: invalidating key " + key + " callback is " + callback); aReg.invalidate(key, callback); Log.getLogWriter().info("operation for " + key + ", invalidateEntry: done invalidating key " + key); } else { // invalidate without callback Log.getLogWriter().info("operation for " + key + ", invalidateEntry: invalidating key " + key); aReg.invalidate(key); Log.getLogWriter().info("operation for " + key + ", invalidateEntry: done invalidating key " + key); } } // validation if (isSerialExecution || uniqueKeys) { // record the current state regionSnapshot.put(key, null); } } catch (com.gemstone.gemfire.cache.EntryNotFoundException e) { if (isSerialExecution || uniqueKeys) throw new TestException(TestHelper.getStackTrace(e)); else { Log.getLogWriter().info("Caught " + e + " (expected with concurrent execution); continuing with test"); return; } } }