madrob commented on a change in pull request #1548:
URL: https://github.com/apache/lucene-solr/pull/1548#discussion_r433292874
##########
File path: solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
##########
@@ -79,40 +78,57 @@ private void testFillWorkQueue() throws Exception {
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, String.valueOf(i),
- "sleep", (i == 0 ? "1000" : "1") //first task waits for 1 second,
and thus blocking
- // all other tasks. Subsequent tasks only wait for 1ms
+ // third task waits for a long time, and thus blocks the queue for
all other tasks for A_COLL.
+ // Subsequent tasks as well as the first two only wait for 1ms
+ "sleep", (i == 2 ? "10000" : "1")
)));
log.info("MOCK task added {}", i);
+ }
+ // Wait until we see the first two A_COLL tasks getting processed
+ boolean acoll0done = false, acoll1done = false;
+ for (int i = 0; i < 500; i++) {
+ if (!acoll0done) {
+ acoll0done = null != getStatusResponse("0",
client).getResponse().get("MOCK_FINISHED");
+ }
+ if (!acoll1done) {
Review comment:
Assuming the queue works as advertised, can we skip checking a0 and only
check a1?
##########
File path: solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
##########
@@ -79,40 +78,57 @@ private void testFillWorkQueue() throws Exception {
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, String.valueOf(i),
- "sleep", (i == 0 ? "1000" : "1") //first task waits for 1 second,
and thus blocking
- // all other tasks. Subsequent tasks only wait for 1ms
+ // third task waits for a long time, and thus blocks the queue for
all other tasks for A_COLL.
+ // Subsequent tasks as well as the first two only wait for 1ms
+ "sleep", (i == 2 ? "10000" : "1")
)));
log.info("MOCK task added {}", i);
+ }
+ // Wait until we see the first two A_COLL tasks getting processed
+ boolean acoll0done = false, acoll1done = false;
Review comment:
I found this section a little bit hard to read, would prefer something
more verbose but potentially easier to understand at a glance.
##########
File path: solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
##########
@@ -79,40 +78,57 @@ private void testFillWorkQueue() throws Exception {
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, String.valueOf(i),
- "sleep", (i == 0 ? "1000" : "1") //first task waits for 1 second,
and thus blocking
- // all other tasks. Subsequent tasks only wait for 1ms
+ // third task waits for a long time, and thus blocks the queue for
all other tasks for A_COLL.
+ // Subsequent tasks as well as the first two only wait for 1ms
+ "sleep", (i == 2 ? "10000" : "1")
)));
log.info("MOCK task added {}", i);
+ }
+ // Wait until we see the first two A_COLL tasks getting processed
+ boolean acoll0done = false, acoll1done = false;
+ for (int i = 0; i < 500; i++) {
+ if (!acoll0done) {
+ acoll0done = null != getStatusResponse("0",
client).getResponse().get("MOCK_FINISHED");
Review comment:
I think one way to make this cleaner is to extract
`getStatusResponse().getResponse.get("MOCK_FINISHED")` out into a separate
method.
##########
File path: solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
##########
@@ -79,40 +78,57 @@ private void testFillWorkQueue() throws Exception {
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, String.valueOf(i),
- "sleep", (i == 0 ? "1000" : "1") //first task waits for 1 second,
and thus blocking
- // all other tasks. Subsequent tasks only wait for 1ms
+ // third task waits for a long time, and thus blocks the queue for
all other tasks for A_COLL.
+ // Subsequent tasks as well as the first two only wait for 1ms
+ "sleep", (i == 2 ? "10000" : "1")
)));
log.info("MOCK task added {}", i);
+ }
+ // Wait until we see the first two A_COLL tasks getting processed
+ boolean acoll0done = false, acoll1done = false;
+ for (int i = 0; i < 500; i++) {
+ if (!acoll0done) {
+ acoll0done = null != getStatusResponse("0",
client).getResponse().get("MOCK_FINISHED");
+ }
+ if (!acoll1done) {
+ acoll1done = null != getStatusResponse("1",
client).getResponse().get("MOCK_FINISHED");
+ }
+ if (acoll0done && acoll1done) break;
+ Thread.sleep(100);
}
- Thread.sleep(100);//wait and post the next message
+ assertTrue("Queue did not process first two tasks on A_COLL, can't run
test", acoll0done && acoll1done);
+
+ // Make sure the long running task did not finish, otherwise no way the
B_COLL task can be tested to run in parallel with it
+ assertNull("Long running task finished too early, can't test",
getStatusResponse("2", client).getResponse().get("MOCK_FINISHED"));
- //this is not going to be blocked because it operates on another
collection
+ // Enqueue a task on another collection not competing with the lock on
A_COLL and see that it can be executed right away
distributedQueue.offer(Utils.toJSON(Utils.makeMap(
"collection", "B_COLL",
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, "200",
"sleep", "1"
)));
-
- Long acoll = null, bcoll = null;
+ // We now check that either the B_COLL task has completed before the
third (long running) task on A_COLL,
+ // Or if both have completed (if this check got significantly delayed
for some reason), we verify B_COLL was first.
+ Long acoll3 = null, bcoll = null;
for (int i = 0; i < 500; i++) {
- if (bcoll == null) {
- CollectionAdminResponse statusResponse = getStatusResponse("200",
client);
- bcoll = (Long) statusResponse.getResponse().get("MOCK_FINISHED");
- }
- if (acoll == null) {
- CollectionAdminResponse statusResponse = getStatusResponse("2",
client);
- acoll = (Long) statusResponse.getResponse().get("MOCK_FINISHED");
+ if (acoll3 == null) {
Review comment:
Do we really care about checking for a3 here? Why not check once after
the loop?
##########
File path: solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
##########
@@ -79,40 +78,57 @@ private void testFillWorkQueue() throws Exception {
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, String.valueOf(i),
- "sleep", (i == 0 ? "1000" : "1") //first task waits for 1 second,
and thus blocking
- // all other tasks. Subsequent tasks only wait for 1ms
+ // third task waits for a long time, and thus blocks the queue for
all other tasks for A_COLL.
+ // Subsequent tasks as well as the first two only wait for 1ms
+ "sleep", (i == 2 ? "10000" : "1")
)));
log.info("MOCK task added {}", i);
+ }
+ // Wait until we see the first two A_COLL tasks getting processed
+ boolean acoll0done = false, acoll1done = false;
+ for (int i = 0; i < 500; i++) {
+ if (!acoll0done) {
+ acoll0done = null != getStatusResponse("0",
client).getResponse().get("MOCK_FINISHED");
+ }
+ if (!acoll1done) {
+ acoll1done = null != getStatusResponse("1",
client).getResponse().get("MOCK_FINISHED");
+ }
+ if (acoll0done && acoll1done) break;
+ Thread.sleep(100);
}
- Thread.sleep(100);//wait and post the next message
+ assertTrue("Queue did not process first two tasks on A_COLL, can't run
test", acoll0done && acoll1done);
+
+ // Make sure the long running task did not finish, otherwise no way the
B_COLL task can be tested to run in parallel with it
+ assertNull("Long running task finished too early, can't test",
getStatusResponse("2", client).getResponse().get("MOCK_FINISHED"));
- //this is not going to be blocked because it operates on another
collection
+ // Enqueue a task on another collection not competing with the lock on
A_COLL and see that it can be executed right away
distributedQueue.offer(Utils.toJSON(Utils.makeMap(
"collection", "B_COLL",
QUEUE_OPERATION, MOCK_COLL_TASK.toLower(),
ASYNC, "200",
"sleep", "1"
)));
-
- Long acoll = null, bcoll = null;
+ // We now check that either the B_COLL task has completed before the
third (long running) task on A_COLL,
+ // Or if both have completed (if this check got significantly delayed
for some reason), we verify B_COLL was first.
+ Long acoll3 = null, bcoll = null;
Review comment:
Inconsistent naming: acoll0, acoll1, then acoll3.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]