Test: add diagnostics to get some details next time this test fails

This commit is contained in:
mikemccand 2014-07-14 13:48:56 -04:00
parent f68a06ff99
commit f392a99bd9
1 changed files with 25 additions and 6 deletions

View File

@ -455,10 +455,12 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
public String id; public String id;
public long version; public long version;
public boolean delete; public boolean delete;
public int threadID = -1;
public long indexTime;
@Override @Override
public String toString() { public String toString() {
return "id=" + id + " version=" + version + " delete?=" + delete; return "id=" + id + " version=" + version + " delete?=" + delete + " threadID=" + threadID + " indexTime=" + indexTime;
} }
} }
@ -556,7 +558,9 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
final AtomicInteger upto = new AtomicInteger(); final AtomicInteger upto = new AtomicInteger();
final CountDownLatch startingGun = new CountDownLatch(1); final CountDownLatch startingGun = new CountDownLatch(1);
Thread[] threads = new Thread[TestUtil.nextInt(random, 1, isNightly() ? 20 : 5)]; Thread[] threads = new Thread[TestUtil.nextInt(random, 1, isNightly() ? 20 : 5)];
final long startTime = System.nanoTime();
for(int i=0;i<threads.length;i++) { for(int i=0;i<threads.length;i++) {
final int threadID = i;
threads[i] = new Thread() { threads[i] = new Thread() {
@Override @Override
public void run() { public void run() {
@ -566,7 +570,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
startingGun.await(); startingGun.await();
while (true) { while (true) {
// TODO: sometimes us bulk: // TODO: sometimes use bulk:
int index = upto.getAndIncrement(); int index = upto.getAndIncrement();
if (index >= idVersions.length) { if (index >= idVersions.length) {
@ -575,10 +579,13 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
if (VERBOSE && index % 100 == 0) { if (VERBOSE && index % 100 == 0) {
System.out.println(Thread.currentThread().getName() + ": index=" + index); System.out.println(Thread.currentThread().getName() + ": index=" + index);
} }
IDAndVersion idVersion = idVersions[index];
String id = idVersions[index].id; String id = idVersion.id;
long version = idVersions[index].version; idVersion.threadID = threadID;
if (idVersions[index].delete) { idVersion.indexTime = System.nanoTime()-startTime;
long version = idVersion.version;
if (idVersion.delete) {
try { try {
client().prepareDelete("test", "type", id) client().prepareDelete("test", "type", id)
.setVersion(version) .setVersion(version)
@ -621,14 +628,18 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
} }
if (threadRandom.nextInt(100) == 7) { if (threadRandom.nextInt(100) == 7) {
System.out.println(threadID + ": TEST: now refresh at " + (System.nanoTime()-startTime));
refresh(); refresh();
System.out.println(threadID + ": TEST: refresh done at " + (System.nanoTime()-startTime));
} }
if (threadRandom.nextInt(100) == 7) { if (threadRandom.nextInt(100) == 7) {
System.out.println(threadID + ": TEST: now flush at " + (System.nanoTime()-startTime));
try { try {
flush(); flush();
} catch (FlushNotAllowedEngineException fnaee) { } catch (FlushNotAllowedEngineException fnaee) {
// OK // OK
} }
System.out.println(threadID + ": TEST: flush done at " + (System.nanoTime()-startTime));
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -653,7 +664,15 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
} else { } else {
expected = -1; expected = -1;
} }
assertThat("id=" + id + " idVersion=" + idVersion, client().prepareGet("test", "type", id).execute().actionGet().getVersion(), equalTo(expected)); try {
assertThat("id=" + id + " idVersion=" + idVersion, client().prepareGet("test", "type", id).execute().actionGet().getVersion(), equalTo(expected));
} catch (AssertionError ae) {
System.out.println("FAILED:");
for(int i=0;i<idVersions.length;i++) {
System.out.println("i=" + i + " " + idVersions[i]);
}
throw ae;
}
} }
} }