I have a use case where I am continuously testing a workflow. I have an entry made to a mysql database to store a student record, retrieve it, update it with some details, and then finally delete it.
In order to test these workflows, I have each of these steps as separate methods. Now, in order to test it continuously, I am possibly thinking of having the entire workflow execute in a multi threaded model.
The difficulty I am having is that how I have the other operations (get, update and delete) wait till the create operation is complete. I was looking up Thread.join() and notify methods but I was unsure if that's the most elegant way to do so.
Here is a sample (pretty naive version) of my code I have so far:
public class Test {
public static void main(String[] args) {
while (true) {
String studentId = createStudent();
Thread.sleep(1000);
Runnable calls[] = new Runnable {
() -> getStudent(studentId),
() -> updateStudent(studentId),
() -> delete(studentId)
};
for (Runnable call: calls) {
call.run();
}
}
}
private String createStudent() {
...
...
...
return studentId;
}
private void getStudent(String studentId)
...
...
...
}
private void updateStudent(String studentId)
...
...
...
}
private void deleteStudent(String studentId)
...
...
...
}
}
I am pretty sure my way of introducing sleep is a pretty naive implementation and is definitely not recommended as well. If I had to use notify or join, is there a best practice suggestion I can look up?