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

The following examples show how to use com.gemstone.gemfire.cache.Region#putAll() . 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: EventTrackerDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void doTwoPutAlls(VM vm, final String regionName) {
  SerializableRunnable createData = new SerializableRunnable("putAlls") {
    
    public void run() {
      Cache cache = getCache();
      Region region = cache.getRegion(regionName);
      
      Map putAllMap = new HashMap();
      for(int i =0; i < 9; i++) {
        putAllMap.put(i, i);
      }
      region.putAll(putAllMap);
      
      putAllMap.clear();
      for(int i =10; i < 19; i++) {
        putAllMap.put(i, i);
      }
      region.putAll(putAllMap);
    }
  };
  
  vm.invoke(createData);
}
 
Example 2
Source File: SingleHopGetAllPutAllDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void putAll() {
  Region region = cache.getRegion(PartitionedRegionName);
  assertNotNull(region);
  final Map keysValuesMap = new HashMap();
  final List testKeysList = new ArrayList();
  for (int i = (totalNumBuckets.intValue() * 3); i > 0; i--) {
    testKeysList.add("execKey-" + i);
    keysValuesMap.put("execKey-" + i, "values-" + i);
  }
  DistributedSystem.setThreadsSocketPolicy(false);
  try {
    // check if the client meta-data is in synch

    // check if the function was routed to pruned nodes
    region.putAll(keysValuesMap);
    // check the listener
    // check how the function was executed
    pause(2000);
    region.putAll(keysValuesMap);
    
    // check if the client meta-data is in synch
    verifyMetadata();
    
    // check if the function was routed to pruned nodes
    Map resultMap = region.getAll(testKeysList);
    assertTrue(resultMap.equals(keysValuesMap));
    pause(2000);
    Map secondResultMap = region.getAll(testKeysList);
    assertTrue(secondResultMap.equals(keysValuesMap));
  }
  catch (Exception e) {
    fail("Test failed after the putAll operation", e);
  }
}
 
Example 3
Source File: ResumableKnownKeysTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** For each available root region, do a putAll with the given putAll argument
 * 
 * @param putAllMap The map to use for the putAll
 */
private void putToAllRegions(Map putAllMap) {
  for (Region aRegion: CacheHelper.getCache().rootRegions()) {
    //Log.getLogWriter().info("Putting putAll map of size " + putAllMap.size() + " into " + aRegion.getFullPath() +
    //    ", keys of putAll map are: " + keySet);
    aRegion.putAll(putAllMap);
  }
}
 
Example 4
Source File: SnapshotTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** putall a map to the given region.
 *
 *  @param aRegion The region to use for putall a map.
 *
 */
protected void putAll(Region aRegion) {
  // determine the number of new keys to put in the putAll
  Map mapToPut = getPutAllMap(aRegion);

  // do the putAll
  Log.getLogWriter().info("putAll: calling putAll with map of " + mapToPut.size() + " entries, region is " + aRegion.getFullPath());
  aRegion.putAll(mapToPut);
  Log.getLogWriter().info("putAll: done calling putAll with map of " + mapToPut.size() + " entries");
}
 
Example 5
Source File: QueryFunctionExecTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Populate regions
 */
protected void populateRegions() {
  maxObjects = TestConfig.tab().intAt(EventPrms.maxObjects, 20000);
  List<Region> regionList = new ArrayList(CacheHelper.getCache()
      .rootRegions());
  for (Region aRegion : regionList) {
    Map aMap = new HashMap();
    for (int j = 0; j < maxObjects; j++) {
      String name = NameFactory.getNextPositiveObjectNameInLimit(maxObjects);
      aMap.put(new Integer(j), new PRPortfolio(name + j, j));
    }
    aRegion.putAll(aMap);
  }
}
 
Example 6
Source File: SingleHopGetAllPutAllDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void putAll() {
  Region region = cache.getRegion(PartitionedRegionName);
  assertNotNull(region);
  final Map keysValuesMap = new HashMap();
  final List testKeysList = new ArrayList();
  for (int i = (totalNumBuckets.intValue() * 3); i > 0; i--) {
    testKeysList.add("execKey-" + i);
    keysValuesMap.put("execKey-" + i, "values-" + i);
  }
  DistributedSystem.setThreadsSocketPolicy(false);
  try {
    // check if the client meta-data is in synch

    // check if the function was routed to pruned nodes
    region.putAll(keysValuesMap);
    // check the listener
    // check how the function was executed
    pause(2000);
    region.putAll(keysValuesMap);
    
    // check if the client meta-data is in synch
    verifyMetadata();
    
    // check if the function was routed to pruned nodes
    Map resultMap = region.getAll(testKeysList);
    assertTrue(resultMap.equals(keysValuesMap));
    pause(2000);
    Map secondResultMap = region.getAll(testKeysList);
    assertTrue(secondResultMap.equals(keysValuesMap));
  }
  catch (Exception e) {
    fail("Test failed after the putAll operation", e);
  }
}
 
Example 7
Source File: RegionSnapshotJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testFilterImportException() throws Exception {
  SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() {
    @Override
    public boolean accept(Entry<Integer, MyObject> entry) {
      throw new RuntimeException();
    }
  };
  
  for (final RegionType rt : RegionType.values()) {
    for (final SerializationType st : SerializationType.values()) {
      String name = "test-" + rt.name() + "-" + st.name();
      Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name);
      final Map<Integer, MyObject> expected = createExpected(st);

      region.putAll(expected);
      RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService();
      rss.save(f, SnapshotFormat.GEMFIRE);

      region.destroyRegion();
      region = rgen.createRegion(cache, ds.getName(), rt, name);
      
      rss = region.getSnapshotService();
      SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops);
      
      boolean caughtException = false;
      try {
        rss.load(f, SnapshotFormat.GEMFIRE, options);
      } catch (RuntimeException e) {
        caughtException = true;
      }

      assertTrue(caughtException);
      assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size());
    }
  }
}
 
Example 8
Source File: PutAllDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * does an update and return the eventid generated. Eventid is caught in the
 * listener and stored in a static variable*
 */
public static Object[] putAll()
{
  Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(region);
  try {
    Map map = new LinkedHashMap();
    map.put(PUTALL_KEY1,PUTALL_VALUE1);
    map.put(PUTALL_KEY2,PUTALL_VALUE2);
    map.put(PUTALL_KEY3,PUTALL_VALUE3);
    map.put(PUTALL_KEY4,PUTALL_VALUE4);
    map.put(PUTALL_KEY5,PUTALL_VALUE5);
    region.putAll(map);
    EventID[] evids = new EventID[5];
    evids[0] = putAlleventId1;
    evids[1] = putAlleventId2;
    evids[2] = putAlleventId3;
    evids[3] = putAlleventId4;
    evids[4] = putAlleventId5;
    assertNotNull(evids[0]);
    assertNotNull(evids[1]);
    assertNotNull(evids[2]);
    assertNotNull(evids[3]);
    assertNotNull(evids[4]);
    return evids;
  }
  catch (Exception e) {
    fail("put failed due to " + e);
  }
  return null;
}
 
Example 9
Source File: PutAllCSDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected Region doPutAll(String regionName, String keyStub, int numEntries) {
  Region region = getRootRegion().getSubregion(regionName);
  LinkedHashMap map = new LinkedHashMap();
  for (int i=0; i<numEntries; i++) {
    map.put(keyStub+i, new TestObject(i));
  }
  region.putAll(map);
  return region;
}
 
Example 10
Source File: PutAllDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * does an update and return the eventid generated. Eventid is caught in the
 * listener and stored in a static variable*
 */
public static Object[] putAll()
{
  Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(region);
  try {
    Map map = new LinkedHashMap();
    map.put(PUTALL_KEY1,PUTALL_VALUE1);
    map.put(PUTALL_KEY2,PUTALL_VALUE2);
    map.put(PUTALL_KEY3,PUTALL_VALUE3);
    map.put(PUTALL_KEY4,PUTALL_VALUE4);
    map.put(PUTALL_KEY5,PUTALL_VALUE5);
    region.putAll(map);
    EventID[] evids = new EventID[5];
    evids[0] = putAlleventId1;
    evids[1] = putAlleventId2;
    evids[2] = putAlleventId3;
    evids[3] = putAlleventId4;
    evids[4] = putAlleventId5;
    assertNotNull(evids[0]);
    assertNotNull(evids[1]);
    assertNotNull(evids[2]);
    assertNotNull(evids[3]);
    assertNotNull(evids[4]);
    return evids;
  }
  catch (Exception e) {
    fail("put failed due to " + e);
  }
  return null;
}
 
Example 11
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void putAllObjects(String regionName) {
  // // MapBB.NUM_PUT is taken because it will give the actual number of
  // keys already put inside region.
  Object key = null, val = null;
  String objectType = MapPrms.getObjectType();
  Map m = new TreeMap();
  int numEntries = TestConfig.tab().getRandGen().nextInt(1, 25);
  int mapSize = 0;

  do {
    int putAllKeyInt = (int) MapBB.getBB().getSharedCounters().incrementAndRead(MapBB.NUM_PUT);
    key = ObjectHelper.createName(putAllKeyInt);
    val = ObjectHelper.createObject(objectType, putAllKeyInt);
    m.put(key, val);
    mapSize++;
  } while (mapSize < numEntries);

  Region region = cache.getRegion(regionName);
  if (region != null) {
    try {
      region.putAll(m);
      Log.getLogWriter().info("----performed putAll operation on " + regionName + " with map size = " + m.size());
    } catch (RegionDestroyedException rdex) {
      Log
          .getLogWriter()
          .info(
              "RegionDestroyedException...may occur in concurrent environment mode. Continuing with test.");
      recoverRegion(regionName);
    } catch (Exception ex) {
      throw new TestException(TestHelper.getStackTrace(ex));
    }
  }
}
 
Example 12
Source File: put.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void put(String command) throws Exception
{
	LinkedList<String> list = new LinkedList();
	gfsh.parseCommand(command, list);
	
	boolean keyEnumerated = false;
	boolean valueEnumerated = false;
	
	String val;
	int keyIndex = 0;
	
	for (int i = 1; i < list.size(); i++) {
		val = list.get(i);
		if (val.equals("-k")) {
			keyEnumerated = true;
		} else if (val.equals("-v")) {
			valueEnumerated = true;
		} else {
			keyIndex = i;
			break;
		}
	}
	
	Region region = gfsh.getCurrentRegion();
	String numbers;
	Object key;

	if (region != null) {
     Map map = getEntryMap(list, keyEnumerated, valueEnumerated,
         keyIndex);
     region.putAll(map);
     PrintUtil.printEntries(region, map.keySet(), null);
   } else {
     gfsh.println("Error: Please 'cd' to the required region to perform put.");
   }
}
 
Example 13
Source File: PartitionedRegionSingleNodeOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void test023UnsupportedOps() throws Exception {
    Region pr = null;
    try {
      pr = PartitionedRegionTestHelper.createPartitionedRegion("testUnsupportedOps", String.valueOf(200), 0);
      
      pr.put(new Integer(1), "one" );
      pr.put(new Integer(2), "two" );
      pr.put(new Integer(3), "three" );
      pr.getEntry("key");
      
      try {
        pr.clear();
        fail("PartitionedRegionSingleNodeOperationTest:testUnSupportedOps() operation failed on a blank PartitionedRegion");
      }
      catch (UnsupportedOperationException expected) {
      }
      
//      try {
//        pr.entries(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
//      try {
//        pr.entrySet(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
      try {
        HashMap data = new HashMap();
        data.put("foo", "bar");
        data.put("bing", "bam");
        data.put("supper", "hero");
        pr.putAll(data);
//        fail("testPutAll() does NOT throw UnsupportedOperationException");
      }
      catch (UnsupportedOperationException onse) {
      }
      
      
//      try {
//        pr.values();
//        fail("testValues() does NOT throw UnsupportedOperationException");
//      }
//      catch (UnsupportedOperationException expected) {
//      }

      
      try {
        pr.containsValue("foo");
      }
      catch (UnsupportedOperationException ex) {
        fail("PartitionedRegionSingleNodeOperationTest:testContainsValue() operation failed");
      }
      
    } finally {
      if (pr!=null) {
        pr.destroyRegion();
      }
    }
  }
 
Example 14
Source File: RegionWithHDFSBasicDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
protected void doPutAll(final String uniqueName, Map map) {
  Region r = getRootRegion(uniqueName);
  r.putAll(map);
}
 
Example 15
Source File: MultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void putAllObjects(String regionName)
{
  Object key = null, val = null;    
  String objectType = MapPrms.getObjectType();
  int putAllKeyInt, numNegEntries;  
  int minQty = 50;
  int maxQty = 100;
  int numForPutAll = rnd.nextInt(maxQty - minQty) + minQty;
  Map m = new TreeMap();

  
  Region region = RegionHelper.getRegion(regionName); 
  
  if (region != null) {
    synchronized (regionOpsTryLock) {
      //  do not perform putAll operation when another thread trys to perform region ops
      if (regionOpsTryLock.booleanValue()) return; 
      
      synchronized (numOfCurrentPutAllOps) {
        numOfCurrentPutAllOps = new Integer(numOfCurrentPutAllOps.intValue()+1) ;
      } //end synchronized numOfCurrentPutAllOps
    } // end synchronized regionOpsTryLock
    
    for (int i = 0; i < numForPutAll; i++) {
      numNegEntries = Math.abs((int)NameFactory.getNegativeNameCounter());
      if(numNegEntries > MapPrms.getMaxNagetiveKeys()){
        NameBB.getBB().zero("NameBB.NEGATIVE_NAME_COUNTER", NameBB.NEGATIVE_NAME_COUNTER);        
      }
      key = NameFactory.getNextNegativeObjectName();
      putAllKeyInt = (int)NameFactory.getCounterForName(key);
      val = ObjectHelper.createObject(objectType, putAllKeyInt);
      m.put(key, val);
      Log.getLogWriter().info("put this key " + key + " in the map for putAll");
    } //end for loop 

    try {
      Log.getLogWriter().info("--- executing putAll with mapSize = " + m.size());
      region.putAll(m);
      MapBB.getBB().getSharedCounters().add(MapBB.NUM_PUT, m.size()); 
      //MapBB.NUM_PUT will be increamented once for the size of the map
      Log.getLogWriter().info("----performed putAll operation on region " + regionName);
    } catch (Exception ex) {
      throw new TestException(TestHelper.getStackTrace(ex));
    } //region ops can't mix with putAll operation in the test
    synchronized (numOfCurrentPutAllOps) {
      numOfCurrentPutAllOps = new Integer(numOfCurrentPutAllOps.intValue()-1) ;
    } //end synchronized

  }
}
 
Example 16
Source File: MultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void putAllObjects(String regionName)
{
  Object key = null, val = null;    
  String objectType = MapPrms.getObjectType();
  int putAllKeyInt, numNegEntries;  
  int minQty = 50;
  int maxQty = 100;
  int numForPutAll = rnd.nextInt(maxQty - minQty) + minQty;
  Map m = new TreeMap();

  
  Region region = RegionHelper.getRegion(regionName); 
  
  if (region != null) {
    synchronized (regionOpsTryLock) {
      //  do not perform putAll operation when another thread trys to perform region ops
      if (regionOpsTryLock.booleanValue()) return; 
      
      synchronized (numOfCurrentPutAllOps) {
        numOfCurrentPutAllOps = new Integer(numOfCurrentPutAllOps.intValue()+1) ;
      } //end synchronized numOfCurrentPutAllOps
    } // end synchronized regionOpsTryLock
    
    for (int i = 0; i < numForPutAll; i++) {
      numNegEntries = Math.abs((int)NameFactory.getNegativeNameCounter());
      if(numNegEntries > MapPrms.getMaxNagetiveKeys()){
        NameBB.getBB().zero("NameBB.NEGATIVE_NAME_COUNTER", NameBB.NEGATIVE_NAME_COUNTER);        
      }
      key = NameFactory.getNextNegativeObjectName();
      putAllKeyInt = (int)NameFactory.getCounterForName(key);
      val = ObjectHelper.createObject(objectType, putAllKeyInt);
      m.put(key, val);
      Log.getLogWriter().info("put this key " + key + " in the map for putAll");
    } //end for loop 

    try {
      Log.getLogWriter().info("--- executing putAll with mapSize = " + m.size());
      region.putAll(m);
      MapBB.getBB().getSharedCounters().add(MapBB.NUM_PUT, m.size()); 
      //MapBB.NUM_PUT will be increamented once for the size of the map
      Log.getLogWriter().info("----performed putAll operation on region " + regionName);
    } catch (Exception ex) {
      throw new TestException(TestHelper.getStackTrace(ex));
    } //region ops can't mix with putAll operation in the test
    synchronized (numOfCurrentPutAllOps) {
      numOfCurrentPutAllOps = new Integer(numOfCurrentPutAllOps.intValue()-1) ;
    } //end synchronized

  }
}
 
Example 17
Source File: RegionWithHDFSBasicDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
protected void doPutAll(final String uniqueName, Map map) {
  Region r = getRootRegion(uniqueName);
  r.putAll(map);
}
 
Example 18
Source File: SecurityTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Task to perform putAll operations.
 */
public static void putAllTask() {
  boolean expectedFail = SecurityClientsPrms.isExpectedException();
  int numOfRegion = TestConfig.tab().intAt(
      SecurityClientsPrms.numberOfRegions, 1);
  Region region = null;
  HashMap aMap = getMapForPutAll();
  try {
    if (numOfRegion == 1) {
      region = RegionHelper.getRegion(REGION_NAME);
      region.putAll(aMap);
    }
    else {
      for (int i = 0; i < numOfRegion; i++) {
        region = RegionHelper.getRegion(REGION_NAME + i);
        region.putAll(aMap);
      }
    }
    Log.getLogWriter().info("performed a PutAll operation in the region");
    if (expectedFail) {
      throw new TestException(
          "Expected this to throw CacheWriterException for putAll operation");
    }

  }
  catch (Exception ex) {
    if ((ex instanceof CacheWriterException || ex instanceof ServerConnectivityException)
        && ex.getCause() instanceof NotAuthorizedException) {
      if (expectedFail) {
        Log.getLogWriter().info(
            "Got expected CacheWriterException: " + ex.getMessage());
      }
      else {
        throw new TestException(
            "CacheWriterException while performing putAll Task :"
                + ex.getMessage());
      }
    }
    else {
      throw new TestException("Exception while performing putAllTask :"
          + ex.getMessage());
    }

  }
}
 
Example 19
Source File: RegionSnapshotJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDSID() throws Exception {
  cache.close();

  CacheFactory cf = new CacheFactory().set("mcast-port", "0")
      .set("log-level", "error")
      .setPdxSerializer(new MyPdxSerializer())
      .set("distributed-system-id", "1");
  cache = cf.create();

  RegionType rt = RegionType.REPLICATE;
  SerializationType st = SerializationType.PDX_SERIALIZER;

  String name = "test-" + rt.name() + "-" + st.name() + "-dsid";
  Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(),
      rt, name);
  final Map<Integer, MyObject> expected = createExpected(st);

  region.putAll(expected);
  region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);

  cache.close();

  // change the DSID from 1 -> 100
  CacheFactory cf2 = new CacheFactory().set("mcast-port", "0")
      .set("log-level", "error")
      .setPdxSerializer(new MyPdxSerializer())
      .set("distributed-system-id", "100");
  cache = cf2.create();

  final Map<Integer, Object> read = new HashMap<Integer, Object>();
  SnapshotIterator<Integer, Object> iter = SnapshotReader.read(f);
  try {
    while (iter.hasNext()) {
      Entry<Integer, Object> entry = iter.next();
      read.put(entry.getKey(), entry.getValue());
    }
    assertEquals("Comparison failure for " + rt.name() + "/" + st.name(),
        expected, read);
  } finally {
    iter.close();
  }
}
 
Example 20
Source File: ColocatedRegionWithHDFSDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void doPutAll(final String uniqueName, Map map) {
  Region r1= getRootRegion(uniqueName + "-r1");
  Region r2= getRootRegion(uniqueName + "-r2");
  r1.putAll(map);
  r2.putAll(map);
}