You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2019/06/18 10:10:58 UTC

[cassandra] branch trunk updated: Fix leak in FramingTest unit test case

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

aleksey pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new abb0e17  Fix leak in FramingTest unit test case
abb0e17 is described below

commit abb0e17785b50baee6e53ee02bd367a5ce9455f8
Author: nvharikrishna <n....@gmail.com>
AuthorDate: Mon Jun 17 15:18:03 2019 +0530

    Fix leak in FramingTest unit test case
    
    patch by Hari Nukala; reviewed by Aleksey Yeschenko for CASSANDRA-15165
---
 .../org/apache/cassandra/net/ShareableBytes.java     |  4 ++--
 test/unit/org/apache/cassandra/net/FramingTest.java  | 20 +++++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/java/org/apache/cassandra/net/ShareableBytes.java b/src/java/org/apache/cassandra/net/ShareableBytes.java
index feea25e..e4f2460 100644
--- a/src/java/org/apache/cassandra/net/ShareableBytes.java
+++ b/src/java/org/apache/cassandra/net/ShareableBytes.java
@@ -40,14 +40,14 @@ class ShareableBytes
     private static final AtomicIntegerFieldUpdater<ShareableBytes> countUpdater =
         AtomicIntegerFieldUpdater.newUpdater(ShareableBytes.class, "count");
 
-    ShareableBytes(ByteBuffer bytes)
+    private ShareableBytes(ByteBuffer bytes)
     {
         this.count = UNSHARED;
         this.owner = this;
         this.bytes = bytes;
     }
 
-    ShareableBytes(ShareableBytes owner, ByteBuffer bytes)
+    private ShareableBytes(ShareableBytes owner, ByteBuffer bytes)
     {
         this.owner = owner;
         this.bytes = bytes;
diff --git a/test/unit/org/apache/cassandra/net/FramingTest.java b/test/unit/org/apache/cassandra/net/FramingTest.java
index ec6cd84..8a7f428 100644
--- a/test/unit/org/apache/cassandra/net/FramingTest.java
+++ b/test/unit/org/apache/cassandra/net/FramingTest.java
@@ -118,7 +118,7 @@ public class FramingTest
         testSomeFrames(FrameEncoderCrc.instance, FrameDecoderCrc.create(GlobalBufferPoolAllocator.instance));
     }
 
-    public void testSomeFrames(FrameEncoder encoder, FrameDecoder decoder)
+    private void testSomeFrames(FrameEncoder encoder, FrameDecoder decoder)
     {
         long seed = new SecureRandom().nextLong();
         logger.info("seed: {}, decoder: {}", seed, decoder.getClass().getSimpleName());
@@ -156,7 +156,7 @@ public class FramingTest
         for (FrameDecoder.Frame frame : out)
             frame.release();
         frames.release();
-        Assert.assertEquals(null, decoder.stash);
+        Assert.assertNull(decoder.stash);
         Assert.assertTrue(decoder.frames.isEmpty());
     }
 
@@ -213,7 +213,7 @@ public class FramingTest
         burnRandomLegacy(1000);
     }
 
-    public void burnRandomLegacy(int count)
+    private void burnRandomLegacy(int count)
     {
         SecureRandom seed = new SecureRandom();
         Random random = new Random();
@@ -234,7 +234,7 @@ public class FramingTest
         testRandomLegacy(250);
     }
 
-    public void testRandomLegacy(int count)
+    private void testRandomLegacy(int count)
     {
         SecureRandom seeds = new SecureRandom();
         for (int messagingVersion : new int[] { VERSION_30, VERSION_3014, current_version})
@@ -247,7 +247,7 @@ public class FramingTest
         }
     }
 
-    public void testSomeMessages(long seed, int count, float largeRatio, int messagingVersion, FrameDecoder decoder)
+    private void testSomeMessages(long seed, int count, float largeRatio, int messagingVersion, FrameDecoder decoder)
     {
         logger.info("seed: {}, iterations: {}, largeRatio: {}, messagingVersion: {}, decoder: {}", seed, count, largeRatio, messagingVersion, decoder.getClass().getSimpleName());
         Random random = new Random(seed);
@@ -291,7 +291,7 @@ public class FramingTest
                     // we should have an initial frame containing only some prefix of the message (probably 64 bytes)
                     // that was stashed only to decide how big the message was
                     FrameDecoder.IntactFrame frame = (FrameDecoder.IntactFrame) out.get(outIndex++);
-                    Assert.assertEquals(false, frame.isSelfContained);
+                    Assert.assertFalse(frame.isSelfContained);
                     start = frame.contents.remaining();
                     verify(message, 0, frame.contents.remaining(), frame.contents);
                 }
@@ -328,7 +328,6 @@ public class FramingTest
             }
 
             // message is fresh
-            int beginFrame = messageStart;
             int beginFrameIndex = messageIndex;
             while (messageStart + message.length <= limit)
             {
@@ -344,7 +343,9 @@ public class FramingTest
                 while (beginFrameIndex < messageIndex)
                 {
                     byte[] m = messages.get(beginFrameIndex);
-                    verify(m, frame.contents.sliceAndConsume(m.length));
+                    ShareableBytes bytesToVerify = frame.contents.sliceAndConsume(m.length);
+                    verify(m, bytesToVerify);
+                    bytesToVerify.release();
                     ++beginFrameIndex;
                 }
                 Assert.assertFalse(frame.contents.hasRemaining());
@@ -367,7 +368,8 @@ public class FramingTest
             i = limit;
         }
         stream.release();
-        Assert.assertEquals(null, decoder.stash);
+        Assert.assertTrue(stream.isReleased());
+        Assert.assertNull(decoder.stash);
         Assert.assertTrue(decoder.frames.isEmpty());
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org