use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testJacksonCodecNumbers.
@Test
public void testJacksonCodecNumbers() throws IOException {
JacksonDataCodec codec = new JacksonDataCodec();
testCodecNumbers(codec);
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testJacksonDataCodecErrorToList.
@Test(expectedExceptions = DataDecodingException.class)
public void testJacksonDataCodecErrorToList() throws IOException {
final JacksonDataCodec codec = new JacksonDataCodec();
codec.bytesToList("{\"A\": 1}".getBytes());
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method perfTest.
private void perfTest(int count, DataMap map) throws IOException {
List<DataCodec> codecs = new ArrayList<DataCodec>();
codecs.add(new JacksonDataCodec());
//codecs.add(new Bson4JacksonDataCodec());
codecs.add(new BsonDataCodec());
for (DataCodec codec : codecs) {
byte[] bytes = codec.mapToBytes(map);
out.println(codec.getClass().getName() + " serialized size " + bytes.length);
}
for (DataCodec codec : codecs) {
dataMapToBytesPerfTest(count, codec, map);
}
for (DataCodec codec : codecs) {
byte[] bytes = codec.mapToBytes(map);
bytesToDataMapPerfTest(count, codec, bytes);
}
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestCharacterEncoding method testQueryParamValueEncoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "protocolVersions")
public void testQueryParamValueEncoding(ProtocolVersion protocolVersion) {
RestLiConfig config = new RestLiConfig();
config.setResourcePackageNames(QueryParamMockCollection.class.getPackage().getName());
RestLiServer server = new RestLiServer(config, new PrototypeResourceFactory(), null);
for (char c = 0; c < 256; ++c) {
final String testValue = String.valueOf(c);
GetRequest<EmptyRecord> req = new GetRequestBuilder<String, EmptyRecord>(QueryParamMockCollection.RESOURCE_NAME, EmptyRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), String.class, null, null, EmptyRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS).id("dummy").setParam(QueryParamMockCollection.VALUE_KEY, testValue).build();
RestRequest restRequest = new RestRequestBuilder(RestliUriBuilderUtil.createUriBuilder(req, protocolVersion).build()).setMethod(req.getMethod().getHttpMethod().toString()).build();
// N.B. since QueryParamMockCollection is implemented using the synchronous rest.li interface,
// RestLiServer.handleRequest() will invoke the application resource *and* the callback
// *synchronously*, ensuring that the all instances of the callback are invoked before the
// loop terminates.
server.handleRequest(restRequest, new RequestContext(), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail();
}
@Override
public void onSuccess(RestResponse result) {
try {
DataMap data = new JacksonDataCodec().readMap(result.getEntity().asInputStream());
Assert.assertEquals(data.get(QueryParamMockCollection.VALUE_KEY), testValue);
Assert.assertEquals(QueryParamMockCollection._lastQueryParamValue, testValue);
} catch (IOException e) {
Assert.fail();
}
}
});
}
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestRestLiSnapshotExporter method compareFiles.
private void compareFiles(String actualFileName, String expectedFileName) throws Exception {
String actualContent = readFile(actualFileName);
String expectedContent = readFile(expectedFileName);
//Compare using a map as opposed to line by line
final JacksonDataCodec jacksonDataCodec = new JacksonDataCodec();
final DataMap actualContentMap = jacksonDataCodec.stringToMap(actualContent);
final DataMap expectedContentMap = jacksonDataCodec.stringToMap(expectedContent);
if (!actualContentMap.equals(expectedContentMap)) {
// Ugh... gradle
PrintStream actualStdout = new PrintStream(new FileOutputStream(FileDescriptor.out));
actualStdout.println("ERROR " + actualFileName + " does not match " + expectedFileName + " . Printing diff...");
try {
// TODO environment dependent, not cross platform
ProcessBuilder pb = new ProcessBuilder("diff", expectedFileName, actualFileName);
pb.redirectErrorStream();
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
actualStdout.println(line);
}
} catch (Exception e) {
// TODO Setup log4j, find appropriate test harness used in R2D2
actualStdout.println("Error printing diff: " + e.getMessage());
}
fail(actualFileName + " does not match " + expectedFileName);
}
}
Aggregations