test/jdk/javax/management/remote/rest/RestAdapterPerfTest.java
branchjmx-rest-api
changeset 56002 60ab3b595a8e
child 56003 4f7f76f6be2f
equal deleted inserted replaced
56001:95c0323f0c1a 56002:60ab3b595a8e
       
     1 import org.testng.annotations.Test;
       
     2 
       
     3 import java.util.ArrayList;
       
     4 import java.util.List;
       
     5 import java.util.Random;
       
     6 import java.util.concurrent.Executors;
       
     7 import java.util.concurrent.ThreadFactory;
       
     8 import java.util.concurrent.ThreadPoolExecutor;
       
     9 import java.util.concurrent.TimeUnit;
       
    10 import java.util.concurrent.atomic.AtomicInteger;
       
    11 
       
    12 @Test
       
    13 public class RestAdapterPerfTest {
       
    14 
       
    15     private static Random random = new Random(System.currentTimeMillis());
       
    16     private static AtomicInteger count = new AtomicInteger(1);
       
    17 
       
    18     public static void main(String[] args) throws Exception {
       
    19         RestAdapterTest test = new RestAdapterTest();
       
    20         List<Runnable> tasks = new ArrayList<>();
       
    21 
       
    22         tasks.add(test::testAllMBeanServers);
       
    23         tasks.add(test::testAllMBeanInfo);
       
    24         tasks.add(test::testAllMBeans);
       
    25         tasks.add(test::testMBeanFiltering);
       
    26         tasks.add(test::testMBeanGetAttributes);
       
    27         tasks.add(test::testMBeanSetAttributes);
       
    28         tasks.add(test::testMbeanNoArgOperations);
       
    29         tasks.add(test::testAllMBeansBulkRequest);
       
    30         tasks.add(test::testThreadMXBeanBulkRequest);
       
    31         tasks.add(test::testThreadMXBeanThreadInfo);
       
    32 
       
    33         ThreadPoolExecutor es = (ThreadPoolExecutor) Executors.newFixedThreadPool(20);
       
    34         es.setThreadFactory((Runnable R) -> new Thread(R, "perf-" + count.getAndIncrement()));
       
    35         long current = System.currentTimeMillis();
       
    36         test.setupServers();
       
    37         for (int i = 0; i < 200; i++) {
       
    38             Runnable task = tasks.get(random.nextInt(tasks.size()));
       
    39             es.execute(task);
       
    40         }
       
    41 
       
    42         System.out.println("Submitted 200 tasks");
       
    43         es.shutdown();
       
    44         es.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
       
    45         float v = (float) (System.currentTimeMillis() - current) / (float) 1000;
       
    46         System.out.println("Total time = " + v + "s");
       
    47         test.tearDownServers();
       
    48     }
       
    49 }