Commit c9c543e authored and Google Java Core Libraries
committed
1 parent 101dc3e commit c9c543e Copy full SHA for c9c543e
File tree 6 files changed +18
-20
lines changed
guava/src/com/google/common/util/concurrent
guava-tests/test/com/google/common/util/concurrent
guava/src/com/google/common/util/concurrent
guava-tests/test/com/google/common/util/concurrent
6 files changed +18
-20
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import static com .google .common .truth .Truth .assertThat ;
19
19
20
- import java . lang . reflect . Method ;
20
+ import com . google . common . util . concurrent . InterruptibleTask . Blocker ;
21
21
import java .nio .channels .spi .AbstractInterruptibleChannel ;
22
22
import java .util .concurrent .CountDownLatch ;
23
23
import java .util .concurrent .TimeUnit ;
24
- import java .util .concurrent .locks .AbstractOwnableSynchronizer ;
25
24
import java .util .concurrent .locks .LockSupport ;
26
25
import junit .framework .TestCase ;
27
26
@@ -152,12 +151,8 @@ public void run() {
152
151
// waiting for the slow interrupting thread to complete Thread.interrupt
153
152
awaitBlockedOnInstanceOf (runner , InterruptibleTask .Blocker .class );
154
153
155
- Object blocker = LockSupport .getBlocker (runner );
156
- assertThat (blocker ).isInstanceOf (AbstractOwnableSynchronizer .class );
157
- Method getExclusiveOwnerThread =
158
- AbstractOwnableSynchronizer .class .getDeclaredMethod ("getExclusiveOwnerThread" );
159
- getExclusiveOwnerThread .setAccessible (true );
160
- Thread owner = (Thread ) getExclusiveOwnerThread .invoke (blocker );
154
+ Blocker blocker = (Blocker ) LockSupport .getBlocker (runner );
155
+ Thread owner = blocker .getOwner ();
161
156
assertThat (owner ).isSameInstanceAs (interrupter );
162
157
163
158
slowChannel .exitClose .countDown (); // release the interrupter
Original file line number Diff line number Diff line change @@ -233,6 +233,11 @@ private void setOwner(Thread thread) {
233
233
super .setExclusiveOwnerThread (thread );
234
234
}
235
235
236
+ @ VisibleForTesting
237
+ Thread getOwner () {
238
+ return super .getExclusiveOwnerThread ();
239
+ }
240
+
236
241
@ Override
237
242
public String toString () {
238
243
return task .toString ();
Original file line number Diff line number Diff line change 425
425
</activation >
426
426
<properties >
427
427
<!--
428
- Some tests need reflective access to the internals of these packages. It is ony the
428
+ Some tests need reflective access to the internals of these packages. It is only the
429
429
tests themselves and not the code being tested that needs that access, though there's no
430
430
obvious way to ensure that.
431
431
435
435
<test .add.opens>
436
436
--add-opens java.base/java.lang=ALL-UNNAMED
437
437
--add-opens java.base/java.util=ALL-UNNAMED
438
- --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED
439
438
--add-opens java.base/sun.security.jca=ALL-UNNAMED
440
439
</test .add.opens>
441
440
</properties >
Original file line number Diff line number Diff line change 17
17
18
18
import static com .google .common .truth .Truth .assertThat ;
19
19
20
- import java . lang . reflect . Method ;
20
+ import com . google . common . util . concurrent . InterruptibleTask . Blocker ;
21
21
import java .nio .channels .spi .AbstractInterruptibleChannel ;
22
22
import java .util .concurrent .CountDownLatch ;
23
23
import java .util .concurrent .TimeUnit ;
24
- import java .util .concurrent .locks .AbstractOwnableSynchronizer ;
25
24
import java .util .concurrent .locks .LockSupport ;
26
25
import junit .framework .TestCase ;
27
26
@@ -152,12 +151,8 @@ public void run() {
152
151
// waiting for the slow interrupting thread to complete Thread.interrupt
153
152
awaitBlockedOnInstanceOf (runner , InterruptibleTask .Blocker .class );
154
153
155
- Object blocker = LockSupport .getBlocker (runner );
156
- assertThat (blocker ).isInstanceOf (AbstractOwnableSynchronizer .class );
157
- Method getExclusiveOwnerThread =
158
- AbstractOwnableSynchronizer .class .getDeclaredMethod ("getExclusiveOwnerThread" );
159
- getExclusiveOwnerThread .setAccessible (true );
160
- Thread owner = (Thread ) getExclusiveOwnerThread .invoke (blocker );
154
+ Blocker blocker = (Blocker ) LockSupport .getBlocker (runner );
155
+ Thread owner = blocker .getOwner ();
161
156
assertThat (owner ).isSameInstanceAs (interrupter );
162
157
163
158
slowChannel .exitClose .countDown (); // release the interrupter
Original file line number Diff line number Diff line change @@ -233,6 +233,11 @@ private void setOwner(Thread thread) {
233
233
super .setExclusiveOwnerThread (thread );
234
234
}
235
235
236
+ @ VisibleForTesting
237
+ Thread getOwner () {
238
+ return super .getExclusiveOwnerThread ();
239
+ }
240
+
236
241
@ Override
237
242
public String toString () {
238
243
return task .toString ();
Original file line number Diff line number Diff line change 432
432
</activation >
433
433
<properties >
434
434
<!--
435
- Some tests need reflective access to the internals of these packages. It is ony the
435
+ Some tests need reflective access to the internals of these packages. It is only the
436
436
tests themselves and not the code being tested that needs that access, though there's no
437
437
obvious way to ensure that.
438
438
442
442
<test .add.opens>
443
443
--add-opens java.base/java.lang=ALL-UNNAMED
444
444
--add-opens java.base/java.util=ALL-UNNAMED
445
- --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED
446
445
--add-opens java.base/sun.security.jca=ALL-UNNAMED
447
446
</test .add.opens>
448
447
</properties >
You can’t perform that action at this time.
0 commit comments