public void doTestHook(int spot) {
   if (spot == 2) {
     rejectedObjects = true;
   } else if (spot == 3) {
     if (count++ == numObjectsBeforeCancel) {
       InternalResourceManager resourceManager =
           (InternalResourceManager) getCache().getResourceManager();
       resourceManager.getHeapMonitor().updateStateAndSendEvent(CRITICAL_HEAP_USED);
       triggeredOOME = true;
     }
   }
 }
 public void doTestHook(int spot) {
   if (spot == 4) {
     if (triggeredOOME == false) {
       InternalResourceManager resourceManager =
           (InternalResourceManager) getCache().getResourceManager();
       resourceManager.getHeapMonitor().updateStateAndSendEvent(CRITICAL_HEAP_USED);
       triggeredOOME = true;
       try {
         Thread.sleep(1000);
       } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
       }
     }
   } else if (spot == 5) {
     rejectedObjects = true;
   }
 }
 public Object call() throws Exception {
   InternalResourceManager irm = ((GemFireCacheImpl) getCache()).getResourceManager();
   // Reset CRITICAL_UP by informing all that heap usage is now 1 byte (0 would disable).
   irm.getHeapMonitor().updateStateAndSendEvent(NORMAL_HEAP_USED);
   Set<ResourceListener> listeners = irm.getResourceListeners(ResourceType.HEAP_MEMORY);
   Iterator<ResourceListener> it = listeners.iterator();
   while (it.hasNext()) {
     ResourceListener<MemoryEvent> l = it.next();
     if (l instanceof TestMemoryThresholdListener) {
       ((TestMemoryThresholdListener) l).resetThresholdCalls();
     }
   }
   irm.setCriticalHeapPercentage(0f);
   irm.setEvictionHeapPercentage(0f);
   irm.getHeapMonitor().setTestMaxMemoryBytes(0);
   HeapMemoryMonitor.setTestDisableMemoryUpdates(false);
   return null;
 }
  public Index createIndex(
      String indexName,
      IndexType indexType,
      String indexedExpression,
      String fromClause,
      String imports,
      boolean loadEntries,
      Region region)
      throws IndexNameConflictException, IndexExistsException, RegionNotFoundException {

    if (pool != null) {
      throw new UnsupportedOperationException(
          "Index creation on the server is not supported from the client.");
    }
    PartitionedIndex parIndex = null;
    if (region == null) {
      region = getRegionFromPath(imports, fromClause);
    }
    RegionAttributes ra = region.getAttributes();

    // Asif: If the evistion action is Overflow to disk then do not allow index creation
    // It is Ok to have index creation if it is persist only mode as data will always
    // exist in memory
    // if(ra.getEvictionAttributes().getAction().isOverflowToDisk() ) {
    //  throw new
    // UnsupportedOperationException(LocalizedStrings.DefaultQueryService_INDEX_CREATION_IS_NOT_SUPPORTED_FOR_REGIONS_WHICH_OVERFLOW_TO_DISK_THE_REGION_INVOLVED_IS_0.toLocalizedString(regionPath));
    // }
    // if its a pr the create index on all of the local buckets.
    if (((LocalRegion) region).heapThresholdReached.get()
        && !InternalResourceManager.isLowMemoryExceptionDisabled()) {
      LocalRegion lr = (LocalRegion) region;
      throw new LowMemoryException(
          LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_INDEX.toLocalizedString(region.getName()),
          lr.getHeapThresholdReachedMembers());
    }
    if (region instanceof PartitionedRegion) {
      try {
        parIndex =
            (PartitionedIndex)
                ((PartitionedRegion) region)
                    .createIndex(
                        false,
                        indexType,
                        indexName,
                        indexedExpression,
                        fromClause,
                        imports,
                        loadEntries);
      } catch (ForceReattemptException ex) {
        region
            .getCache()
            .getLoggerI18n()
            .info(
                LocalizedStrings
                    .DefaultQueryService_EXCEPTION_WHILE_CREATING_INDEX_ON_PR_DEFAULT_QUERY_PROCESSOR,
                ex);
      } catch (IndexCreationException exx) {
        region
            .getCache()
            .getLoggerI18n()
            .info(
                LocalizedStrings
                    .DefaultQueryService_EXCEPTION_WHILE_CREATING_INDEX_ON_PR_DEFAULT_QUERY_PROCESSOR,
                exx);
      }
      return parIndex;

    } else {

      IndexManager indexManager = IndexUtils.getIndexManager(region, true);
      Index index =
          indexManager.createIndex(
              indexName,
              indexType,
              indexedExpression,
              fromClause,
              imports,
              null,
              null,
              loadEntries);

      return index;
    }
  }