Skip to content

Commit 2cd501a

Browse files
committed
wip
1 parent 31a9408 commit 2cd501a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

commercetools/commercetools-sdk-java-api/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ tasks.register('runMainMethodMemoryLeakTest', JavaExec) {
3636
maxHeapSize("128m")
3737
}
3838

39+
tasks.register('runLongRunningTimeoutTest', JavaExec) {
40+
group = "Execution"
41+
description = "Run the main method thread leak test class"
42+
classpath = sourceSets.test.runtimeClasspath
43+
mainClass = "com.commercetools.LongRunningTimeoutTest"
44+
maxHeapSize("128m")
45+
}
3946

4047
apply plugin: com.commercetools.sdk.plugins.MigrationInfoPlugin
4148

commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LongRunningTimeoutTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
5454
final int elements = 100000;
5555
BlockingQueue<Pair<String, Integer>> blockingQueue = new ArrayBlockingQueue<>(50000);
5656

57-
final int concurrency = 20;
57+
final int concurrency = 100;
5858
ExecutorService threadPool = Executors.newFixedThreadPool(concurrency);
5959

6060
Random r = new Random();
@@ -83,26 +83,32 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
8383
// .protocols(Lists.list(Protocol.HTTP_1_1))
8484
.build();
8585
for (int i = 0; i < concurrency; i++) {
86+
int finalI = i;
8687
threadPool.execute(() -> {
8788
try {
8889
while (!threadPool.isTerminated()) {
8990
Pair<String, Integer> p = blockingQueue.poll(1, TimeUnit.SECONDS);
9091
if (p == null) {
9192
break;
9293
}
93-
// final Request request = new Request.Builder()
94-
// .addHeader("Authorization", "Bearer " + token.getAccessToken())
95-
// .addHeader("Content-Type", "application/json")
96-
// .url(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl() + "/" + getProjectKey() + "/messages/"
97-
// + p.getLeft())
98-
// .build();
99-
// try (Response response = client2.newCall(request).execute()) {
100-
// String b = response.body().string();
101-
// response.close();
102-
// System.out.println(b);
103-
// System.out.println(p.getRight());
104-
// System.out.println(client2.dispatcher().runningCallsCount());
105-
// }
94+
final Request request = new Request.Builder()
95+
// .addHeader("Authorization", "Bearer " + token.getAccessToken())
96+
// .addHeader("Content-Type", "application/json")
97+
.url("https://jsonapi.org/")
98+
.get()
99+
.build();
100+
try (Response response = client2.newCall(request).execute()) {
101+
String b = response.body().string();
102+
response.body().close();
103+
response.close();
104+
System.out.println("i: " + p.getRight() + "\ts: " + response.code() + "\tr: "
105+
+ client2.dispatcher().runningCallsCount() + "\tc: "
106+
+ client2.connectionPool().idleConnectionCount() + "; "
107+
+ client2.connectionPool().connectionCount());
108+
}
109+
catch (IOException e) {
110+
throw new RuntimeException(e);
111+
}
106112

107113
final ApiHttpResponse<byte[]> messageApiHttpResponse = client.withProjectKey(getProjectKey())
108114
.messages()

0 commit comments

Comments
 (0)