Test: more verbosity for this test on failure

This commit is contained in:
mikemccand 2014-07-26 04:42:12 -04:00
parent f682461b2f
commit e42b73c6d4
1 changed files with 71 additions and 12 deletions

View File

@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.TestUtil;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
@ -44,6 +45,7 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
@ -460,10 +462,62 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
public long indexFinishTime;
public boolean versionConflict;
public boolean alreadyExists;
public ActionResponse response;
@Override
public String toString() {
return "id=" + id + " version=" + version + " delete?=" + delete + " threadID=" + threadID + " indexStartTime=" + indexStartTime + " indexFinishTime=" + indexFinishTime + " versionConflict=" + versionConflict + " alreadyExists=" + alreadyExists;
StringBuilder sb = new StringBuilder();
sb.append("id=");
sb.append(id);
sb.append(" version=");
sb.append(version);
sb.append(" delete?=");
sb.append(delete);
sb.append(" threadID=");
sb.append(threadID);
sb.append(" indexStartTime=");
sb.append(indexStartTime);
sb.append(" indexFinishTime=");
sb.append(indexFinishTime);
sb.append(" versionConflict=");
sb.append(versionConflict);
sb.append(" alreadyExists?=");
sb.append(alreadyExists);
if (response != null) {
if (response instanceof DeleteResponse) {
DeleteResponse deleteResponse = (DeleteResponse) response;
sb.append(" response:");
sb.append(" index=");
sb.append(deleteResponse.getIndex());
sb.append(" id=");
sb.append(deleteResponse.getId());
sb.append(" type=");
sb.append(deleteResponse.getType());
sb.append(" version=");
sb.append(deleteResponse.getVersion());
sb.append(" found=");
sb.append(deleteResponse.isFound());
} else if (response instanceof IndexResponse) {
IndexResponse indexResponse = (IndexResponse) response;
sb.append(" index=");
sb.append(indexResponse.getIndex());
sb.append(" id=");
sb.append(indexResponse.getId());
sb.append(" type=");
sb.append(indexResponse.getType());
sb.append(" version=");
sb.append(indexResponse.getVersion());
sb.append(" created=");
sb.append(indexResponse.isCreated());
} else {
sb.append(" response: " + response);
}
} else {
sb.append(" response: null");
}
return sb.toString();
}
}
@ -482,7 +536,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
// We test deletes, but can't rely on wall-clock delete GC:
HashMap<String,Object> newSettings = new HashMap<>();
newSettings.put("index.gc_deletes", "1000000h");
client().admin().indices().prepareUpdateSettings("test").setSettings(newSettings).execute().actionGet();
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(newSettings).execute().actionGet());
Random random = getRandom();
@ -590,7 +644,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
long version = idVersion.version;
if (idVersion.delete) {
try {
client().prepareDelete("test", "type", id)
idVersion.response = client().prepareDelete("test", "type", id)
.setVersion(version)
.setVersionType(VersionType.EXTERNAL).execute().actionGet();
} catch (VersionConflictEngineException vcee) {
@ -611,7 +665,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
// index document
try {
client().prepareIndex("test", "type", id)
idVersion.response = client().prepareIndex("test", "type", id)
.setSource("foo", "bar")
.setOpType(op)
.setVersion(version)
@ -663,6 +717,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
}
// Verify against truth:
boolean failed = false;
for(String id : ids) {
long expected;
IDAndVersion idVersion = truth.get(id);
@ -671,16 +726,20 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
} else {
expected = -1;
}
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;
long actualVersion = client().prepareGet("test", "type", id).execute().actionGet().getVersion();
if (actualVersion != expected) {
System.out.println("FAILED: idVersion=" + idVersion + " actualVersion=" + actualVersion);
failed = true;
}
}
if (failed) {
System.out.println("All versions:");
for(int i=0;i<idVersions.length;i++) {
System.out.println("i=" + i + " " + idVersions[i]);
}
fail("wrong versions for some IDs");
}
}
@Test