|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -112,28 +112,51 @@ public static void main(String args[]) throws Exception {
|
112 | 112 | throw error;
|
113 | 113 | }
|
114 | 114 |
|
115 |
| - log("cleaning..."); |
116 |
| - // Attach to server debuggee and resume it so it can exit |
| 115 | + log("final attach..."); |
| 116 | + // Attach to server debuggee to ensure it's still available to attach and resume it so it can exit |
117 | 117 | AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
|
118 |
| - Map<String, Argument> conn_args = conn.defaultArguments(); |
119 |
| - Connector.IntegerArgument port_arg = |
120 |
| - (Connector.IntegerArgument)conn_args.get("port"); |
121 |
| - port_arg.setValue(port); |
122 |
| - VirtualMachine vm = conn.attach(conn_args); |
| 118 | + retryDelay = 20; |
| 119 | + for (int retry = 0; retry < 5; retry++) { |
| 120 | + if (error != null) { |
| 121 | + try { |
| 122 | + Thread.sleep(retryDelay); |
| 123 | + } catch (InterruptedException ex) { |
| 124 | + // ignore |
| 125 | + } |
| 126 | + retryDelay *= 2; |
| 127 | + error = null; |
| 128 | + } |
| 129 | + try { |
| 130 | + log("retry: " + retry); |
| 131 | + Map<String, Argument> conn_args = conn.defaultArguments(); |
| 132 | + Connector.IntegerArgument port_arg = |
| 133 | + (Connector.IntegerArgument)conn_args.get("port"); |
| 134 | + port_arg.setValue(port); |
| 135 | + VirtualMachine vm = conn.attach(conn_args); |
| 136 | + |
| 137 | + // The first event is always a VMStartEvent, and it is always in |
| 138 | + // an EventSet by itself. Wait for it. |
| 139 | + EventSet evtSet = vm.eventQueue().remove(); |
| 140 | + for (Event event : evtSet) { |
| 141 | + if (event instanceof VMStartEvent) { |
| 142 | + break; |
| 143 | + } |
| 144 | + throw new RuntimeException("Test failed - debuggee did not start properly"); |
| 145 | + } |
123 | 146 |
|
124 |
| - // The first event is always a VMStartEvent, and it is always in |
125 |
| - // an EventSet by itself. Wait for it. |
126 |
| - EventSet evtSet = vm.eventQueue().remove(); |
127 |
| - for (Event event : evtSet) { |
128 |
| - if (event instanceof VMStartEvent) { |
| 147 | + vm.eventRequestManager().deleteAllBreakpoints(); |
| 148 | + vm.resume(); |
129 | 149 | break;
|
| 150 | + } catch (ConnectException ex) { |
| 151 | + log("got exception: " + ex.toString()); |
| 152 | + error = ex; |
130 | 153 | }
|
131 |
| - throw new RuntimeException("Test failed - debuggee did not start properly"); |
| 154 | + } |
| 155 | + if (error != null) { |
| 156 | + throw error; |
132 | 157 | }
|
133 | 158 |
|
134 |
| - vm.eventRequestManager().deleteAllBreakpoints(); |
135 |
| - vm.resume(); |
136 |
| - |
| 159 | + // give the debuggee some time to exit before forcibly terminating it |
137 | 160 | debuggee.waitFor(10, TimeUnit.SECONDS);
|
138 | 161 | }
|
139 | 162 | }
|
|
0 commit comments