ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-7195 correction for initial fix (addition for commit 5d66516d18b84878331918b79afe452d70bd7a42).
Date Thu, 11 Jan 2018 10:35:01 GMT
Repository: ignite
Updated Branches:
  refs/heads/master ba9c11041 -> 6f943820a


ignite-7195 correction for initial fix (addition for commit 5d66516d18b84878331918b79afe452d70bd7a42).


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

Branch: refs/heads/master
Commit: 6f943820a4d9f65383854bd4b567352019d320df
Parents: ba9c110
Author: Alexander Belyak <alexandr.belyak@xored.com>
Authored: Thu Jan 11 13:34:50 2018 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Jan 11 13:34:50 2018 +0300

----------------------------------------------------------------------
 .../util/tostring/CircularStringBuilder.java    | 16 +++++++-
 .../util/tostring/GridToStringBuilder.java      |  2 +-
 .../internal/util/tostring/SBLengthLimit.java   | 33 ++++++++-------
 .../internal/util/tostring/SBLimitedLength.java | 43 ++++++++++++--------
 .../tostring/GridToStringBuilderSelfTest.java   | 20 +++++----
 5 files changed, 72 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6f943820/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/CircularStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/CircularStringBuilder.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/CircularStringBuilder.java
index 4f33724..856da80 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/CircularStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/CircularStringBuilder.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.util.tostring;
 
+import java.util.Arrays;
+
 /**
  * Basic string builder over circular buffer.
  */
@@ -46,6 +48,16 @@ public class CircularStringBuilder {
     }
 
     /**
+     * Reset internal builder state
+     */
+    public void reset() {
+        Arrays.fill(value,(char)0);
+        finishAt = -1;
+        full = false;
+        skipped = 0;
+    }
+
+    /**
      * Returns the length (character count).
      *
      * @return  the length of the sequence of characters currently
@@ -108,6 +120,8 @@ public class CircularStringBuilder {
                 skipped += full ? objStrLen : objStrLen - firstPart;
 
                 finishAt = finishAt + objStrLen - value.length;
+
+                full = true;
             }
             else {
                 // Whole string fin into remaining part of value array
@@ -117,8 +131,6 @@ public class CircularStringBuilder {
 
                 finishAt += objStrLen;
             }
-
-            full = full || finishAt + objStrLen >= value.length - 1;
         }
 
         return this;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6f943820/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index e633ded..a5f2c95 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -1047,7 +1047,7 @@ public class GridToStringBuilder {
      * @return String representation of an array.
      */
     @SuppressWarnings({"ConstantConditions", "unchecked"})
-    public static <T> String arrayToString(Class arrType, Object arr) {
+    public static <T> String arrayToString(Class arrType, @Nullable Object arr) {
         if (arr == null)
             return "null";
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6f943820/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLengthLimit.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLengthLimit.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLengthLimit.java
index 0c78d73..783efd6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLengthLimit.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLengthLimit.java
@@ -28,9 +28,12 @@ class SBLengthLimit {
     /** */
     private static final int MAX_TO_STR_LEN = IgniteSystemProperties.getInteger(IGNITE_TO_STRING_MAX_LENGTH,
10_000);
 
-    /** Length of tail part of message */
+    /** Length of tail part of message. */
     private static final int TAIL_LEN = MAX_TO_STR_LEN / 10 * 2;
 
+    /** Length of head part of message. */
+    private static final int HEAD_LEN = MAX_TO_STR_LEN - TAIL_LEN;
+
     /** */
     private int len;
 
@@ -55,23 +58,25 @@ class SBLengthLimit {
     void onWrite(SBLimitedLength sb, int writtenLen) {
         len += writtenLen;
 
-// TODO IGNITE-7195
-//        if (len > MAX_TO_STR_LEN && sb.getTail() == null) {
-//            CircularStringBuilder tail = new CircularStringBuilder(TAIL_LEN);
-//
-//            tail.append(sb.impl().substring(MAX_TO_STR_LEN - TAIL_LEN));
-//
-//            sb.setTail(tail);
-//            sb.setLength(MAX_TO_STR_LEN - TAIL_LEN);
-//        }
+        if (overflowed(sb) && (sb.getTail() == null || sb.getTail().length() == 0))
{
+            CircularStringBuilder tail = getTail();
+
+            int newSbLen = Math.min(sb.length(), HEAD_LEN + 1);
+            tail.append(sb.impl().substring(newSbLen));
+
+            sb.setTail(tail);
+            sb.setLength(newSbLen);
+        }
+    }
+
+    CircularStringBuilder getTail() {
+        return new CircularStringBuilder(TAIL_LEN);
     }
 
     /**
      * @return {@code True} if reached limit.
      */
-    boolean overflowed() {
-        // TODO IGNITE-7195
-        return false;
-        //return len > MAX_TO_STR_LEN;
+    boolean overflowed(SBLimitedLength sb) {
+        return sb.impl().length() > HEAD_LEN;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6f943820/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
index 8574d9e..c47cf40 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
@@ -45,7 +45,9 @@ public class SBLimitedLength extends GridStringBuilder {
      */
     void initLimit(SBLengthLimit lenLimit) {
         this.lenLimit = lenLimit;
-        tail = null;
+
+        if (tail != null)
+            tail.reset();
     }
 
     /**
@@ -76,7 +78,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(Object obj) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(obj);
             return this;
         }
@@ -90,7 +92,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(String str) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(str);
             return this;
         }
@@ -104,7 +106,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(StringBuffer sb) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(sb);
             return this;
         }
@@ -118,7 +120,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(CharSequence s) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(s);
             return this;
         }
@@ -132,7 +134,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(CharSequence s, int start, int end) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(s.subSequence(start, end));
             return this;
         }
@@ -146,7 +148,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(char[] str) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(str);
             return this;
         }
@@ -160,7 +162,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(char[] str, int offset, int len) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(Arrays.copyOfRange(str, offset, len));
             return this;
         }
@@ -174,7 +176,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(boolean b) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(b);
             return this;
         }
@@ -188,7 +190,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(char c) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(c);
             return this;
         }
@@ -202,7 +204,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(int i) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(i);
             return this;
         }
@@ -216,7 +218,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(long lng) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(lng);
             return this;
         }
@@ -230,7 +232,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(float f) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(f);
             return this;
         }
@@ -244,7 +246,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder a(double d) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(d);
             return this;
         }
@@ -258,7 +260,7 @@ public class SBLimitedLength extends GridStringBuilder {
 
     /** {@inheritDoc} */
     @Override public GridStringBuilder appendCodePoint(int codePoint) {
-        if (lenLimit.overflowed()) {
+        if (lenLimit.overflowed(this)) {
             tail.append(codePoint);
             return this;
         }
@@ -276,11 +278,16 @@ public class SBLimitedLength extends GridStringBuilder {
             return super.toString();
         else {
             int tailLen = tail.length();
-            StringBuilder res = new StringBuilder(impl().capacity() + 100);
+            StringBuilder res = new StringBuilder(impl().capacity() + tailLen + 100);
 
             res.append(impl());
-            res.append("... and ").append(String.valueOf(tail.getSkipped() + tailLen))
-                .append(" skipped ...").append(tail.toString());
+
+            if (tail.getSkipped() > 0) {
+                res.append("... and ").append(String.valueOf(tail.getSkipped() + tailLen))
+                    .append(" skipped ...");
+            }
+
+            res.append(tail.toString());
 
             return res.toString();
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6f943820/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
index e4c20f9..04186a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
@@ -190,10 +190,6 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest
{
      * @throws Exception If failed.
      */
     public void testToStringSizeLimits() throws Exception {
-        // TODO IGNITE-7195
-        if (true)
-            return;
-
         int limit = IgniteSystemProperties.getInteger(IGNITE_TO_STRING_MAX_LENGTH, 10_000);
         int tailLen = limit / 10 * 2;
         StringBuilder sb = new StringBuilder(limit + 10);
@@ -201,14 +197,14 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest
{
             sb.append('a');
         }
         String actual = GridToStringBuilder.toString(TestClass2.class, new TestClass2(sb.toString()));
-        String expected = "TestClass2 [str=" + sb.toString() + "]";
+        String expected = "TestClass2 [str=" + sb.toString() + ", nullArr=null]";
         assertEquals(expected, actual);
 
-        for (int i = 0; i < 100; i++) {
+        for (int i = 0; i < 110; i++) {
             sb.append('b');
         }
         actual = GridToStringBuilder.toString(TestClass2.class, new TestClass2(sb.toString()));
-        expected = "TestClass2 [str=" + sb.toString() + "]";
+        expected = "TestClass2 [str=" + sb.toString() + ", nullArr=null]";
         assertEquals(expected.substring(0, limit - tailLen), actual.substring(0, limit -
tailLen));
         assertEquals(expected.substring(expected.length() - tailLen), actual.substring(actual.length()
- tailLen));
         assertTrue(actual.contains("... and"));
@@ -330,12 +326,22 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest
{
         }
     }
 
+    /**
+     *
+     */
     private static class TestClass2{
         /** */
         @SuppressWarnings("unused")
         @GridToStringInclude
         private String str;
 
+        /** */
+        @GridToStringInclude
+        private Object[] nullArr;
+
+        /**
+         * @param str String.
+         */
         public TestClass2(String str) {
             this.str = str;
         }


Mime
View raw message