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

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 33a54ea8 RATIS-1560. Remove xml code from RaftProperties. (#629)
33a54ea8 is described below

commit 33a54ea8a2cc94a8fb9bbfdbb753e41dfc2ee41a
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Wed Apr 6 20:42:43 2022 +0800

    RATIS-1560. Remove xml code from RaftProperties. (#629)
---
 .../java/org/apache/ratis/conf/RaftProperties.java | 594 +--------------------
 .../ratis/examples/filestore/FileStoreWriter.java  |   2 +-
 .../raftlog/segmented/TestSegmentedRaftLog.java    |   2 +-
 .../java/org/apache/ratis/util/TestDataQueue.java  |   8 +-
 4 files changed, 21 insertions(+), 585 deletions(-)

diff --git 
a/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java 
b/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
index f3b715b0..b48f79f9 100644
--- a/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
+++ b/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
@@ -18,52 +18,25 @@
 
 package org.apache.ratis.conf;
 
+import org.apache.ratis.util.JavaUtils;
 import org.apache.ratis.util.ReflectionUtils;
 import org.apache.ratis.util.SizeInBytes;
 import org.apache.ratis.util.StringUtils;
 import org.apache.ratis.util.TimeDuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.xml.sax.SAXException;
 
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.JarURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Objects;
-import java.util.Properties;
 import java.util.Set;
-import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 import java.util.function.BiFunction;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
 import java.util.stream.Collectors;
 
 /**
@@ -73,91 +46,10 @@ import java.util.stream.Collectors;
 public class RaftProperties {
   private static final Logger LOG = 
LoggerFactory.getLogger(RaftProperties.class);
 
-  private static class Resource {
-    private final Object resource;
-    private final String name;
-
-    Resource(Object resource) {
-      this(resource, resource.toString());
-    }
-
-    Resource(Object resource, String name) {
-      this.resource = resource;
-      this.name = name;
-    }
-
-    public String getName(){
-      return name;
-    }
-
-    public Object getResource() {
-      return resource;
-    }
-
-    @Override
-    public String toString() {
-      return name;
-    }
-  }
-
-  /**
-   * List of configuration resources.
-   */
-  private final ArrayList<Resource> resources;
-
-  /**
-   * The value reported as the setting resource when a key is set
-   * by code rather than a file resource by dumpConfiguration.
-   */
-  static final String UNKNOWN_RESOURCE = "Unknown";
-
-  /**
-   * List of configuration parameters marked <b>final</b>.
-   */
-  private final Set<String> finalParameters = Collections.newSetFromMap(new 
ConcurrentHashMap<>());
-
-  private final boolean loadDefaults;
-
-  /**
-   * Configuration objects
-   */
-  private static final WeakHashMap<RaftProperties, Object> REGISTRY = new 
WeakHashMap<>();
-
-  /**
-   * List of default Resources. Resources are loaded in the order of the list
-   * entries
-   */
-  private static final CopyOnWriteArrayList<String> DEFAULT_RESOURCES =
-    new CopyOnWriteArrayList<>();
-
-  /**
-   * Stores the mapping of key to the resource which modifies or loads
-   * the key most recently
-   */
-  private final Map<String, String[]> updatingResource;
-
-  private Properties properties;
-  private Properties overlay;
+  private final ConcurrentMap<String, String> properties = new 
ConcurrentHashMap<>();
 
   /** A new configuration. */
   public RaftProperties() {
-    this(true);
-  }
-
-  /** A new configuration where the behavior of reading from the default
-   * resources can be turned off.
-   *
-   * If the parameter {@code loadDefaults} is false, the new instance
-   * will not load resources from the default files.
-   * @param loadDefaults specifies whether to load from the default files
-   */
-  public RaftProperties(boolean loadDefaults) {
-    this.loadDefaults = loadDefaults;
-    this.resources = new ArrayList<>();
-    this.updatingResource = new ConcurrentHashMap<>();
-    synchronized(RaftProperties.class) {
-      REGISTRY.put(this, null);
-    }
   }
 
   /**
@@ -165,120 +57,8 @@ public class RaftProperties {
    *
    * @param other the RaftProperties from which to clone settings.
    */
-  @SuppressWarnings("unchecked")
   public RaftProperties(RaftProperties other) {
-    this.resources = (ArrayList<Resource>) other.resources.clone();
-    synchronized(other) {
-      if (other.properties != null) {
-        this.properties = (Properties)other.properties.clone();
-      }
-
-      if (other.overlay!=null) {
-        this.overlay = (Properties)other.overlay.clone();
-      }
-
-      this.updatingResource = new ConcurrentHashMap<>(other.updatingResource);
-      this.finalParameters.addAll(other.finalParameters);
-    }
-
-    synchronized(RaftProperties.class) {
-      REGISTRY.put(this, null);
-    }
-    this.loadDefaults = other.loadDefaults;
-  }
-
-  /**
-   * Add a default resource. Resources are loaded in the order of the resources
-   * added.
-   * @param name file name. File should be present in the classpath.
-   */
-  public static synchronized void addDefaultResource(String name) {
-    if(!DEFAULT_RESOURCES.contains(name)) {
-      DEFAULT_RESOURCES.add(name);
-      REGISTRY.keySet().stream().filter(conf -> conf.loadDefaults)
-          .forEach(RaftProperties::reloadConfiguration);
-    }
-  }
-
-  /**
-   * Add a configuration resource.
-   *
-   * The properties of this resource will override properties of previously
-   * added resources, unless they were marked <a href="#Final">final</a>.
-   *
-   * @param name resource to be added, the classpath is examined for a file
-   *             with that name.
-   */
-  public void addResource(String name) {
-    addResourceObject(new Resource(name));
-  }
-
-
-  public void addResource(URL path) {
-    addResourceObject(new Resource(path));
-  }
-
-  /**
-   * Add a configuration resource.
-   *
-   * The properties of this resource will override properties of previously
-   * added resources, unless they were marked <a href="#Final">final</a>.
-   *
-   * WARNING: The contents of the InputStream will be cached, by this method.
-   * So use this sparingly because it does increase the memory consumption.
-   *
-   * @param in InputStream to deserialize the object from. In will be read from
-   * when a get or set is called next.  After it is read the stream will be
-   * closed.
-   */
-  public void addResource(InputStream in) {
-    addResourceObject(new Resource(in));
-  }
-
-  /**
-   * Add a configuration resource.
-   *
-   * The properties of this resource will override properties of previously
-   * added resources, unless they were marked <a href="#Final">final</a>.
-   *
-   * @param in InputStream to deserialize the object from.
-   * @param name the name of the resource because InputStream.toString is not
-   * very descriptive some times.
-   */
-  public void addResource(InputStream in, String name) {
-    addResourceObject(new Resource(in, name));
-  }
-
-  /**
-   * Add a configuration resource.
-   *
-   * The properties of this resource will override properties of previously
-   * added resources, unless they were marked <a href="#Final">final</a>.
-   *
-   * @param conf Configuration object from which to load properties
-   */
-  public void addResource(RaftProperties conf) {
-    addResourceObject(new Resource(conf.getProps()));
-  }
-
-
-
-  /**
-   * Reload configuration from previously added resources.
-   *
-   * This method will clear all the configuration read from the added
-   * resources, and final parameters. This will make the resources to
-   * be read again before accessing the values. Values that are added
-   * via set methods will overlay values read from the resources.
-   */
-  public synchronized void reloadConfiguration() {
-    properties = null;                            // trigger reload
-    finalParameters.clear();                      // clear site-limits
-  }
-
-  private synchronized void addResourceObject(Resource resource) {
-    resources.add(resource);                      // add to resources
-    reloadConfiguration();
+    this.properties.putAll(other.properties);
   }
 
   private static final int MAX_SUBST = 20;
@@ -483,21 +263,6 @@ public class RaftProperties {
     }
   }
 
-  /**
-   * Get the value of the <code>name</code> property as a trimmed 
<code>String</code>,
-   * <code>defaultValue</code> if no such property exists.
-   * See @{Configuration#getTrimmed} for more details.
-   *
-   * @param name          the property name.
-   * @param defaultValue  the property default value.
-   * @return              the value of the <code>name</code> or defaultValue
-   *                      if it is not set.
-   */
-  public String getTrimmed(String name, String defaultValue) {
-    String ret = getTrimmed(name);
-    return ret == null ? defaultValue : ret;
-  }
-
   /**
    * Get the value of the <code>name</code> property, without doing
    * <a href="#VariableExpansion">variable expansion</a>.If the key is
@@ -509,7 +274,7 @@ public class RaftProperties {
    *         its replacing property and null if no such property exists.
    */
   public String getRaw(String name) {
-    return getProps().getProperty(name.trim());
+    return properties.get(Objects.requireNonNull(name, "name == null").trim());
   }
 
   /**
@@ -523,21 +288,16 @@ public class RaftProperties {
    * @throws IllegalArgumentException when the value or name is null.
    */
   public void set(String name, String value) {
-    final String trimmed = Objects.requireNonNull(name, "Property name must be 
non-null.");
-    Objects.requireNonNull(value, () -> "The value of property " + trimmed + " 
must be non-null.");
-    name = trimmed;
-    getProps();
-
-    getOverlay().setProperty(name, value);
-    getProps().setProperty(name, value);
+    final String trimmed = Objects.requireNonNull(name, "name == null").trim();
+    Objects.requireNonNull(value, () -> "value == null for " + trimmed);
+    properties.put(trimmed, value);
   }
 
   /**
    * Unset a previously set property.
    */
-  public synchronized void unset(String name) {
-    getOverlay().remove(name);
-    getProps().remove(name);
+  public void unset(String name) {
+    properties.remove(name);
   }
 
   /**
@@ -551,13 +311,6 @@ public class RaftProperties {
     }
   }
 
-  private synchronized Properties getOverlay() {
-    if (overlay == null){
-      overlay = new Properties();
-    }
-    return overlay;
-  }
-
   /**
    * Get the value of the <code>name</code>. If the key is deprecated,
    * it returns the value of the first key which replaces the deprecated key
@@ -571,7 +324,7 @@ public class RaftProperties {
    *         doesn't exist.
    */
   public String get(String name, String defaultValue) {
-    return substituteVars(getProps().getProperty(name, defaultValue));
+    return substituteVars(properties.getOrDefault(name, defaultValue));
   }
 
   /**
@@ -764,15 +517,6 @@ public class RaftProperties {
     set(name, Boolean.toString(value));
   }
 
-  /**
-   * Set the given property, if it is currently unset.
-   * @param name property name
-   * @param value new value
-   */
-  public void setBooleanIfUnset(String name, boolean value) {
-    setIfUnset(name, Boolean.toString(value));
-  }
-
   /**
    * Set the value of the <code>name</code> property to the given type. This
    * is equivalent to <code>set(&lt;name&gt;, value.toString())</code>.
@@ -834,43 +578,6 @@ public class RaftProperties {
     return (key, defaultValue) -> getTimeDuration(key, defaultValue, 
defaultUnit);
   }
 
-  /**
-   * Get the value of the <code>name</code> property as a <code>Pattern</code>.
-   * If no such property is specified, or if the specified value is not a valid
-   * <code>Pattern</code>, then <code>DefaultValue</code> is returned.
-   * Note that the returned value is NOT trimmed by this method.
-   *
-   * @param name property name
-   * @param defaultValue default value
-   * @return property value as a compiled Pattern, or defaultValue
-   */
-  public Pattern getPattern(String name, Pattern defaultValue) {
-    String valString = get(name);
-    if (null == valString || valString.isEmpty()) {
-      return defaultValue;
-    }
-    try {
-      return Pattern.compile(valString);
-    } catch (PatternSyntaxException pse) {
-      LOG.warn("Regular expression '" + valString + "' for property '" +
-               name + "' not valid. Using default", pse);
-      return defaultValue;
-    }
-  }
-
-  /**
-   * Set the given property to <code>Pattern</code>.
-   * If the pattern is passed as null, sets the empty pattern which results in
-   * further calls to getPattern(...) returning the default value.
-   *
-   * @param name property name
-   * @param pattern new value
-   */
-  public void setPattern(String name, Pattern pattern) {
-    assert pattern != null : "Pattern cannot be null";
-    set(name, pattern.pattern());
-  }
-
   /**
    * Get the comma delimited values of the <code>name</code> property as
    * an array of <code>String</code>s, trimmed of the leading and trailing 
whitespace.
@@ -989,291 +696,20 @@ public class RaftProperties {
     set(name, theClass.getName());
   }
 
-  protected synchronized Properties getProps() {
-    if (properties == null) {
-      properties = new Properties();
-      Map<String, String[]> backup =
-          new ConcurrentHashMap<>(updatingResource);
-      loadResources();
-
-      if (overlay != null) {
-        properties.putAll(overlay);
-        for (Entry<Object,Object> item: overlay.entrySet()) {
-          String key = (String) item.getKey();
-          String[] source = backup.get(key);
-          if(source != null) {
-            updatingResource.put(key, source);
-          }
-        }
-      }
-    }
-    return properties;
-  }
-
-  /**
-   * Return the number of keys in the configuration.
-   *
-   * @return number of keys in the configuration.
-   */
+  /** @return number of keys in the properties. */
   public int size() {
-    return getProps().size();
+    return properties.size();
   }
 
   /**
    * Clears all keys from the configuration.
    */
   public void clear() {
-    getProps().clear();
-    getOverlay().clear();
-  }
-
-  private Document parse(DocumentBuilder builder, URL url)
-      throws IOException, SAXException {
-    LOG.debug("parsing URL " + url);
-    if (url == null) {
-      return null;
-    }
-
-    URLConnection connection = url.openConnection();
-    if (connection instanceof JarURLConnection) {
-      // Disable caching for JarURLConnection to avoid sharing JarFile
-      // with other users.
-      connection.setUseCaches(false);
-    }
-    return parse(builder, connection.getInputStream(), url.toString());
-  }
-
-  private Document parse(DocumentBuilder builder, InputStream is,
-      String systemId) throws IOException, SAXException {
-    LOG.debug("parsing input stream " + is);
-    if (is == null) {
-      return null;
-    }
-    try {
-      return (systemId == null) ? builder.parse(is) : builder.parse(is,
-          systemId);
-    } finally {
-      is.close();
-    }
-  }
-
-  private void loadResources() {
-    if(loadDefaults) {
-      for (String resource : DEFAULT_RESOURCES) {
-        loadResource(properties, new Resource(resource));
-      }
-    }
-
-    for (int i = 0; i < resources.size(); i++) {
-      Resource ret = loadResource(properties, resources.get(i));
-      if (ret != null) {
-        resources.set(i, ret);
-      }
-    }
-  }
-
-  private Resource loadResource(Properties propts, Resource wrapper) {
-    String name = UNKNOWN_RESOURCE;
-    try {
-      Object resource = wrapper.getResource();
-      name = wrapper.getName();
-
-      DocumentBuilderFactory docBuilderFactory = 
DocumentBuilderFactory.newInstance();
-      docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, 
true);
-      docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-      docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-      //ignore all comments inside the xml file
-      docBuilderFactory.setIgnoringComments(true);
-
-      //allow includes in the xml file
-      docBuilderFactory.setNamespaceAware(true);
-      try {
-          docBuilderFactory.setXIncludeAware(true);
-      } catch (UnsupportedOperationException e) {
-        LOG.error("Failed to set setXIncludeAware(true) for parser " + 
docBuilderFactory + ":" + e, e);
-      }
-      DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
-      Document doc = null;
-      Element root = null;
-      boolean returnCachedProperties = false;
-
-      if (resource instanceof URL) { // an URL resource
-        doc = parse(builder, (URL) resource);
-      } else if (resource instanceof String) { // a CLASSPATH resource
-        URL url = 
ReflectionUtils.getClassLoader().getResource((String)resource);
-        doc = parse(builder, url);
-      } else if (resource instanceof InputStream) {
-        doc = parse(builder, (InputStream) resource, null);
-        returnCachedProperties = true;
-      } else if (resource instanceof Properties) {
-        overlay(propts, (Properties) resource);
-      } else if (resource instanceof Element) {
-        root = (Element) resource;
-      }
-
-      if (root == null) {
-        if (doc == null) {
-          return null;
-        }
-        root = doc.getDocumentElement();
-      }
-      Properties toAddTo = propts;
-      if(returnCachedProperties) {
-        toAddTo = new Properties();
-      }
-      if (!"configuration".equals(root.getTagName())) {
-        LOG.error("bad conf file: top-level element not <configuration>");
-      }
-      NodeList props = root.getChildNodes();
-      for (int i = 0; i < props.getLength(); i++) {
-        Node propNode = props.item(i);
-        if (!(propNode instanceof Element)) {
-          continue;
-        }
-
-        Element prop = (Element)propNode;
-        if ("configuration".equals(prop.getTagName())) {
-          loadResource(toAddTo, new Resource(prop, name));
-          continue;
-        }
-        if (!"property".equals(prop.getTagName())) {
-          LOG.warn("bad conf file: element not <property>");
-        }
-
-        String attr = null;
-        String value = null;
-        boolean finalParameter = false;
-        LinkedList<String> source = new LinkedList<>();
-
-        Attr propAttr = prop.getAttributeNode("name");
-        if (propAttr != null) {
-          attr = StringUtils.weakIntern(propAttr.getValue());
-        }
-        propAttr = prop.getAttributeNode("value");
-        if (propAttr != null) {
-          value = StringUtils.weakIntern(propAttr.getValue());
-        }
-        propAttr = prop.getAttributeNode("final");
-        if (propAttr != null) {
-          finalParameter = "true".equals(propAttr.getValue());
-        }
-        propAttr = prop.getAttributeNode("source");
-        if (propAttr != null) {
-          source.add(StringUtils.weakIntern(propAttr.getValue()));
-        }
-
-        NodeList fields = prop.getChildNodes();
-        for (int j = 0; j < fields.getLength(); j++) {
-          Node fieldNode = fields.item(j);
-          if (!(fieldNode instanceof Element)) {
-            continue;
-          }
-          Element field = (Element)fieldNode;
-          if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
-            attr = StringUtils.weakIntern(
-                ((Text)field.getFirstChild()).getData().trim());
-          }
-          if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
-            value = StringUtils.weakIntern(
-                ((Text)field.getFirstChild()).getData());
-          }
-          if ("final".equals(field.getTagName()) && field.hasChildNodes()) {
-            finalParameter = 
"true".equals(((Text)field.getFirstChild()).getData());
-          }
-          if ("source".equals(field.getTagName()) && field.hasChildNodes()) {
-            source.add(StringUtils.weakIntern(
-                ((Text)field.getFirstChild()).getData()));
-          }
-        }
-        source.add(name);
-
-        // Ignore this parameter if it has already been marked as 'final'
-        if (attr != null) {
-          loadProperty(toAddTo, name, attr, value, finalParameter,
-              source.toArray(new String[source.size()]));
-        }
-      }
-
-      if (returnCachedProperties) {
-        overlay(propts, toAddTo);
-        return new Resource(toAddTo, name);
-      }
-      return null;
-    } catch (IOException | DOMException | SAXException |
-        ParserConfigurationException e) {
-      LOG.error("error parsing conf " + name, e);
-      throw new RuntimeException(e);
-    }
-  }
-
-  private void overlay(Properties to, Properties from) {
-    for (Entry<Object, Object> entry: from.entrySet()) {
-      to.put(entry.getKey(), entry.getValue());
-    }
-  }
-
-  private void loadProperty(Properties prop, String name, String attr,
-      String value, boolean finalParameter, String[] source) {
-    if (value != null) {
-      if (!finalParameters.contains(attr)) {
-        prop.setProperty(attr, value);
-        if(source != null) {
-          updatingResource.put(attr, source);
-        }
-      } else if (!value.equals(prop.getProperty(attr))) {
-        LOG.warn(name+":an attempt to override final parameter: "+attr
-            +";  Ignoring.");
-      }
-    }
-    if (finalParameter && attr != null) {
-      finalParameters.add(attr);
-    }
+    properties.clear();
   }
 
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder();
-    sb.append("Configuration: ");
-    if(loadDefaults) {
-      toString(DEFAULT_RESOURCES, sb);
-      if(resources.size()>0) {
-        sb.append(", ");
-      }
-    }
-    toString(resources, sb);
-    return sb.toString();
-  }
-
-  private <T> void toString(List<T> res, StringBuilder sb) {
-    ListIterator<T> i = res.listIterator();
-    while (i.hasNext()) {
-      if (i.nextIndex() != 0) {
-        sb.append(", ");
-      }
-      sb.append(i.next());
-    }
-  }
-
-  /**
-   * get keys matching the the regex
-   * @return a map with matching keys
-   */
-  public Map<String,String> getValByRegex(String regex) {
-    Pattern p = Pattern.compile(regex);
-
-    Map<String,String> result = new HashMap<>();
-    Matcher m;
-
-    for(Entry<Object,Object> item: getProps().entrySet()) {
-      if (item.getKey() instanceof String &&
-          item.getValue() instanceof String) {
-        m = p.matcher((String)item.getKey());
-        if(m.find()) { // match
-          result.put((String) item.getKey(),
-              substituteVars(getProps().getProperty((String) item.getKey())));
-        }
-      }
-    }
-    return result;
+    return JavaUtils.getClassSimpleName(getClass()) + ":" + size();
   }
 }
diff --git 
a/ratis-examples/src/test/java/org/apache/ratis/examples/filestore/FileStoreWriter.java
 
b/ratis-examples/src/test/java/org/apache/ratis/examples/filestore/FileStoreWriter.java
index ac869d42..dbffab8a 100644
--- 
a/ratis-examples/src/test/java/org/apache/ratis/examples/filestore/FileStoreWriter.java
+++ 
b/ratis-examples/src/test/java/org/apache/ratis/examples/filestore/FileStoreWriter.java
@@ -130,7 +130,7 @@ class FileStoreWriter implements Closeable {
           fileName, offset, length, close);
       final long written = client.write(fileName, offset, close, b, sync);
       Assert.assertEquals(length, written);
-      offset += written;
+      offset += length;
     }
     return this;
   }
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestSegmentedRaftLog.java
 
b/ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestSegmentedRaftLog.java
index e1fff149..50ec159b 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestSegmentedRaftLog.java
+++ 
b/ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestSegmentedRaftLog.java
@@ -665,7 +665,7 @@ public class TestSegmentedRaftLog extends BaseTest {
     testFailureCase("testSegmentedRaftLogFormatInternalHeader",
         () -> SegmentedRaftLogFormat.applyHeaderTo(header -> {
           LOG.info("header  = " + new String(header, StandardCharsets.UTF_8));
-          header[0] += 1; // try changing the internal header
+          header[0]++; // try changing the internal header
           LOG.info("header' = " + new String(header, StandardCharsets.UTF_8));
           return null;
         }), IllegalStateException.class);
diff --git a/ratis-test/src/test/java/org/apache/ratis/util/TestDataQueue.java 
b/ratis-test/src/test/java/org/apache/ratis/util/TestDataQueue.java
index e629b165..fe8a7ac2 100644
--- a/ratis-test/src/test/java/org/apache/ratis/util/TestDataQueue.java
+++ b/ratis-test/src/test/java/org/apache/ratis/util/TestDataQueue.java
@@ -43,7 +43,7 @@ public class TestDataQueue {
 
   final SizeInBytes byteLimit = SizeInBytes.valueOf(100);
   final int elementLimit = 5;
-  final DataQueue<Long> q = new DataQueue<Long>(null, byteLimit, elementLimit, 
Long::longValue);
+  final DataQueue<Long> q = new DataQueue<>(null, byteLimit, elementLimit, 
Long::longValue);
 
   @Test(timeout = 1000)
   public void testElementLimit() {
@@ -54,7 +54,7 @@ public class TestDataQueue {
     assertSizes(0, 0, q);
 
     final int elementLimit = q.getElementLimit();
-    int numBytes = 0;
+    long numBytes = 0;
     for (long i = 0; i < elementLimit; i++) {
       Assert.assertEquals(i, q.getNumElements());
       Assert.assertEquals(numBytes, q.getNumBytes());
@@ -146,7 +146,7 @@ public class TestDataQueue {
 
     final int elementLimit = q.getElementLimit();
     int numElements = 0;
-    int numBytes = 0;
+    long numBytes = 0;
     for(long i = 0; i < elementLimit; i++) {
       final boolean offered = q.offer(i);
       Assert.assertTrue(offered);
@@ -184,7 +184,7 @@ public class TestDataQueue {
   public void testTimeout() {
     assertSizes(0, 0, q);
 
-    int numBytes = 0;
+    long numBytes = 0;
     for (long i = 0; i < elementLimit; i++) {
       Assert.assertEquals(i, q.getNumElements());
       Assert.assertEquals(numBytes, q.getNumBytes());

Reply via email to