Merge
authorjbachorik
Tue, 24 Mar 2015 16:21:28 +0000
changeset 30112 ea1dbf32c865
parent 30110 20d4dc1409a6 (current diff)
parent 30111 fbba8c368ce0 (diff)
child 30113 3f6beb804b02
child 30115 313d2bd3f281
Merge
--- a/hotspot/test/serviceability/attach/AttachWithStalePidFile.java	Mon Mar 23 13:53:44 2015 +0100
+++ b/hotspot/test/serviceability/attach/AttachWithStalePidFile.java	Tue Mar 24 16:21:28 2015 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
  * @bug 7162400
  * @key regression
  * @summary Regression test for attach issue where stale pid files in /tmp lead to connection issues
- * @ignore 8024055
  * @library /testlibrary
  * @build com.oracle.java.testlibrary.* AttachWithStalePidFileTarget
  * @run main AttachWithStalePidFile
@@ -79,9 +78,7 @@
       // wait for vm.paused file to be created and delete it once we find it.
       waitForAndResumeVM(pid);
 
-      // unfortunately there's no reliable way to know the VM is ready to receive the
-      // attach request so we have to do an arbitrary sleep.
-      Thread.sleep(5000);
+      waitForTargetReady(target);
 
       HotSpotVirtualMachine vm = (HotSpotVirtualMachine)VirtualMachine.attach(((Integer)pid).toString());
       BufferedReader remoteDataReader = new BufferedReader(new InputStreamReader(vm.remoteDataDump()));
@@ -101,6 +98,16 @@
     }
   }
 
+  private static void waitForTargetReady(Process target) throws IOException {
+    BufferedReader br = new BufferedReader(new InputStreamReader(target.getInputStream()));
+    String line = br.readLine();
+    // wait for the ready message having been printed or EOF (line == null)
+    while (line != null && !line.equals(AttachWithStalePidFileTarget.READY_MSG)) {
+        line = br.readLine();
+    }
+    // target VM ready
+  }
+
   private static Path createJavaPidFile(int pid) throws Exception {
     Path pidFile = Paths.get("/tmp/.java_pid" + pid);
     if(Files.exists(pidFile)) {
@@ -108,8 +115,10 @@
         Files.delete(pidFile);
       }
       catch(FileSystemException e) {
-        if(e.getReason().equals("Operation not permitted")) {
+        if(e.getReason().matches("Operation not permitted|Not owner")) {
           System.out.println("Unable to remove exisiting stale PID file" + pidFile);
+          System.out.println("===================================================");
+          e.printStackTrace(System.out);
           return null;
         }
         throw e;
--- a/hotspot/test/serviceability/attach/AttachWithStalePidFileTarget.java	Mon Mar 23 13:53:44 2015 +0100
+++ b/hotspot/test/serviceability/attach/AttachWithStalePidFileTarget.java	Tue Mar 24 16:21:28 2015 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,10 @@
  * questions.
  */
 public class AttachWithStalePidFileTarget {
+  static final String READY_MSG = "*ready*";
   public static void main(String... args) throws Exception {
-    Thread.sleep(2*60*1000);
+      System.out.println(READY_MSG);
+      System.out.flush();
+      System.in.read();
   }
 }