Java Code Examples for com.gemstone.gemfire.cache.Region#size()
The following examples show how to use
com.gemstone.gemfire.cache.Region#size() .
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: IndexTrackingQueryObserverDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void initializeRegion(VM vm) { SerializableRunnable initRegion = new SerializableRunnable("Initialize the PR") { public void run() { Region region = getCache().getRegion("portfolio"); if (region.size() == 0) { for (int i = 0; i < TOTAL_OBJECTS; i++) { region.put(Integer.toString(i), new Portfolio(i, i)); } } assertEquals(TOTAL_OBJECTS, region.size()); } }; vm.invoke(initRegion); }
Example 2
Source File: MapInterfaceTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
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 3
Source File: SnapshotPerformanceDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void doExport(Region<Integer, MyObject> region) throws Exception { File f = new File(getDiskDirs()[0], region.getName()); long start = System.currentTimeMillis(); region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); long elapsed = System.currentTimeMillis() - start; int size = region.size(); long bytes = f.length(); double eps = 1000.0 * size / elapsed; double mbps = 1000.0 * bytes / elapsed / (1024 * 1024); getLogWriter().info("SNP: Exported " + size + " entries (" + bytes + " bytes) in " + elapsed + " ms"); getLogWriter().info("SNP: Export entry rate: " + eps + " entries / sec"); getLogWriter().info("SNP: Export data rate: " + mbps + " MB / sec"); }
Example 4
Source File: SnapshotTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** Get an operation to perform on the region * @param reg The region to get an operation for. * @returns A random operation. */ protected int getOperation(Region aRegion) { Long opsPrm = SnapshotPrms.operations; Long upperThresholdOpsPrm = SnapshotPrms.upperThresholdOperations; Long lowerThresholdOpsPrm = SnapshotPrms.lowerThresholdOperations; int upperThreshold = SnapshotPrms.getUpperThreshold(); int lowerThreshold = SnapshotPrms.getLowerThreshold(); int size = aRegion.size(); if (size >= upperThreshold) { return getOperation(upperThresholdOpsPrm); } else if (size <= lowerThreshold) { return getOperation(lowerThresholdOpsPrm); } else { return getOperation(opsPrm); } }
Example 5
Source File: CQTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** Modifies an existing value in an entry in the given region, but does not * do a put. * * @param aRegion The region to use for updating an entry. */ protected void modifyValue(Region aRegion) { Object key = getExistingKey(aRegion, uniqueKeys, numThreadsInClients); if (key == null) { int size = aRegion.size(); if (isSerialExecution && (size != 0)) throw new TestException("getExistingKey returned " + key + ", but region size is " + size); Log.getLogWriter().info("modifyEntry: No keys in region"); return; } QueryObject anObj = toQueryObject(aRegion.get(key)); Log.getLogWriter().info("operation for " + key + ", modifyEntry: Modifying " + anObj + " directly"); if (TestConfig.tab().getRandGen().nextBoolean()) { anObj.modify(anObj.depth(), QueryObject.INCREMENT, 1, true, true); } else { anObj.modify(anObj.depth(), QueryObject.NEGATE, 0, true, true); } // validation if (isSerialExecution) { // record the current state regionSnapshot.put(key, PdxTestVersionHelper.toBaseObject(anObj)); } }
Example 6
Source File: SnapshotTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** Get an operation to perform on the region * @param reg The region to get an operation for. * @returns A random operation. */ protected int getOperation(Region aRegion) { Long opsPrm = SnapshotPrms.operations; Long upperThresholdOpsPrm = SnapshotPrms.upperThresholdOperations; Long lowerThresholdOpsPrm = SnapshotPrms.lowerThresholdOperations; int upperThreshold = SnapshotPrms.getUpperThreshold(); int lowerThreshold = SnapshotPrms.getLowerThreshold(); int size = aRegion.size(); if (size >= upperThreshold) { return getOperation(upperThresholdOpsPrm); } else if (size <= lowerThreshold) { return getOperation(lowerThresholdOpsPrm); } else { return getOperation(opsPrm); } }
Example 7
Source File: P2PDeltaPropagationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void verifyNoFailurePeer() throws Exception { Region reg = cache.getRegion(Region.SEPARATOR + REGION_NAME); long elapsed = 0; long start = System.currentTimeMillis(); while(elapsed < 10000 && reg.size() < NUM_OF_CREATES){ try { elapsed = System.currentTimeMillis() - start; Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } assertTrue("create's are missing", reg.size() == NUM_OF_CREATES); // start validation CachePerfStats stats = ((DistributedRegion)cache.getRegion(REGION_NAME)) .getCachePerfStats(); long deltaFailures = stats.getDeltaFailedUpdates(); assertTrue("delta failures count is not zero", deltaFailures == 0); assertTrue("fromDelta invoked", !DeltaTestImpl.fromDeltaFeatureUsed()); }
Example 8
Source File: DeltaTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** Update an existing entry in the given region. If there are * no available keys in the region, then this is a noop. * * @param aRegion The region to use for updating an entry. */ protected void updateEntry(Region aReg) { Object key = getExistingKey(aReg, uniqueKeys, numThreadsInClients); if (key == null) { int size = aReg.size(); if (isSerialExecution && (size != 0)) throw new TestException("getExistingKey returned " + key + ", but region size is " + size); Log.getLogWriter().info("updateEntry: No keys in region"); return; } DeltaObject previousObj = (DeltaObject)(aReg.get(key)); DeltaObject anObj = previousObj; String callback = updateCallbackPrefix + ProcessMgr.getProcessId(); if (previousObj == null) { // entry was previously invalidated Log.getLogWriter().info("Unable to modify value for key " + key + " because it was previously invalidated"); anObj = new DeltaObject( NameFactory.getCounterForName(key), DeltaObject.EQUAL_VALUES, 0, 1); anObj.extra = key; // embed key into the object for later validation callback = fullDistribution; trackUpdate(aReg, key, false); } else { // modify the previousObj boolean deltaBooleansSet = modifyDeltaObject(anObj); trackUpdate(aReg, key, deltaBooleansSet); if (!deltaBooleansSet) { callback = fullDistribution; } } Log.getLogWriter().info("operation for " + key + ", updateEntry: replacing key " + key + " with " + anObj.toStringFull() + ", callback is " + callback); Object returnVal = aReg.put(key, anObj, callback); Log.getLogWriter().info("operation for " + key + ", updateEntry: Done with call to put (update), returnVal is " + returnVal); // validation if (isSerialExecution || uniqueKeys) { // record the current state regionSnapshot.put(key, anObj.copy()); } }
Example 9
Source File: MapClearGIITest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static boolean checkImageStateFlag() throws Exception { Region rgn = new MapClearGIITest("dumb object to get cache").getCache().getRegion("/map"); if (rgn == null) { fail("Map region not yet created"); } if (((LocalRegion) rgn).getImageState().getClearRegionFlag()) { fail( "The image state clear region flag should have been cleared" + " (region size=" + rgn.size() + ")." + " Hence failing"); } if (!wasGIIInProgressDuringClear) { fail( "The clear operation invoked from VM1 reached VM0 after the " + "GII completed, or it reached VM0 even before the region in " + " VM0 got inserted in the subregion Map" + " (region size=" + rgn.size() + ")." + " Hence failing"); } if (rgn.size() != 0) { fail( "The clear operation invoked from VM1 should have made the " + "size of region zero. Hence failing. Size = " + rgn.size()); } return true; }
Example 10
Source File: DeltaToRegionRelationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static void waitForCreate(String r) { Region reg = cache.getRegion(REGION_NAME1); long elapsed = 0; long start = System.currentTimeMillis(); while(elapsed < 10000 && reg.size() < 10){ try { elapsed = System.currentTimeMillis() - start; Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } /* WaitCriterion wc = new WaitCriterion() { public boolean done() { Region reg = cache.getRegion(Region.SEPARATOR + REGION_NAME1); int val = ((DeltaTestObj)reg.get(new Integer(1))).getIntVar(); return val == 9; } public String description() { return "Updates NOT received."; } }; DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true); */ }
Example 11
Source File: ConcResumableTxTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** Add new entries to all root regions until the region has a size of at * least REGION_SIZE. */ public static void HydraTask_populateRegions() { for (Region aRegion: CacheHelper.getCache().rootRegions()) { while (aRegion.size() < REGION_SIZE) { Object key = NameFactory.getNextPositiveObjectName(); Object value = NameFactory.getCounterForName(key); aRegion.put(key, value); } } logRegionSizes(); }
Example 12
Source File: ConcResumableTxTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** Add new entries to all root regions until the region has a size of at * least REGION_SIZE. */ public static void HydraTask_populateRegions() { for (Region aRegion: CacheHelper.getCache().rootRegions()) { while (aRegion.size() < REGION_SIZE) { Object key = NameFactory.getNextPositiveObjectName(); Object value = NameFactory.getCounterForName(key); aRegion.put(key, value); } } logRegionSizes(); }
Example 13
Source File: DeltaTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** Update an existing entry in the given region. If there are * no available keys in the region, then this is a noop. * * @param aRegion The region to use for updating an entry. */ protected void updateEntry(Region aReg) { Object key = getExistingKey(aReg, uniqueKeys, numThreadsInClients); if (key == null) { int size = aReg.size(); if (isSerialExecution && (size != 0)) throw new TestException("getExistingKey returned " + key + ", but region size is " + size); Log.getLogWriter().info("updateEntry: No keys in region"); return; } DeltaObject previousObj = (DeltaObject)(aReg.get(key)); DeltaObject anObj = previousObj; String callback = updateCallbackPrefix + ProcessMgr.getProcessId(); if (previousObj == null) { // entry was previously invalidated Log.getLogWriter().info("Unable to modify value for key " + key + " because it was previously invalidated"); anObj = new DeltaObject( NameFactory.getCounterForName(key), DeltaObject.EQUAL_VALUES, 0, 1); anObj.extra = key; // embed key into the object for later validation callback = fullDistribution; trackUpdate(aReg, key, false); } else { // modify the previousObj boolean deltaBooleansSet = modifyDeltaObject(anObj); trackUpdate(aReg, key, deltaBooleansSet); if (!deltaBooleansSet) { callback = fullDistribution; } } Log.getLogWriter().info("operation for " + key + ", updateEntry: replacing key " + key + " with " + anObj.toStringFull() + ", callback is " + callback); Object returnVal = aReg.put(key, anObj, callback); Log.getLogWriter().info("operation for " + key + ", updateEntry: Done with call to put (update), returnVal is " + returnVal); // validation if (isSerialExecution || uniqueKeys) { // record the current state regionSnapshot.put(key, anObj.copy()); } }
Example 14
Source File: MapInterfaceTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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: DeltaTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** Load the region with N entries, specified by DeltaPropagationPrms.upperThreshold. * */ protected void loadToUpperThreshold(Region aReg) { int logIntervalMS = 10000; long startTime = System.currentTimeMillis(); long lastLogTime = System.currentTimeMillis(); Log.getLogWriter().info("Loading region to size " + upperThreshold + ", current region size is " + aReg.size()); while (aReg.size() < upperThreshold) { if (System.currentTimeMillis() - lastLogTime >= logIntervalMS) { Log.getLogWriter().info("Loading region to size " + upperThreshold + ", current region size is " + aReg.size()); lastLogTime = System.currentTimeMillis(); } addEntry(aReg); long numUpdates = DeltaPropagationBB.getBB().getSharedCounters().read(DeltaPropagationBB.NUM_UPDATE); if (numUpdates > 0) { throw new TestException("After loading with creates, test detected " + numUpdates + " update events, but expected only create events"); } if (System.currentTimeMillis() - startTime >= minTaskGranularityMS) { break; } } HydraTask_verifyNoDeltaCalls(); // only creates have occured, no updates, so no delta calls if (aReg.size() >= upperThreshold) { String aStr = "Finished loadToUpperThreshold, " + aReg.getFullPath() + " is size " + aReg.size(); Log.getLogWriter().info(aStr); throw new StopSchedulingTaskOnClientOrder(aStr); } }
Example 16
Source File: WANOperationsClient.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Destroy an entry in the given region. * * @param aRegion * The region to use for destroying an entry. * @param isLocalDestroy * True if the destroy should be local, false otherwise. */ protected void destroyEntry(Region aRegion, boolean isLocalDestroy) { Object key = getExistingKey(aRegion); if (key == null) { int size = aRegion.size(); return; } try { 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); 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); 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); aRegion.destroy(key, callback); Log.getLogWriter().info("destroyEntry: done destroying key " + key); } else { // destroy without callback Log.getLogWriter().info("destroyEntry: destroying key " + key); aRegion.destroy(key); Log.getLogWriter().info("destroyEntry: done destroying key " + key); } // unique key validation does not support local destroy if (useUniqueKeyPerThread) { updateBlackboardSnapshot(aRegion, key, null, true); } } } catch (com.gemstone.gemfire.cache.EntryNotFoundException e) { Log.getLogWriter().info( "Caught " + e + " (expected with concurrent execution); continuing with test"); return; } }
Example 17
Source File: LRUEvictionControllerDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Carefully verifies that region operations effect the {@link * LRUStatistics} as expected using the LRU_HEAP algorithm. */ public void testRegionOperationsLruHeap() throws CacheException { final String name = this.getUniqueName(); AttributesFactory factory = new AttributesFactory(); factory.setEnableOffHeapMemory(isOffHeapEnabled()); factory.setScope(Scope.LOCAL); factory.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(new ObjectSizer() { public int sizeof(Object o) { return 1024; }; })); Region region; if (usingMain) { DistributedSystem system = DistributedSystem.connect(getDistributedSystemProperties()); Cache cache = CacheFactory.create(system); region = cache.createRegion("Test", factory.create()); } else { region = createRegion(name, factory.create()); } InternalResourceManager irm = (InternalResourceManager) getCache().getResourceManager(); irm.setEvictionHeapPercentage(5.0f); irm.addResourceListener(getResourceType(), this); HeapEvictor evictor = getEvictor(); evictor.testAbortAfterLoopCount = 0; int counter = 0; while (!this.receivedEvictionEvent) { region.put(counter++, new byte[1024]); } int startingSize = region.size(); LRUStatistics lruStats = getLRUStats(region); assertNotNull(lruStats); long evictionCount = lruStats.getEvictions(); for (int i = 0; i <= 10; i++) { region.put(counter++, new byte[1024]); assertEquals(++evictionCount, lruStats.getEvictions()); assertEquals(startingSize, region.size()); } irm.removeResourceListener(this); region.destroyRegion(); evictor.testAbortAfterLoopCount = Integer.MAX_VALUE; }
Example 18
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; } } }
Example 19
Source File: SimplePrintUtil.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Prints the region entries. It prints both keys and values formatted. * @param region * @param startIndex * @param startRowNum * @param rowCount * @param keyList * @return Returns the number of rows printed. * @throws Exception */ public static int printEntries(Region region, Iterator regionIterator, int startIndex, int startRowNum, int rowCount, List keyList) throws Exception { if (region == null || regionIterator == null) { System.out.println("Error: Region is null"); return 0; } int endIndex = startIndex + rowCount; // exclusive if (endIndex >= region.size()) { endIndex = region.size(); } if (startIndex == endIndex) { return 0; } HashSet keyNameSet = new HashSet(); HashSet valueNameSet = new HashSet(); Object key = null; Object value = null; int index = startIndex; // Print keys and values int row = startRowNum; index = startIndex; for (Iterator itr = regionIterator; index < endIndex && itr.hasNext(); index++) { Region.Entry entry = (Region.Entry) itr.next(); key = entry.getKey(); value = entry.getValue(); keyNameSet.add(key.getClass().getName()); if (value != null) { valueNameSet.add(value.getClass().getName()); } printObject(row, "Key", key, true); printObject(row, "Value", value, false); System.out.println(); row++; } System.out.println(); System.out.println(" Fetch size: " + rowCount); System.out.println(" Returned: " + (row-1) + "/" + region.size()); for (Object keyName : keyNameSet) { System.out.println(" Key Class: " + keyName); } for (Object valueName : valueNameSet) { System.out.println("Value Class: " + valueName); } return endIndex - startIndex; }
Example 20
Source File: SecurityTestUtils.java From gemfirexd-oss with Apache License 2.0 | 3 votes |
private void refreshNumRows() throws SQLException { String regionPath = Misc.getRegionPath(tableschema, tabnm .toUpperCase(), null); getLogWriter().info("getting region " + regionPath); Region<?,?> reg = Misc.getGemFireCache().getRegion(regionPath); assertTrue("Region expected " + regionPath, reg != null); num_rows = reg.size(); }