Skip to content

Commit f578808

Browse files
authored
Merge pull request #50530 from jmartisk/graphql-virtual-thread-test-native
Fix the GraphQL RunOnVirtualThreadIT in native
2 parents c6104f8 + b3fb6bd commit f578808

File tree

4 files changed

+130
-123
lines changed

4 files changed

+130
-123
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.quarkus.virtual.graphql;
2+
3+
import org.eclipse.microprofile.graphql.GraphQLApi;
4+
import org.eclipse.microprofile.graphql.Mutation;
5+
import org.eclipse.microprofile.graphql.Query;
6+
7+
import io.smallrye.common.annotation.RunOnVirtualThread;
8+
9+
@GraphQLApi
10+
public class RunOnVirtualThreadObjectTestThreadResource {
11+
12+
// Return type Object with @RunOnVirtualThread
13+
@Query
14+
@RunOnVirtualThread
15+
public TestThread annotatedRunOnVirtualThreadObject() {
16+
sleep();
17+
return getTestThread();
18+
}
19+
20+
// Return type Object with @RunOnVirtualThread
21+
@Mutation
22+
@RunOnVirtualThread
23+
public TestThread annotatedRunOnVirtualThreadMutationObject(String test) {
24+
sleep();
25+
return getTestThread();
26+
}
27+
28+
@Query
29+
@RunOnVirtualThread
30+
public TestThread pinThread() {
31+
// Synchronize on an object to cause thread pinning
32+
Object lock = new Object();
33+
synchronized (lock) {
34+
sleep();
35+
}
36+
return getTestThread();
37+
}
38+
39+
private void sleep() {
40+
try {
41+
Thread.sleep(100);
42+
} catch (InterruptedException e) {
43+
Thread.currentThread().interrupt();
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
48+
private TestThread getTestThread() {
49+
Thread t = Thread.currentThread();
50+
long id = t.getId();
51+
String name = t.getName();
52+
int priority = t.getPriority();
53+
String state = t.getState().name();
54+
String group = t.getThreadGroup().getName();
55+
return new TestThread(id, name, priority, state, group);
56+
}
57+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.quarkus.virtual.graphql;
2+
3+
import io.vertx.core.Context;
4+
import io.vertx.core.Vertx;
5+
6+
/**
7+
* Holds info about a thread
8+
*/
9+
public class TestThread {
10+
11+
private long id;
12+
private String name;
13+
private int priority;
14+
private String state;
15+
private String group;
16+
17+
public TestThread() {
18+
super();
19+
}
20+
21+
public TestThread(long id, String name, int priority, String state, String group) {
22+
this.id = id;
23+
this.name = name;
24+
this.priority = priority;
25+
this.state = state;
26+
this.group = group;
27+
}
28+
29+
public long getId() {
30+
return id;
31+
}
32+
33+
public void setId(long id) {
34+
this.id = id;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public void setName(String name) {
42+
this.name = name;
43+
}
44+
45+
public int getPriority() {
46+
return priority;
47+
}
48+
49+
public void setPriority(int priority) {
50+
this.priority = priority;
51+
}
52+
53+
public String getState() {
54+
return state;
55+
}
56+
57+
public void setState(String state) {
58+
this.state = state;
59+
}
60+
61+
public String getGroup() {
62+
return group;
63+
}
64+
65+
public void setGroup(String group) {
66+
this.group = group;
67+
}
68+
69+
public String getVertxContextClassName() {
70+
Context vc = Vertx.currentContext();
71+
return vc.getClass().getName();
72+
}
73+
}

integration-tests/virtual-threads/graphql-virtual-threads/src/test/java/io/quarkus/virtual/graphql/AbstractGraphQLTest.java

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import io.restassured.RestAssured;
1818
import io.restassured.parsing.Parser;
19-
import io.vertx.core.Context;
20-
import io.vertx.core.Vertx;
2119

2220
/**
2321
* Some shared methods
@@ -112,72 +110,4 @@ protected static String getPropertyAsString(Map<String, String> otherProperties)
112110
PROPERTIES.put("smallrye.graphql.events.enabled", "true");
113111
}
114112

115-
/**
116-
* Hold info about a thread
117-
*/
118-
public static class TestThread {
119-
120-
private long id;
121-
private String name;
122-
private int priority;
123-
private String state;
124-
private String group;
125-
126-
public TestThread() {
127-
super();
128-
}
129-
130-
public TestThread(long id, String name, int priority, String state, String group) {
131-
this.id = id;
132-
this.name = name;
133-
this.priority = priority;
134-
this.state = state;
135-
this.group = group;
136-
}
137-
138-
public long getId() {
139-
return id;
140-
}
141-
142-
public void setId(long id) {
143-
this.id = id;
144-
}
145-
146-
public String getName() {
147-
return name;
148-
}
149-
150-
public void setName(String name) {
151-
this.name = name;
152-
}
153-
154-
public int getPriority() {
155-
return priority;
156-
}
157-
158-
public void setPriority(int priority) {
159-
this.priority = priority;
160-
}
161-
162-
public String getState() {
163-
return state;
164-
}
165-
166-
public void setState(String state) {
167-
this.state = state;
168-
}
169-
170-
public String getGroup() {
171-
return group;
172-
}
173-
174-
public void setGroup(String group) {
175-
this.group = group;
176-
}
177-
178-
public String getVertxContextClassName() {
179-
Context vc = Vertx.currentContext();
180-
return vc.getClass().getName();
181-
}
182-
}
183113
}

integration-tests/virtual-threads/graphql-virtual-threads/src/test/java/io/quarkus/virtual/graphql/RunOnVirtualThreadTest.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.quarkus.virtual.graphql;
22

3-
import org.eclipse.microprofile.graphql.GraphQLApi;
4-
import org.eclipse.microprofile.graphql.Mutation;
5-
import org.eclipse.microprofile.graphql.Query;
63
import org.hamcrest.Matchers;
74
import org.junit.jupiter.api.Disabled;
85
import org.junit.jupiter.api.Test;
@@ -11,7 +8,6 @@
118
import io.quarkus.test.junit5.virtual.ShouldNotPin;
129
import io.quarkus.test.junit5.virtual.VirtualThreadUnit;
1310
import io.restassured.RestAssured;
14-
import io.smallrye.common.annotation.RunOnVirtualThread;
1511

1612
@QuarkusTest
1713
@VirtualThreadUnit
@@ -103,53 +99,4 @@ public void testPiningThread() {
10399
Matchers.equalTo("io.vertx.core.impl.DuplicatedContext"));
104100
}
105101

106-
@GraphQLApi
107-
public static class RunOnVirtualThreadObjectTestThreadResource {
108-
109-
// Return type Object with @RunOnVirtualThread
110-
@Query
111-
@RunOnVirtualThread
112-
public TestThread annotatedRunOnVirtualThreadObject() {
113-
sleep();
114-
return getTestThread();
115-
}
116-
117-
// Return type Object with @RunOnVirtualThread
118-
@Mutation
119-
@RunOnVirtualThread
120-
public TestThread annotatedRunOnVirtualThreadMutationObject(String test) {
121-
sleep();
122-
return getTestThread();
123-
}
124-
125-
@Query
126-
@RunOnVirtualThread
127-
public TestThread pinThread() {
128-
// Synchronize on an object to cause thread pinning
129-
Object lock = new Object();
130-
synchronized (lock) {
131-
sleep();
132-
}
133-
return getTestThread();
134-
}
135-
136-
private void sleep() {
137-
try {
138-
Thread.sleep(100);
139-
} catch (InterruptedException e) {
140-
Thread.currentThread().interrupt();
141-
throw new RuntimeException(e);
142-
}
143-
}
144-
145-
private TestThread getTestThread() {
146-
Thread t = Thread.currentThread();
147-
long id = t.getId();
148-
String name = t.getName();
149-
int priority = t.getPriority();
150-
String state = t.getState().name();
151-
String group = t.getThreadGroup().getName();
152-
return new TestThread(id, name, priority, state, group);
153-
}
154-
}
155102
}

0 commit comments

Comments
 (0)