cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: Fix SafeMemoryWriterTest
Date Thu, 30 Aug 2018 17:13:07 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk f8d34d356 -> 8b1a6247e


Fix SafeMemoryWriterTest

patch by Robert Stupp; reviewed by Branimir Lambov for CASSANDRA-14681


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/8b1a6247
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/8b1a6247
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/8b1a6247

Branch: refs/heads/trunk
Commit: 8b1a6247ec5aabad92a664ff2cbf6d6529d8ceb7
Parents: f8d34d3
Author: Robert Stupp <snazy@snazy.de>
Authored: Thu Aug 30 19:10:57 2018 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Thu Aug 30 19:10:57 2018 +0200

----------------------------------------------------------------------
 .../cassandra/io/util/SafeMemoryWriterTest.java | 28 +++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8b1a6247/test/unit/org/apache/cassandra/io/util/SafeMemoryWriterTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/util/SafeMemoryWriterTest.java b/test/unit/org/apache/cassandra/io/util/SafeMemoryWriterTest.java
index 12c8c98..8b37c2d 100644
--- a/test/unit/org/apache/cassandra/io/util/SafeMemoryWriterTest.java
+++ b/test/unit/org/apache/cassandra/io/util/SafeMemoryWriterTest.java
@@ -24,8 +24,6 @@ import java.util.Random;
 import org.junit.Assert;
 import org.junit.Test;
 
-import sun.misc.VM;
-
 import static org.junit.Assert.assertEquals;
 
 public class SafeMemoryWriterTest
@@ -33,6 +31,28 @@ public class SafeMemoryWriterTest
     Random rand = new Random();
     static final int CHUNK = 54321;
 
+    static final long maxDirectMemory;
+    static
+    {
+        try
+        {
+            Class<?> cVM;
+            try
+            {
+                cVM = Class.forName("jdk.internal.misc.VM");
+            }
+            catch (ClassNotFoundException e)
+            {
+                cVM = Class.forName("sun.misc.VM");
+            }
+            maxDirectMemory = (Long) cVM.getDeclaredMethod("maxDirectMemory").invoke(null);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
     @Test
     public void testTrim() throws IOException
     {
@@ -51,9 +71,9 @@ public class SafeMemoryWriterTest
         while (initialSize * 2 / 3 > 1024L * 1024L * DataOutputBuffer.DOUBLING_THRESHOLD)
             initialSize = initialSize * 2 / 3;
 
-        if (VM.maxDirectMemory() * 2 / 3 < testSize)
+        if (maxDirectMemory * 2 / 3 < testSize)
         {
-            testSize = VM.maxDirectMemory() * 2 / 3;
+            testSize = maxDirectMemory * 2 / 3;
             System.err.format("Insufficient direct memory for full test, reducing to: %,d
%x\n", testSize, testSize);
         }
 


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


Mime
View raw message