< prev index next > test/jdk/jdk/internal/misc/ThreadFlock/WithScopedValue.java
Print this page
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2024, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*/
@ParameterizedTest
@MethodSource("factories")
void testInheritsScopedValue(ThreadFactory factory) throws Exception {
ScopedValue<String> name = ScopedValue.newInstance();
- String value = ScopedValue.callWhere(name, "duke", () -> {
+ String value = ScopedValue.where(name, "duke").call(() -> {
var result = new AtomicReference<String>();
try (var flock = ThreadFlock.open(null)) {
Thread thread = factory.newThread(() -> {
// child
result.set(name.get());
ThreadFlock flock1;
ThreadFlock flock2;
}
var box = new Box();
try {
- ScopedValue.runWhere(name, "x1", () -> {
+ ScopedValue.where(name, "x1").run(() -> {
box.flock1 = ThreadFlock.open(null);
box.flock2 = ThreadFlock.open(null);
});
fail();
} catch (StructureViolationException expected) { }
*/
@Test
void testStructureViolation2() {
ScopedValue<String> name = ScopedValue.newInstance();
try (var flock1 = ThreadFlock.open("flock1")) {
- ScopedValue.runWhere(name, "x1", () -> {
+ ScopedValue.where(name, "x1").run(() -> {
try (var flock2 = ThreadFlock.open("flock2")) {
- ScopedValue.runWhere(name, "x2", () -> {
+ ScopedValue.where(name, "x2").run(() -> {
try (var flock3 = ThreadFlock.open("flock3")) {
- ScopedValue.runWhere(name, "x3", () -> {
+ ScopedValue.where(name, "x3").run(() -> {
var flock4 = ThreadFlock.open("flock4");
try {
flock1.close();
fail();
*/
@Test
void testStructureViolation3() {
ScopedValue<String> name = ScopedValue.newInstance();
try (var flock1 = ThreadFlock.open("flock1")) {
- ScopedValue.runWhere(name, "x1", () -> {
+ ScopedValue.where(name, "x1").run(() -> {
try (var flock2 = ThreadFlock.open("flock2")) {
- ScopedValue.runWhere(name, "x2", () -> {
+ ScopedValue.where(name, "x2").run(() -> {
try (var flock3 = ThreadFlock.open("flock3")) {
- ScopedValue.runWhere(name, "x3", () -> {
+ ScopedValue.where(name, "x3").run(() -> {
var flock4 = ThreadFlock.open("flock4");
try {
flock2.close();
fail();
*/
@Test
void testStructureViolation4() {
ScopedValue<String> name = ScopedValue.newInstance();
try (var flock1 = ThreadFlock.open("flock1")) {
- ScopedValue.runWhere(name, "x1", () -> {
+ ScopedValue.where(name, "x1").run(() -> {
try (var flock2 = ThreadFlock.open("flock2")) {
- ScopedValue.runWhere(name, "x2", () -> {
+ ScopedValue.where(name, "x2").run(() -> {
try (var flock3 = ThreadFlock.open("flock3")) {
- ScopedValue.runWhere(name, "x3", () -> {
+ ScopedValue.where(name, "x3").run(() -> {
var flock4 = ThreadFlock.open("flock4");
try {
flock3.close();
fail();
@ParameterizedTest
@MethodSource("factories")
void testStructureViolation5(ThreadFactory factory) throws Exception {
ScopedValue<String> name = ScopedValue.newInstance();
try (var flock = ThreadFlock.open(null)) {
- ScopedValue.runWhere(name, "duke", () -> {
+ ScopedValue.where(name, "duke").run(() -> {
Thread thread = factory.newThread(() -> { });
assertThrows(StructureViolationException.class, () -> flock.start(thread));
});
}
}
*/
@ParameterizedTest
@MethodSource("factories")
void testStructureViolation6(ThreadFactory factory) throws Exception {
ScopedValue<String> name = ScopedValue.newInstance();
- ScopedValue.runWhere(name, "duke", () -> {
+ ScopedValue.where(name, "duke").run(() -> {
try (var flock = ThreadFlock.open(null)) {
- ScopedValue.runWhere(name, "duchess", () -> {
+ ScopedValue.where(name, "duchess").run(() -> {
Thread thread = factory.newThread(() -> { });
assertThrows(StructureViolationException.class, () -> flock.start(thread));
});
}
});
< prev index next >