You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jj...@apache.org on 2019/07/23 17:59:21 UTC

[geode] branch develop updated: GEODE-6999: Fix XML attribute parsing (#3823)

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

jjramos 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 8718171  GEODE-6999: Fix XML attribute parsing (#3823)
8718171 is described below

commit 8718171b749552709876fa3f5cd74cdc1851941c
Author: Juan José Ramos <ju...@users.noreply.github.com>
AuthorDate: Tue Jul 23 14:59:08 2019 -0300

    GEODE-6999: Fix XML attribute parsing (#3823)
    
    - Fixed parsing of the 'attribute disk-usage-warning-percentage'
      attribute.
---
 .../cache/xmlcache/CacheXmlParserJUnitTest.java    | 28 ++++++++++++++++++++--
 ...itTest.testDiskUsageWarningPercentage.cache.xml | 22 +++++++++++++++++
 .../internal/cache/xmlcache/CacheXmlParser.java    |  2 +-
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.java
index 3276e83..0876d6e 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.java
@@ -30,8 +30,12 @@ import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.rules.TemporaryFolder;
 import org.xml.sax.Attributes;
 
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.DiskStore;
 import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.client.ClientCacheFactory;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
@@ -46,6 +50,9 @@ public class CacheXmlParserJUnitTest {
   @Rule
   public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
 
+  @Rule
+  public final TemporaryFolder temporaryFolderRule = new TemporaryFolder();
+
   private static final String NAMESPACE_URI =
       "urn:java:org.apache.geode.internal.cache.xmlcache.MockXmlParser";
 
@@ -126,16 +133,16 @@ public class CacheXmlParserJUnitTest {
     Properties nonDefault = new Properties();
     nonDefault.setProperty(MCAST_PORT, "0"); // loner
 
+
     ClientCache cache = new ClientCacheFactory(nonDefault).set("cache-xml-file",
         "xmlcache/CacheXmlParserJUnitTest.testMultiplePools.cache.xml").create();
-
     assertThat(cache.getRegion("regionOne").getAttributes().getPoolName()).isEqualTo("poolOne");
     assertThat(cache.getRegion("regionTwo").getAttributes().getPoolName()).isEqualTo("poolTwo");
     cache.close();
   }
 
   @Test
-  public void cacheXmlParserShouldShouldThrowExceptionWhenPoolDoesNotExist() {
+  public void cacheXmlParserShouldThrowExceptionWhenPoolDoesNotExist() {
     Properties nonDefault = new Properties();
     nonDefault.setProperty(MCAST_PORT, "0"); // loner
 
@@ -145,6 +152,23 @@ public class CacheXmlParserJUnitTest {
             .hasMessage("The connection pool nonExistingPool has not been created");
   }
 
+  @Test
+  public void cacheXmlParserShouldCorrectlyHandleDiskUsageWarningPercentage() {
+    String diskStoreName = "myDiskStore";
+    System.setProperty("DISK_STORE_NAME", diskStoreName);
+    System.setProperty("DISK_STORE_DIRECTORY", temporaryFolderRule.getRoot().getAbsolutePath());
+
+    Cache cache =
+        new CacheFactory()
+            .set("cache-xml-file",
+                "xmlcache/CacheXmlParserJUnitTest.testDiskUsageWarningPercentage.cache.xml")
+            .create();
+    DiskStore diskStore = cache.findDiskStore(diskStoreName);
+    assertThat(diskStore).isNotNull();
+    assertThat(diskStore.getDiskUsageWarningPercentage()).isEqualTo(70);
+    cache.close();
+  }
+
   /**
    * Test that {@link CacheXmlParser} falls back to DTD parsing when locale language is not English.
    *
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.testDiskUsageWarningPercentage.cache.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.testDiskUsageWarningPercentage.cache.xml
new file mode 100644
index 0000000..e842f0d
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/xmlcache/CacheXmlParserJUnitTest.testDiskUsageWarningPercentage.cache.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+  ~ 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.
+  -->
+<cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" copy-on-read="false" is-server="false" lock-lease="120" lock-timeout="60" search-timeout="300" version="1.0" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd">
+       <disk-store name="${DISK_STORE_NAME}" disk-usage-warning-percentage="70">
+              <disk-dirs>
+                     <disk-dir>${DISK_STORE_DIRECTORY}</disk-dir>
+              </disk-dirs>
+       </disk-store>
+</cache>
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParser.java b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParser.java
index 1ee2d42..8ddecbe 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParser.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlParser.java
@@ -1015,7 +1015,7 @@ public class CacheXmlParser extends CacheXml implements ContentHandler {
     }
 
     String criticalPct = atts.getValue(DISK_USAGE_CRITICAL_PERCENTAGE);
-    if (warnPct != null) {
+    if (criticalPct != null) {
       attrs.setDiskUsageCriticalPercentage(parseFloat(criticalPct));
     }