geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [geode] branch feature/GEODE-6196 updated: code cleanup and fixing a unit test failure by reverting a change I made
Date Wed, 06 Mar 2019 00:26:57 GMT
This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch feature/GEODE-6196
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-6196 by this push:
     new e485104  code cleanup and fixing a unit test failure by reverting a change I made
e485104 is described below

commit e48510440840524de75f34aee8bb2cdae4f0fb64
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
AuthorDate: Tue Mar 5 16:25:45 2019 -0800

    code cleanup and fixing a unit test failure by reverting a change I made
---
 .../geode/management/QueryDataDUnitTest.java       |  4 +--
 .../internal/cli/json/QueryResultFormatter.java    | 42 +++++++++-------------
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/QueryDataDUnitTest.java
b/geode-core/src/distributedTest/java/org/apache/geode/management/QueryDataDUnitTest.java
index 0d4e292..fa037cd 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/QueryDataDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/QueryDataDUnitTest.java
@@ -254,7 +254,7 @@ public class QueryDataDUnitTest implements Serializable {
       JSONArray jsonArray1 = jsonArray.getJSONArray(0);
 
       // Get the ObjectValue
-      JSONArray collectionObject = (JSONArray) jsonArray1.get(1);
+      JSONObject collectionObject = (JSONObject) jsonArray1.get(1);
       assertThat(collectionObject.length()).isEqualTo(100);
 
       // Query With Override Values
@@ -284,7 +284,7 @@ public class QueryDataDUnitTest implements Serializable {
       jsonArray1 = jsonArray.getJSONArray(0);
 
       // Get the ObjectValue
-      collectionObject = (JSONArray) jsonArray1.get(1);
+      collectionObject = (JSONObject) jsonArray1.get(1);
       assertThat(collectionObject.length()).isEqualTo(newQueryCollectionDepth);
     });
   }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/QueryResultFormatter.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/QueryResultFormatter.java
index 935f1d7..55f2d0e 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/QueryResultFormatter.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/QueryResultFormatter.java
@@ -53,7 +53,6 @@ import org.apache.geode.pdx.PdxInstance;
 public class QueryResultFormatter {
 
   private final ObjectMapper mapper;
-  private final SimpleModule mapperModule;
 
   /**
    * map contains the named objects to be serialized
@@ -82,12 +81,14 @@ public class QueryResultFormatter {
    * @param maxCollectionElements limit on collection elements
    * @param serializationDepth when traversing objects, how deep should we go?
    */
-  public QueryResultFormatter(int maxCollectionElements, int serializationDepth) {
+  private QueryResultFormatter(int maxCollectionElements, int serializationDepth) {
     this.map = new LinkedHashMap<>();
 
     this.serializedObjects = new IdentityHashMap<>();
     this.mapper = new ObjectMapper();
-    this.mapperModule = new SimpleModule() {
+    // install a modifier that prevents recursive serialization in cases where
+    // there are cyclical references
+    SimpleModule mapperModule = new SimpleModule() {
       @Override
       public void setupModule(SetupContext context) {
         // install a modifier that prevents recursive serialization in cases where
@@ -130,7 +131,7 @@ public class QueryResultFormatter {
    * After instantiating a formatter add the objects you want to be formatted
    * using this method. Typically this will be add("result", queryResult)
    */
-  public QueryResultFormatter add(String key, Object value) {
+  public synchronized QueryResultFormatter add(String key, Object value) {
     List<Object> list = this.map.get(key);
     if (list != null) {
       list.add(value);
@@ -146,23 +147,10 @@ public class QueryResultFormatter {
 
   /* non-javadoc use Jackson to serialize added objects into JSON format */
   @Override
-  public String toString() {
-    StringWriter w = new StringWriter();
-    synchronized (w.getBuffer()) {
-      try {
-        return this.write(w).toString();
-      } catch (Exception e) {
-        e.printStackTrace();
-        return null;
-      }
-    }
-  }
-
-
-  private Writer write(Writer writer) throws GfJsonException {
+  public synchronized String toString() {
+    Writer writer = new StringWriter();
     try {
       boolean addComma = false;
-
       writer.write('{');
       for (Map.Entry<String, List<Object>> entry : this.map.entrySet()) {
         if (addComma) {
@@ -175,12 +163,16 @@ public class QueryResultFormatter {
       }
       writer.write('}');
 
-      return writer;
+      return writer.toString();
     } catch (IOException exception) {
-      throw new GfJsonException(exception);
+      new GfJsonException(exception).printStackTrace();
+    } catch (GfJsonException e) {
+      e.printStackTrace();
     }
+    return null;
   }
 
+
   private Writer writeList(Writer writer, List<Object> values) throws GfJsonException
{
     // for each object we clear out the serializedObjects recursion map so that
     // we don't immediately see "duplicate" entries
@@ -343,7 +335,7 @@ public class QueryResultFormatter {
       gen.writeEndObject();
     }
 
-    public void _serialize(Collection value, JsonGenerator gen) throws IOException {
+    void _serialize(Collection value, JsonGenerator gen) throws IOException {
       Iterator<Object> objects = value.iterator();
       for (int i = 0; i < maxCollectionElements && objects.hasNext(); i++) {
         Object nextObject = objects.next();
@@ -377,7 +369,7 @@ public class QueryResultFormatter {
       gen.writeEndObject();
     }
 
-    public void _serialize(PdxInstance value, JsonGenerator gen) throws IOException {
+    void _serialize(PdxInstance value, JsonGenerator gen) throws IOException {
       for (String field : value.getFieldNames()) {
         gen.writeObjectField(field, value.getField(field));
       }
@@ -407,8 +399,8 @@ public class QueryResultFormatter {
       gen.writeEndObject();
     }
 
-    public void _serialize(StructImpl value, JsonGenerator gen) throws IOException {
-      String fields[] = value.getFieldNames();
+    void _serialize(StructImpl value, JsonGenerator gen) throws IOException {
+      String[] fields = value.getFieldNames();
       Object[] values = value.getFieldValues();
       for (int i = 0; i < fields.length; i++) {
         gen.writeObjectField(fields[i], values[i]);


Mime
View raw message