< prev index next >

test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java

Print this page
@  rev 57446 : Review changes
|
~


  48                 break;
  49         }
  50     }
  51 
  52     private static void testMemoryLimit(String value) {
  53         long limit = getMemoryValue(value);
  54 
  55         if (limit != Metrics.systemMetrics().getMemoryLimit()) {
  56             throw new RuntimeException("Memory limit not equal, expected : ["
  57                     + limit + "]" + ", got : ["
  58                     + Metrics.systemMetrics().getMemoryLimit() + "]");
  59         }
  60         System.out.println("TEST PASSED!!!");
  61     }
  62 
  63     private static void testMemoryFailCount() {
  64         long count = Metrics.systemMetrics().getMemoryFailCount();
  65 
  66         // Allocate 512M of data
  67         byte[][] bytes = new byte[64][];

  68         for (int i = 0; i < 64; i++) {
  69             try {
  70                 bytes[i] = new byte[8 * 1024 * 1024];

  71                 // Break out as soon as we see an increase in failcount
  72                 // to avoid getting killed by the OOM killer.
  73                 if (Metrics.systemMetrics().getMemoryFailCount() > count) {
  74                     break;
  75                 }
  76             } catch (Error e) { // OOM error
  77                 break;
  78             }
  79         }






  80         if (Metrics.systemMetrics().getMemoryFailCount() <= count) {
  81             throw new RuntimeException("Memory fail count : new : ["
  82                     + Metrics.systemMetrics().getMemoryFailCount() + "]"
  83                     + ", old : [" + count + "]");
  84         }
  85         System.out.println("TEST PASSED!!!");
  86     }
  87 
  88     private static void testMemorySoftLimit(String softLimit) {
  89 
  90         long memorySoftLimit = Metrics.systemMetrics().getMemorySoftLimit();
  91         long newmemorySoftLimit = getMemoryValue(softLimit);
  92 
  93         if (newmemorySoftLimit != memorySoftLimit) {
  94             throw new RuntimeException("Memory softlimit not equal, Actual : ["
  95                     + newmemorySoftLimit + "]" + ", Expected : ["
  96                     + memorySoftLimit + "]");
  97         }
  98         System.out.println("TEST PASSED!!!");
  99     }




  48                 break;
  49         }
  50     }
  51 
  52     private static void testMemoryLimit(String value) {
  53         long limit = getMemoryValue(value);
  54 
  55         if (limit != Metrics.systemMetrics().getMemoryLimit()) {
  56             throw new RuntimeException("Memory limit not equal, expected : ["
  57                     + limit + "]" + ", got : ["
  58                     + Metrics.systemMetrics().getMemoryLimit() + "]");
  59         }
  60         System.out.println("TEST PASSED!!!");
  61     }
  62 
  63     private static void testMemoryFailCount() {
  64         long count = Metrics.systemMetrics().getMemoryFailCount();
  65 
  66         // Allocate 512M of data
  67         byte[][] bytes = new byte[64][];
  68         boolean atLeastOneAllocationWorked = false;
  69         for (int i = 0; i < 64; i++) {
  70             try {
  71                 bytes[i] = new byte[8 * 1024 * 1024];
  72                 atLeastOneAllocationWorked = true;
  73                 // Break out as soon as we see an increase in failcount
  74                 // to avoid getting killed by the OOM killer.
  75                 if (Metrics.systemMetrics().getMemoryFailCount() > count) {
  76                     break;
  77                 }
  78             } catch (Error e) { // OOM error
  79                 break;
  80             }
  81         }
  82         if (!atLeastOneAllocationWorked) {
  83             System.out.println("Allocation failed immediately. Ignoring test!");
  84             return;
  85         }
  86         // Be sure bytes allocations don't get optimized out
  87         System.out.println("DEBUG: Bytes allocation length 1: " + bytes[0].length);
  88         if (Metrics.systemMetrics().getMemoryFailCount() <= count) {
  89             throw new RuntimeException("Memory fail count : new : ["
  90                     + Metrics.systemMetrics().getMemoryFailCount() + "]"
  91                     + ", old : [" + count + "]");
  92         }
  93         System.out.println("TEST PASSED!!!");
  94     }
  95 
  96     private static void testMemorySoftLimit(String softLimit) {
  97 
  98         long memorySoftLimit = Metrics.systemMetrics().getMemorySoftLimit();
  99         long newmemorySoftLimit = getMemoryValue(softLimit);
 100 
 101         if (newmemorySoftLimit != memorySoftLimit) {
 102             throw new RuntimeException("Memory softlimit not equal, Actual : ["
 103                     + newmemorySoftLimit + "]" + ", Expected : ["
 104                     + memorySoftLimit + "]");
 105         }
 106         System.out.println("TEST PASSED!!!");
 107     }


< prev index next >