disable using CBOR in randomized test infra

due to a bug in CBOR handling long values (test case to verify it is included), disalbe using CBOR in our tests till it gets fixed
This commit is contained in:
Shay Banon 2014-04-29 19:11:12 -04:00
parent 9038db7bfc
commit 34302a7cc5
2 changed files with 36 additions and 2 deletions

View File

@ -19,6 +19,10 @@
package org.elasticsearch.common.xcontent.cbor;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentGenerator;
@ -27,6 +31,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
@ -37,6 +42,26 @@ import static org.hamcrest.Matchers.nullValue;
*/
public class JsonVsCborTests extends ElasticsearchTestCase {
@Test
public void testBugInJacksonCBOR() throws Exception {
JsonFactory factory = new CBORFactory();
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator generator = factory.createGenerator(out);
generator.writeStartObject();
generator.writeFieldName("field");
generator.writeNumber(-1000000000001L);
generator.writeEndObject();
generator.close();
JsonParser parser = factory.createParser(out.toByteArray());
parser.nextToken();
parser.nextToken();
parser.nextToken();
// this is the bug, if it gets fixed when upgrading to a new Jackson version
// we should re-enable using CBOR in our randomized testing (ElasticsearchTestCase#randomXContentType)
assertThat(parser.getLongValue(), equalTo(0L));
}
@Test
public void compareParsingTokens() throws IOException {
BytesStreamOutput xsonOs = new BytesStreamOutput();

View File

@ -163,8 +163,17 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
});
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(defaultHandler));
Requests.CONTENT_TYPE = randomFrom(XContentType.values());
Requests.INDEX_CONTENT_TYPE = randomFrom(XContentType.values());
Requests.CONTENT_TYPE = randomXContentType();
Requests.INDEX_CONTENT_TYPE = randomXContentType();
}
private static XContentType randomXContentType() {
XContentType type = randomFrom(XContentType.values());
// for now, CBOR is disabled, see JsonVsCborTests#testBugInJacksonCBOR
if (type == XContentType.CBOR) {
return XContentType.JSON;
}
return type;
}
@AfterClass