aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/main
diff options
context:
space:
mode:
authorThomas Nelson <nelson24@att.com>2019-07-25 20:17:25 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-25 20:17:25 +0000
commita98c068aa9a97b73aa1423f432674485a05bdb60 (patch)
tree7816cc2e2c9fb303fc7961badca4eb3928071610 /mdbc-server/src/main
parent32dbfd3759fc2aa20e8f03637b8fcc281c3730e2 (diff)
parent394d23b48b5baffe02230e47ff3479c913cf9b55 (diff)
Merge "End test with a select all"
Diffstat (limited to 'mdbc-server/src/main')
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestMultiClient.java58
1 files changed, 55 insertions, 3 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestMultiClient.java b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestMultiClient.java
index 2923cd7..02b7c7c 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestMultiClient.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestMultiClient.java
@@ -49,6 +49,8 @@ public class MdbcTestMultiClient implements Runnable {
private int selectInsteadOfUpdatePct = 25;
private int rollbackChancePct = 15;
private int maxTables = 0;
+ public static boolean[] threadsDone;
+
private boolean sequentialIds = false;
private static Integer currentId = -1;
@@ -62,6 +64,7 @@ public class MdbcTestMultiClient implements Runnable {
private static final List<String> defaultTableNames = Arrays.asList(new String[] {"persons", "persons2"});
private boolean explainConnection = true;
+ private boolean endInSelect = true;
public static class Employee {
public final int empid;
@@ -716,7 +719,44 @@ public class MdbcTestMultiClient implements Runnable {
doLog("");
}
+ threadsDone[threadId] = true;
+ if (endInSelect) {
+ doLog("Ending in select to ensure all db's are in sync");
+ while (!allThreadsDone()) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ continue;
+ }
+ }
+ doLog("All threads are done. Ending in select");
+ if (connection==null) {
+ try {
+ doLog("Opening new connection");
+ connection = DriverManager.getConnection(connectionString);
+ connection.setAutoCommit(false);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+ for (String tableName : tableNames) {
+ try {
+ Statement querySt = connection.createStatement();
+ ResultSet rs = executeQueryTimed("select * from " + tableName, querySt, false);
+ while (rs.next()) {
+ // doLog("PersonId = " + rs.getInt("personId") + ", lastname = " + rs.getString("lastname") + ", firstname = " + rs.getString("firstname"));
+ Employee emp = new Employee(rs.getInt("personId"), rs.getString("lastname"), rs.getString("firstname"), rs.getString("address"), rs.getString("city"));
+ doLog("Found: " + emp);
+ }
+ querySt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
if (connection!=null) {
try {
doLog("Closing connection at end");
@@ -729,27 +769,39 @@ public class MdbcTestMultiClient implements Runnable {
doLog("All done.");
}
- private void doLog(String string) {
+ private boolean allThreadsDone() {
+ for (Boolean b: this.threadsDone) {
+ if (!b) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void doLog(String string) {
System.out.println(">> Thread " + threadId + " " + sdf.format(new java.util.Date()) + " >> " + string);
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws InterruptedException {
MdbcTestMultiClient mtc = new MdbcTestMultiClient(args);
mtc.runTests();
}
- private void runTests() {
+ private void runTests() throws InterruptedException {
if (randomSeed==null) {
randomSeed = new Random().nextLong();
}
doLog("Using random seed = " + randomSeed);
Random seedRandom = new Random(randomSeed);
+ this.threadsDone = new boolean[connectionStrings.size()];
+
for (int i=0; i<connectionStrings.size(); i++) {
MdbcTestMultiClient mt = new MdbcTestMultiClient(this, i);
mt.setRandomSeed(seedRandom.nextLong());
Thread t = new Thread(mt);
t.start();
}
+
}
}