geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esh...@apache.org
Subject geode git commit: GEODE-2892: Add sizeOnServer and isEmptyOnServer to Region
Date Thu, 01 Jun 2017 16:59:15 GMT
Repository: geode
Updated Branches:
  refs/heads/develop 8c81965be -> fbb74d8ef


GEODE-2892: Add sizeOnServer and isEmptyOnServer to Region

Implement sizeOnServer and isEmptyOnServer so that ClientRegion could get size on the server.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/fbb74d8e
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/fbb74d8e
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/fbb74d8e

Branch: refs/heads/develop
Commit: fbb74d8ef30269a1e40e21af0708404ad7309551
Parents: 8c81965
Author: eshu <eshu@pivotal.io>
Authored: Thu Jun 1 09:53:06 2017 -0700
Committer: eshu <eshu@pivotal.io>
Committed: Thu Jun 1 09:53:06 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/geode/cache/Region.java     |  23 ++-
 .../cache/client/internal/ProxyRegion.java      |  20 +++
 .../internal/admin/remote/AdminRegion.java      |  12 ++
 .../geode/internal/cache/LocalDataSet.java      |  10 ++
 .../geode/internal/cache/LocalRegion.java       |  22 +++
 .../internal/cache/xmlcache/RegionCreation.java |  12 ++
 .../geode/internal/i18n/LocalizedStrings.java   |   6 +-
 .../internal/cache/AbstractRegionJUnitTest.java |  10 ++
 .../tier/sockets/ClientServerMiscDUnitTest.java | 168 ++++++++++++++++---
 .../security/ClientAuthenticationTestCase.java  |   8 +
 .../geode/security/SecurityTestUtils.java       |  74 ++++++--
 11 files changed, 323 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/cache/Region.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/Region.java b/geode-core/src/main/java/org/apache/geode/cache/Region.java
index 0fa29c6..61f2c81 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/Region.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/Region.java
@@ -1480,7 +1480,7 @@ public interface Region<K, V> extends ConcurrentMap<K, V>
{
    * 
    * @since GemFire 5.0
    * @see java.util.Map#size()
-   * @return int the number of entries present in this region
+   * @return the number of entries present in this region
    */
   public int size();
 
@@ -2094,6 +2094,27 @@ public interface Region<K, V> extends ConcurrentMap<K, V>
{
   public boolean containsKeyOnServer(Object key);
 
   /**
+   * Returns the number of entries present in this region on the server. Entries stored in
this
+   * client region are ignored.
+   *
+   * @return the number of entries present in this region on the server.
+   * @throws UnsupportedOperationException if the region is not configured with a pool name.
+   *
+   * @since Geode 1.2.0
+   */
+  public int sizeOnServer();
+
+  /**
+   * Returns true if this region contains no entries on the server.
+   *
+   * @return true if this region contains no entries on the server.
+   * @throws UnsupportedOperationException if the region is not configured with a pool name.
+   *
+   * @since Geode 1.2.0
+   */
+  public boolean isEmptyOnServer();
+
+  /**
    * If the specified key is not already associated with a value, associate it with the given
value.
    * This is equivalent to
    * 

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/cache/client/internal/ProxyRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ProxyRegion.java
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ProxyRegion.java
index e35750b..369f87d 100755
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ProxyRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ProxyRegion.java
@@ -103,6 +103,26 @@ public class ProxyRegion implements Region {
     }
   }
 
+  @Override
+  public int sizeOnServer() {
+    try {
+      preOp();
+      return this.realRegion.sizeOnServer();
+    } finally {
+      postOp();
+    }
+  }
+
+  @Override
+  public boolean isEmptyOnServer() {
+    try {
+      preOp();
+      return this.realRegion.isEmptyOnServer();
+    } finally {
+      postOp();
+    }
+  }
+
   public boolean containsValue(Object value) {
     try {
       preOp();

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/internal/admin/remote/AdminRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/AdminRegion.java
b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/AdminRegion.java
index 51f1fdb..d67d56a 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/AdminRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/AdminRegion.java
@@ -419,6 +419,18 @@ public class AdminRegion implements Region {
         LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
   }
 
+  @Override
+  public int sizeOnServer() throws CacheWriterException {
+    throw new UnsupportedOperationException(
+        LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
+  }
+
+  @Override
+  public boolean isEmptyOnServer() throws CacheWriterException {
+    throw new UnsupportedOperationException(
+        LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
+  }
+
   @Override // GemStoneAddition
   public String toString() {
     return "<AdminRegion " + getFullPath() + ">";

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/internal/cache/LocalDataSet.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalDataSet.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalDataSet.java
index 8be8de1..f1db32f 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalDataSet.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalDataSet.java
@@ -407,6 +407,16 @@ public class LocalDataSet implements Region, QueryExecutor {
     return this.proxy.keySetOnServer();
   }
 
+  @Override
+  public int sizeOnServer() {
+    return this.proxy.sizeOnServer();
+  }
+
+  @Override
+  public boolean isEmptyOnServer() {
+    return this.proxy.isEmptyOnServer();
+  }
+
   public void loadSnapshot(InputStream inputStream)
       throws IOException, ClassNotFoundException, CacheWriterException, TimeoutException
{
     throw new UnsupportedOperationException();

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index e1fe6c7..a8dd611 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -4070,6 +4070,28 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
     }
   }
 
+  @Override
+  public int sizeOnServer() {
+    ServerRegionProxy proxy = getServerProxy();
+    if (proxy != null) {
+      return proxy.size();
+    } else {
+      throw new UnsupportedOperationException(
+          LocalizedStrings.LocalRegion_SERVER_SIZE_REQUIRES_A_POOL.toLocalizedString());
+    }
+  }
+
+  @Override
+  public boolean isEmptyOnServer() {
+    ServerRegionProxy proxy = getServerProxy();
+    if (proxy != null) {
+      return proxy.size() == 0;
+    } else {
+      throw new UnsupportedOperationException(
+          LocalizedStrings.LocalRegion_SERVER_ISEMPTY_REQUIRES_A_POOL.toLocalizedString());
+    }
+  }
+
   /**
    * WARNING: this method is overridden in subclasses.
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/RegionCreation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/RegionCreation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/RegionCreation.java
index a107fb3..1754d1b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/RegionCreation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/RegionCreation.java
@@ -543,6 +543,18 @@ public class RegionCreation implements Region, Extensible<Region<?,
?>> {
         LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
   }
 
+  @Override
+  public int sizeOnServer() throws CacheWriterException {
+    throw new UnsupportedOperationException(
+        LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
+  }
+
+  @Override
+  public boolean isEmptyOnServer() throws CacheWriterException {
+    throw new UnsupportedOperationException(
+        LocalizedStrings.UNSUPPORTED_AT_THIS_TIME.toLocalizedString());
+  }
+
   static class Entry implements Region.Entry {
     private Object key;
     private Object value;

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
index 67867fb..ae1c005 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
@@ -3080,12 +3080,14 @@ public class LocalizedStrings {
       new StringId(2866, "Regions with DataPolicy  {0}  do not support loadSnapshot.");
   public static final StringId LocalRegion_REGIONS_WITH_DATAPOLICY_0_DO_NOT_SUPPORT_SAVESNAPSHOT
=
       new StringId(2867, "Regions with DataPolicy  {0}  do not support saveSnapshot.");
-
+  public static final StringId LocalRegion_SERVER_ISEMPTY_REQUIRES_A_POOL =
+      new StringId(2868, "isEmptyOnServer requires a pool.");
   public static final StringId LocalRegion_REGION_ATTRIBUTES_MUST_NOT_BE_NULL =
       new StringId(2869, "region attributes must not be null");
   public static final StringId LocalRegion_SERVER_KEYSET_REQUIRES_A_POOL =
       new StringId(2870, "Server keySet requires a pool.");
-
+  public static final StringId LocalRegion_SERVER_SIZE_REQUIRES_A_POOL =
+      new StringId(2871, "sizeOnServer requires a pool.");
   public static final StringId LocalRegion_TX_NOT_IN_PROGRESS =
       new StringId(2872, "tx not in progress");
   public static final StringId LocalRegion_UNEXPECTED_SNAPSHOT_CODE_0_THIS_SNAPSHOT_WAS_PROBABLY_WRITTEN_BY_AN_EARLIER_INCOMPATIBLE_RELEASE
=

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionJUnitTest.java
index ce83165..eef1192 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionJUnitTest.java
@@ -424,6 +424,16 @@ public class AbstractRegionJUnitTest {
     }
 
     @Override
+    public int sizeOnServer() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isEmptyOnServer() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
     public Object putIfAbsent(Object key, Object value) {
       throw new UnsupportedOperationException();
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
index 9ca5ab9..bbaea9d 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
@@ -31,12 +31,14 @@ import org.apache.geode.cache.CacheException;
 import org.apache.geode.cache.CacheWriterException;
 import org.apache.geode.cache.DataPolicy;
 import org.apache.geode.cache.EntryEvent;
+import org.apache.geode.cache.PartitionAttributesFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.client.ClientCacheFactory;
 import org.apache.geode.cache.client.NoAvailableServersException;
 import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
 import org.apache.geode.cache.client.PoolManager;
 import org.apache.geode.cache.client.internal.Connection;
 import org.apache.geode.cache.client.internal.Op;
@@ -144,17 +146,24 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
   }
 
   int initServerCache(boolean notifyBySub) {
-    Object[] args = new Object[] {notifyBySub, getMaxThreads()};
-    return ((Integer) server1.invoke(ClientServerMiscDUnitTest.class, "createServerCache",
args))
-        .intValue();
+    return initServerCache(notifyBySub, false);
   }
 
   int initServerCache2(boolean notifyBySub) {
-    Object[] args = new Object[] {notifyBySub, getMaxThreads()};
-    return ((Integer) server2.invoke(ClientServerMiscDUnitTest.class, "createServerCache",
args))
-        .intValue();
+    return initServerCache2(notifyBySub, false);
   }
 
+  int initServerCache(boolean notifyBySub, boolean isHA) {
+    return initServerCache(notifyBySub, server1, isHA);
+  }
+
+  int initServerCache2(boolean notifyBySub, boolean isHA) {
+    return initServerCache(notifyBySub, server2, isHA);
+  }
+
+  int initServerCache(boolean notifyBySub, VM vm, boolean isHA) {
+    return vm.invoke(() -> createServerCache(notifyBySub, getMaxThreads(), isHA));
+  }
 
   @Test
   public void testConcurrentOperationsWithDRandPR() throws Exception {
@@ -754,30 +763,37 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
   }
 
   public static void createClientCacheV(String h, int port) throws Exception {
-    _createClientCache(h, port, false);
+    _createClientCache(h, false, port);
+  }
+
+  public static void createEmptyClientCache(String h, int... ports) throws Exception {
+    _createClientCache(h, false, ports);
   }
 
-  public static void createEmptyClientCache(String h, int port) throws Exception {
-    _createClientCache(h, port, true);
+  public static Pool createClientCache(String h, int... ports) throws Exception {
+    return _createClientCache(h, false, ports);
   }
 
-  public static Pool createClientCache(String h, int port) throws Exception {
-    return _createClientCache(h, port, false);
+  private static PoolFactory addServers(PoolFactory factory, String h, int... ports) {
+    for (int port : ports) {
+      factory.addServer(h, port);
+    }
+    return factory;
   }
 
-  public static Pool _createClientCache(String h, int port, boolean empty) throws Exception
{
+  public static Pool _createClientCache(String h, boolean empty, int... ports) throws Exception
{
     Properties props = new Properties();
     props.setProperty(MCAST_PORT, "0");
     props.setProperty(LOCATORS, "");
     Cache cache = new ClientServerMiscDUnitTest().createCacheV(props);
     ClientServerMiscDUnitTest.static_cache = cache;
-    PoolImpl p =
-        (PoolImpl) PoolManager.createFactory().addServer(h, port).setSubscriptionEnabled(true)
-            .setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768)
-            .setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000)
-            // .setRetryAttempts(5)
-            // .setRetryInterval(2000)
-            .create("ClientServerMiscDUnitTestPool");
+    PoolFactory poolFactory = PoolManager.createFactory();
+    PoolImpl p = (PoolImpl) addServers(poolFactory, h, ports).setSubscriptionEnabled(true)
+        .setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768)
+        .setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000)
+        // .setRetryAttempts(5)
+        // .setRetryInterval(2000)
+        .create("ClientServerMiscDUnitTestPool");
 
     AttributesFactory factory = new AttributesFactory();
     factory.setScope(Scope.DISTRIBUTED_ACK);
@@ -849,8 +865,8 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
     }
   }
 
-  public static Integer createServerCache(Boolean notifyBySubscription, Integer maxThreads)
-      throws Exception {
+  public static Integer createServerCache(Boolean notifyBySubscription, Integer maxThreads,
+      boolean isHA) throws Exception {
     Cache cache = new ClientServerMiscDUnitTest().createCacheV(new Properties());
     unsetSlowDispatcherFlag();
     AttributesFactory factory = new AttributesFactory();
@@ -862,7 +878,12 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
     Region r2 = cache.createRegion(REGION_NAME2, myAttrs);
     factory = new AttributesFactory();
     factory.setDataPolicy(DataPolicy.PARTITION);
+    if (isHA) {
+      PartitionAttributesFactory paf = new PartitionAttributesFactory().setRedundantCopies(1);
+      factory.setPartitionAttributes(paf.create());
+    }
     RegionAttributes prAttrs = factory.create();
+
     Region pr = cache.createRegion(PR_REGION_NAME, prAttrs);
     assertNotNull(r1);
     assertNotNull(r2);
@@ -1303,4 +1324,109 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase
{
     CacheClientProxy.isSlowStartForTesting = false;
   }
 
+  @Test
+  public void testOnSeverMethodsWithProxyClient() throws Exception {
+    testOnServerMothods(false, false);
+  }
+
+  @Test
+  public void testOnSeverMethodsWithCachingProxyClient() throws Exception {
+    testOnServerMothods(true, false);
+  }
+
+  @Test
+  public void testOnSeverMethodsWithProxyClientHA() throws Exception {
+    testOnServerMothods(false, true);
+  }
+
+  @Test
+  public void testOnSeverMethodsWithCachingProxyClientHA() throws Exception {
+    testOnServerMothods(true, true);
+  }
+
+  private void testOnServerMothods(boolean isCachingProxy, boolean isHA) throws Exception
{
+    int port1 = initServerCache(true, isHA); // vm0
+    int port2 = initServerCache2(true, isHA); // vm1
+    String serverName = NetworkUtils.getServerHostName(Host.getHost(0));
+    if (isCachingProxy) {
+      createClientCache(serverName, port1, port2);
+    } else {
+      createEmptyClientCache(serverName, port1, port2);
+    }
+    if (isHA) {
+      // add another server for HA scenario
+      initServerCache(true, host.getVM(1), true);
+    }
+    String rName = "/" + REGION_NAME1;
+    String prName = "/" + PR_REGION_NAME;
+
+    verifyIsEmptyOnServer(rName, true);
+    verifyIsEmptyOnServer(prName, true);
+    int size = 10;
+    putIntoRegion(rName, size, isCachingProxy);
+    verifySizeOnServer(rName, size);
+
+    putIntoRegion(prName, size, isCachingProxy);
+    if (isHA) {
+      server1.invoke(() -> closeMyCache());
+    }
+    verifySizeOnServer(prName, size);
+
+    verifyIsEmptyOnServer(rName, false);
+    verifyIsEmptyOnServer(prName, false);
+
+    destroyEntries(rName, size);
+    destroyEntries(prName, size);
+
+    verifyIsEmptyOnServer(rName, true);
+    verifyIsEmptyOnServer(prName, true);
+    verifySizeOnServer(rName, 0);
+    verifySizeOnServer(prName, 0);
+  }
+
+  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 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);
+    }
+  }
+
+  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 verifyIsEmptyOnServer(String regionName, boolean expected) {
+    Cache cache = getCache();
+    final Region region = cache.getRegion(regionName);
+    boolean isEmptyOnServer = region.isEmptyOnServer();
+    assertEquals("isEmptyOnServer returns unexpected " + isEmptyOnServer + " instead of expected
"
+        + expected, expected, isEmptyOnServer);
+  }
+
+  private void closeMyCache() {
+    Cache cache = getCache();
+    cache.close();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/test/java/org/apache/geode/security/ClientAuthenticationTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientAuthenticationTestCase.java
b/geode-core/src/test/java/org/apache/geode/security/ClientAuthenticationTestCase.java
index d1eddbb..1293aff 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientAuthenticationTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientAuthenticationTestCase.java
@@ -111,6 +111,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
     // Verify that the puts succeeded
     client2.invoke(() -> doGets(2));
 
+    // Verify sizeOnServer is correct
+    client1.invoke(() -> verifySizeOnServer(2));
+    client1.invoke(() -> verifyIsEmptyOnServer(false));
+    client2.invoke(() -> verifySizeOnServer(2));
+    client2.invoke(() -> verifyIsEmptyOnServer(false));
+
     if (multiUser) {
       client1.invoke(() -> doProxyCacheClose());
       client2.invoke(() -> doProxyCacheClose());
@@ -196,6 +202,8 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
 
     // Perform some put operations from client1
     client1.invoke(() -> doPuts(2));
+    client1.invoke(() -> verifySizeOnServer(2));
+    client1.invoke(() -> verifyIsEmptyOnServer(false));
 
     // Start second client with invalid credentials
     // Trying to create the region on client2 should throw a security

http://git-wip-us.apache.org/repos/asf/geode/blob/fbb74d8e/geode-core/src/test/java/org/apache/geode/security/SecurityTestUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityTestUtils.java b/geode-core/src/test/java/org/apache/geode/security/SecurityTestUtils.java
index 2b26cdc..b1c0907 100644
--- a/geode-core/src/test/java/org/apache/geode/security/SecurityTestUtils.java
+++ b/geode-core/src/test/java/org/apache/geode/security/SecurityTestUtils.java
@@ -663,6 +663,14 @@ public class SecurityTestUtils {
     doPutsP(num, expectedResult, false);
   }
 
+  protected static void verifySizeOnServer(final int size) {
+    verifySizeOnServer(size, NO_EXCEPTION);
+  }
+
+  protected static void verifyIsEmptyOnServer(final boolean isEmpty) {
+    verifyIsEmptyOnServer(isEmpty, NO_EXCEPTION);
+  }
+
   protected static void doMultiUserPuts(final int num, final int numOfUsers,
       final int[] expectedResults) {
     if (numOfUsers != expectedResults.length) {
@@ -975,6 +983,32 @@ public class SecurityTestUtils {
     }
   }
 
+  private static void verifySizeOnServer(final int size, final int expectedResult) {
+    Region region = getRegion(0, expectedResult);
+    try {
+      int sizeOnServer = region.sizeOnServer();
+      if (expectedResult != NO_EXCEPTION) {
+        fail("Expected a NotAuthorizedException while executing sizeOnServer");
+      }
+      assertEquals(size, sizeOnServer);
+    } catch (Exception ex) {
+      fail("Got unexpected exception when executing sizeOnServer", ex);
+    }
+  }
+
+  private static void verifyIsEmptyOnServer(final boolean isEmpty, final int expectedResult)
{
+    Region region = getRegion(0, expectedResult);
+    try {
+      boolean isEmptyOnServer = region.isEmptyOnServer();
+      if (expectedResult != NO_EXCEPTION) {
+        fail("Expected a NotAuthorizedException while executing isEmptyOnServer");
+      }
+      assertEquals(isEmpty, isEmptyOnServer);
+    } catch (Exception ex) {
+      fail("Got unexpected exception when executing isEmptyOnServer", ex);
+    }
+  }
+
   private static void doPutsP(final int num, final int expectedResult, final boolean newVals)
{
     doPutsP(num, 0, expectedResult, newVals);
   }
@@ -982,24 +1016,7 @@ public class SecurityTestUtils {
   private static void doPutsP(final int num, final int multiUserIndex, final int expectedResult,
       final boolean newVals) {
     assertTrue(num <= KEYS.length);
-    Region region = null;
-
-    try {
-      if (multiUserAuthMode) {
-        region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
-        regionRef = region;
-      } else {
-        region = getCache().getRegion(REGION_NAME);
-      }
-      assertNotNull(region);
-
-    } catch (Exception ex) {
-      if (expectedResult == OTHER_EXCEPTION) {
-        getLogWriter().info("Got expected exception when doing puts: " + ex);
-      } else {
-        fail("Got unexpected exception when doing puts", ex);
-      }
-    }
+    Region region = getRegion(multiUserIndex, expectedResult);
 
     for (int index = 0; index < num; ++index) {
       try {
@@ -1056,6 +1073,27 @@ public class SecurityTestUtils {
     }
   }
 
+  private static Region getRegion(final int multiUserIndex, final int expectedResult) {
+    Region region = null;
+    try {
+      if (multiUserAuthMode) {
+        region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
+        regionRef = region;
+      } else {
+        region = getCache().getRegion(REGION_NAME);
+      }
+      assertNotNull(region);
+
+    } catch (Exception ex) {
+      if (expectedResult == OTHER_EXCEPTION) {
+        getLogWriter().info("Got expected exception during getRegion: " + ex);
+      } else {
+        fail("Got unexpected exception during getRegion", ex);
+      }
+    }
+    return region;
+  }
+
   private static Map<Field, Object> getSSLFields(final Object obj, final Class[] classes)
{
     Map<Field, Object> resultFields = new HashMap<>();
     Field[] fields = obj.getClass().getDeclaredFields();


Mime
View raw message