Core: Remove nasty hack in toString

This makes the output of EsThreadPoolExecutor#toString less pretty but
we no longer have funky hacky that rely on the specific format of the
toString produced by ThreadPoolExecutor which isn't part of its API and
could change with any JVM version and break the output.
This commit is contained in:
Nik Everett 2015-07-30 13:52:58 -04:00
parent ed7d84ca5f
commit 804f14c68e
2 changed files with 7 additions and 16 deletions

View File

@ -101,19 +101,6 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor {
@Override
public String toString() {
/*
* ThreadPoolExecutor has some nice information in its toString but we
* can't recreate it without nastier hacks than this.
*/
String tpeToString = super.toString();
int startOfInfoInTpeToString = tpeToString.indexOf('[');
String tpeInfo;
if (startOfInfoInTpeToString >= 0) {
tpeInfo = tpeToString.substring(startOfInfoInTpeToString + 1);
} else {
assert false: "Unsupported ThreadPoolExecutor toString";
tpeInfo = tpeToString;
}
StringBuilder b = new StringBuilder();
b.append(getClass().getSimpleName()).append('[');
b.append(name).append(", ");
@ -122,7 +109,11 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor {
SizeBlockingQueue queue = (SizeBlockingQueue) getQueue();
b.append("queue capacity = ").append(queue.capacity()).append(", ");
}
b.append("state = ").append(tpeInfo);
/*
* ThreadPoolExecutor has some nice information in its toString but we
* can't get at it easily without just getting the toString.
*/
b.append(super.toString()).append(']');
return b.toString();
}
}

View File

@ -274,7 +274,7 @@ public class EsExecutorsTests extends ESTestCase {
assertThat(message, containsString("of dummy runnable"));
assertThat(message, containsString("on EsThreadPoolExecutor[testRejectionMessage"));
assertThat(message, containsString("queue capacity = " + queue));
assertThat(message, containsString("state = Running"));
assertThat(message, containsString("[Running"));
assertThat(message, containsString("active threads = " + pool));
assertThat(message, containsString("queued tasks = " + queue));
assertThat(message, containsString("completed tasks = 0"));
@ -302,7 +302,7 @@ public class EsExecutorsTests extends ESTestCase {
assertThat(message, containsString("of dummy runnable"));
assertThat(message, containsString("on EsThreadPoolExecutor[" + getTestName()));
assertThat(message, containsString("queue capacity = " + queue));
assertThat(message, containsString("state = Terminated"));
assertThat(message, containsString("[Terminated"));
assertThat(message, containsString("active threads = 0"));
assertThat(message, containsString("queued tasks = 0"));
assertThat(message, containsString("completed tasks = " + actions));