public static PartitionedRegion getPartitionedRegion(String prName, Cache cache) { Region region = cache.getRegion(prName); if (region != null) { if (region instanceof PartitionedRegion) return (PartitionedRegion) region; } return null; }
private Region<?, ?> verifyRegionExists(Cache cache, String regionName) { Region<?, ?> result = cache.getRegion(regionName); if (result == null) { throw new IllegalStateException( "create jdbc-mapping requires that the region \"" + regionName + "\" exists."); } return result; }
public void populateRegion(String regionName, Map<?, ?> entries) { Region r = cache.getRegion("/" + regionName); entries.entrySet().forEach(e -> { r.put(e.getKey(), e.getValue()); }); }
/** * @throws org.apache.geode.cache.CacheRuntimeException if no cache created */ protected Region getRegion(DistributedSystem sys) { Cache cache = CacheFactory.getInstance(sys); return cache.getRegion(this.regionName); }
public static void doPutAll(String regionName, int numPuts, int size) { Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); for (long i = 0; i < numPuts; i++) { Map putAllMap = new HashMap(); for (long j = 0; j < size; j++) { putAllMap.put((size * i) + j, i); } r.putAll(putAllMap, "putAllCallback"); putAllMap.clear(); } }
public static void putGivenKeyValue(String regionName, Map keyValues) { Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); for (Object key : keyValues.keySet()) { r.put(key, keyValues.get(key)); } }
private void destroyEntries(String regionName, int size) { Cache cache = getCache(); final Region region = cache.getRegion(regionName); for (int i = 0; i < size; i++) { region.destroy(i); } }
public static String getRegionFullPath(String regionName) { final Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); return r.getFullPath(); }
/** * To be used for CacheLoader related tests */ public static void doGets(String regionName, int numGets) { Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); for (long i = 0; i < numGets; i++) { r.get(i); } }
public static void doPutsFrom(String regionName, int from, int numPuts) { Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); for (long i = from; i < numPuts; i++) { r.put(i, i); } }
@BeforeClass public static void populateRegions() { Cache cache = server.getCache(); Region<String, String> simpleRegion = cache.getRegion("simpleRegion"); Region<String, Customer> complexRegion = cache.getRegion("complexRegion"); for (int i = 0; i < Gfsh.DEFAULT_APP_FETCH_SIZE + 1; i++) { String key = "key" + i; simpleRegion.put(key, "value" + i); complexRegion.put(key, new Customer("name" + i, "Main Street " + i, "Hometown")); } }
@Override public boolean isMappingSynchronous(String regionName, Cache cache) { Region<?, ?> region = cache.getRegion(regionName); if (region == null) { throw new IllegalStateException("Region for mapping could not be found."); } // If our region has a Jdbc Writer set as the cache writer then we know it is syncronous return region.getAttributes().getCacheWriter() != null && region.getAttributes().getCacheWriter() instanceof JdbcWriter; }
private void verifySizeOnServer(String regionName, int expectedSize) { Cache cache = getCache(); final Region region = cache.getRegion(regionName); int actualSize = region.sizeOnServer(); assertEquals( "sizeOnServer returns unexpected " + actualSize + " instead of expected " + expectedSize, expectedSize, actualSize); }
private void putIntoRegion(String regionName, int size, boolean isCachingProxy) { Cache cache = getCache(); final Region region = cache.getRegion(regionName); for (int i = 0; i < size; i++) { region.put(i, i); } if (isCachingProxy) { for (int i = 0; i < size; i++) { region.localDestroy(i, i); } } }
private static void closeRegion1() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region<String, String> r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1); assertNotNull(r1); r1.close(); } catch (Exception e) { e.printStackTrace(); fail("Test failed due to Exception during closeRegion1" + e); } }
private static void destroyRegion2() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r2); r2.destroyRegion(); } catch (Exception e) { e.printStackTrace(); fail("Test failed due to Exception during closeBothRegions" + e); } }
private static void verifyCacheClientProxyOnServer(String regionName) { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); assertNull(cache.getRegion(Region.SEPARATOR + regionName)); verifyCacheClientProxyOnServer(); // assertIndexDetailsEquals(1, // bs.getAcceptor().getCacheClientNotifier().getClientProxies().size()); } catch (Exception ex) { ex.printStackTrace(); fail("while setting verifyNoCacheClientProxyOnServer " + ex); } }
private static void destroyPRRegion() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region r2 = cache.getRegion(Region.SEPARATOR + PR_REGION_NAME); assertNotNull(r2); r2.destroyRegion(); } catch (Exception e) { // e.printStackTrace(); fail("Test failed due to Exception during closeBothRegions" + e); } }
@Test public void validateColocationWithNonPartitionedRegion() { Region region = mock(Region.class); when(cache.getRegion("nonPrRegion")).thenReturn(region); PartitionAttributesImpl instance = createPartitionAttributesImpl(); instance.setColocatedWith("nonPrRegion"); assertThatThrownBy(() -> instance.validateColocation(cache)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("supported only for PartitionedRegions"); }
public static void registerInterest() { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r); r.registerInterest("ALL_KEYS"); r.getAttributesMutator().addCacheListener(new MemberIDVerifier()); }