Skip to content

Commit b9d7dd5

Browse files
committed
Bug#28550140 FIX RECONNECTTEST IN CLUSTERJ
This bug report, from 2018, notes that on rare occasions the test ReconnectTest will fail and report "Retry count too low: 0"; the problem report says "the retry count is too low due to a race condition in the threads run by the test." In my analysis, I found that a test thread obtains a lock on the retryCount when incrementing it (line 339; line 358; line 371) but that the main thread neglects to acquire this lock when reading the retryCount at line 197. Replace retryCount with an AtomicInteger, and reenable the test. This patch is for 7.5 and up. Change-Id: I62563be7d94f7431f90855a1cf717a24991124bc
1 parent fad30ab commit b9d7dd5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/ReconnectTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
1717

1818
package testsuite.clusterj;
1919

20+
import java.util.concurrent.atomic.AtomicInteger;
2021
import java.util.ArrayList;
2122
import java.util.Collection;
2223
import java.util.Comparator;
@@ -35,7 +36,6 @@
3536
import testsuite.clusterj.model.Order;
3637
import testsuite.clusterj.model.OrderLine;
3738

38-
@org.junit.Ignore("Bug#28550140 : disable test until diagnosis of failure")
3939
public class ReconnectTest extends AbstractClusterJModelTest {
4040

4141
@Override
@@ -194,10 +194,10 @@ public void test() {
194194
}
195195
}
196196
// summarize for the record
197-
if (retryCount < 5) error ("Retry count too low: " + retryCount);
197+
if (retryCount.get() < 5) error ("Retry count too low: " + retryCount.get());
198198
if (getDebug()) {
199-
System.out.println("Retry count: " + retryCount);
200-
System.out.println("Number of threads: " + numberOfThreads +
199+
System.out.println("Retry count: " + retryCount.get());
200+
System.out.println("Number of threads: " + numberOfThreads +
201201
"; number of new customers per thread: " + numberOfNewCustomersPerThread +
202202
"; number of orders per new customer: " + numberOfNewOrdersPerNewCustomer);
203203
System.out.println("Created " + nextCustomerId + " customers; " +
@@ -249,12 +249,8 @@ public void test() {
249249
failOnError();
250250
}
251251

252-
private int retryCount = 0;
253-
private void incrementRetryCount() {
254-
synchronized(this) {
255-
++retryCount;
256-
}
257-
}
252+
private AtomicInteger retryCount = new AtomicInteger();
253+
258254
class Misbehaving implements Runnable {
259255
@Override
260256
public void run() {
@@ -336,7 +332,7 @@ public void run() {
336332
} catch (ClusterJUserException cjue) {
337333
if (getDebug()) { System.out.println("StuffToDo: create customer caught " + cjue.getMessage()); }
338334
if (cjue.getMessage().contains("SessionFactory is not open")) {
339-
incrementRetryCount();
335+
retryCount.getAndIncrement();
340336
sleep(300);
341337
}
342338
}
@@ -355,7 +351,7 @@ public void run() {
355351
} catch (ClusterJUserException cjue) {
356352
if (getDebug()) { System.out.println("StuffToDo: update orders caught " + cjue.getMessage()); }
357353
if (cjue.getMessage().contains("SessionFactory is not open")) {
358-
incrementRetryCount();
354+
retryCount.getAndIncrement();
359355
sleep(300);
360356
}
361357
}
@@ -372,7 +368,7 @@ public void run() {
372368
} catch (ClusterJUserException cjue) {
373369
if (getDebug()) { System.out.println("StuffToDo: delete order caught " + cjue.getMessage()); }
374370
if (cjue.getMessage().contains("SessionFactory is not open")) {
375-
incrementRetryCount();
371+
retryCount.getAndIncrement();
376372
sleep(300);
377373
}
378374
}

0 commit comments

Comments
 (0)