You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2019/04/24 16:50:02 UTC

[geode] branch develop updated: GEODE-6612: use java Objects for comparision instead of guava (#3493)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new aae23e3  GEODE-6612: use java Objects for comparision instead of guava (#3493)
aae23e3 is described below

commit aae23e300ce3c493a351562692b512b33966db45
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Wed Apr 24 09:49:42 2019 -0700

    GEODE-6612: use java Objects for comparision instead of guava (#3493)
    
    Co-authored-by: Owen Nichols <on...@pivotal.io>
---
 .../ManagementClientTestCreateRegion.java          |  6 +++
 .../mutators/RegionConfigManager.java              | 15 +++---
 .../mutators/RegionConfigManagerTest.java          | 54 ++++++++++++++++++++++
 .../geode/cache/configuration/RegionConfig.java    |  6 +--
 4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/geode-assembly/src/acceptanceTest/resources/ManagementClientTestCreateRegion.java b/geode-assembly/src/acceptanceTest/resources/ManagementClientTestCreateRegion.java
index 1b96e07..bbdbcd5 100644
--- a/geode-assembly/src/acceptanceTest/resources/ManagementClientTestCreateRegion.java
+++ b/geode-assembly/src/acceptanceTest/resources/ManagementClientTestCreateRegion.java
@@ -36,6 +36,7 @@ public class ManagementClientCreateRegion {
       cms = ClusterManagementServiceProvider.getService("localhost", httpPort);
     }
 
+    // create region
     RegionConfig config = new RegionConfig();
     config.setName(regionName);
     config.setType(RegionType.REPLICATE);
@@ -47,6 +48,11 @@ public class ManagementClientCreateRegion {
           "Failure creating region: " + result.getStatusMessage());
     }
 
+    result = cms.list(new RegionConfig());
+    if (!result.isSuccessful()) {
+      throw new RuntimeException("failed " + result.getStatusMessage());
+    }
+
     System.out.println("Successfully created region: " + regionName);
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManager.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManager.java
index de44010..1cb8b7d 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManager.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManager.java
@@ -34,11 +34,13 @@ import org.apache.geode.management.configuration.RuntimeRegionConfig;
 public class RegionConfigManager
     implements ConfigurationManager<RegionConfig> {
   private InternalCache cache;
-  private ManagementService managementService;
 
   public RegionConfigManager(InternalCache cache) {
     this.cache = cache;
-    this.managementService = ManagementService.getExistingManagementService(cache);
+  }
+
+  ManagementService getManagementService() {
+    return ManagementService.getExistingManagementService(cache);
   }
 
   @Override
@@ -70,12 +72,13 @@ public class RegionConfigManager
     List<RuntimeRegionConfig> results = new ArrayList<>();
     for (RegionConfig config : staticRegionConfigs) {
       DistributedRegionMXBean distributedRegionMXBean =
-          managementService.getDistributedRegionMXBean("/" + config.getName());
-      if (distributedRegionMXBean == null) {
-        throw new IllegalStateException("Can't get the region mbean info for " + config.getName());
+          getManagementService().getDistributedRegionMXBean("/" + config.getName());
+      long entryCount = -1;
+      if (distributedRegionMXBean != null) {
+        entryCount = distributedRegionMXBean.getSystemRegionEntryCount();
       }
       RuntimeRegionConfig runtimeConfig = new RuntimeRegionConfig(config);
-      runtimeConfig.setEntryCount(distributedRegionMXBean.getSystemRegionEntryCount());
+      runtimeConfig.setEntryCount(entryCount);
       results.add(runtimeConfig);
     }
     return results;
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManagerTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManagerTest.java
new file mode 100644
index 0000000..2936d13
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigManagerTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.configuration.mutators;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.RegionConfig;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.management.configuration.RuntimeRegionConfig;
+
+public class RegionConfigManagerTest {
+  @Test
+  public void managerCountIsMinusOneIfMbeanNotReady() throws Exception {
+    RegionConfig filter = new RegionConfig();
+    CacheConfig existing = mock(CacheConfig.class);
+    List<RegionConfig> staticRegionConfigs = new ArrayList<>();
+    RegionConfig region1 = new RegionConfig();
+    region1.setName("region1");
+    staticRegionConfigs.add(region1);
+    when(existing.getRegions()).thenReturn(staticRegionConfigs);
+
+    InternalCache cache = mock(InternalCache.class);
+    RegionConfigManager manager = spy(new RegionConfigManager(cache));
+    ManagementService managementService = mock(ManagementService.class);
+    doReturn(managementService).when(manager).getManagementService();
+
+    List<RuntimeRegionConfig> result = manager.list(filter, existing);
+    assertThat(result.get(0).getEntryCount()).isEqualTo(-1);
+  }
+}
diff --git a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
index 610233e..4b83c2f 100644
--- a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
+++ b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
@@ -21,6 +21,7 @@ package org.apache.geode.cache.configuration;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -30,7 +31,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.google.common.base.Objects;
 
 import org.apache.geode.annotations.Experimental;
 import org.apache.geode.management.api.RestfulEndpoint;
@@ -488,8 +488,8 @@ public class RegionConfig extends CacheElement implements RestfulEndpoint {
       return false;
     }
     RegionConfig config = (RegionConfig) that;
-    return Objects.equal(getName(), config.getName()) &&
-        Objects.equal(getType(), config.getType());
+    return Objects.equals(getName(), config.getName()) &&
+        Objects.equals(getType(), config.getType());
   }
 
   /**