use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestCloudPerformance method run.
@Test
public void run() throws IOException {
DataCodec[] codecs = { new JacksonDataCodec(), new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(false).setEncodeStringLength(false)), new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(false).setEncodeStringLength(true)), new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(true).setEncodeStringLength(false)), new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(true).setEncodeStringLength(true)) };
if (_testOnly == false) {
out.println("Number of elements " + _numElements);
out.println("Number of iterations " + _numIterations);
}
for (DataCodec codec : codecs) {
testSerializeDataMap(codec);
testDeserializeDataMap(codec);
}
testEdgeListAddAll();
testEdgeListEfficientAddAll();
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class ParSeqRestClientTest method mockClient.
/**
* @return a mock ParSeqRestClient that gives an error
*/
@SuppressWarnings("deprecation")
private ParSeqRestClient mockClient(final String errKey, final String errValue, final String errMsg, final int httpCode, final int appCode, String code, String docUrl, String requestId, final ProtocolVersion protocolVersion, final String errorResponseHeaderName) {
final ErrorResponse er = new ErrorResponse();
final DataMap errMap = new DataMap();
errMap.put(errKey, errValue);
er.setErrorDetails(new ErrorDetails(errMap));
er.setErrorDetailType(EmptyRecord.class.getCanonicalName());
er.setStatus(httpCode);
er.setMessage(errMsg);
er.setServiceErrorCode(appCode);
er.setCode(code);
er.setDocUrl(docUrl);
er.setRequestId(requestId);
final byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(er.data());
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
headers.put(errorResponseHeaderName, RestConstants.HEADER_VALUE_ERROR);
RestClient restClient = new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost");
return new ParSeqRestliClientBuilder().setClient(restClient).setConfig(new ParSeqRestliClientConfigBuilder().build()).build();
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class ParSeqRestClientTest method mockClient.
/**
* @return a mock ParSeqRestClient that returns a TestRecord with the given id.
*/
private ParSeqRestClient mockClient(final long id, final int httpCode, final ProtocolVersion protocolVersion) {
final TestRecord record = new TestRecord().setId(id);
byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(record.data());
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
RestClient restClient = new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost");
return new ParSeqRestliClientBuilder().setClient(restClient).setConfig(new ParSeqRestliClientConfigBuilder().build()).build();
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class ExporterTestUtils method compareFiles.
/**
* Compares two JSON files and throws an AssertionError if the files are semantically different. Assumes that the
* root data object in the file is a map. Used mainly to compare the content of generated IDL and snapshot files.
*
* @param actualFileName filename of the generated JSON file.
* @param expectedFileName filename of the reference JSON file.
* @throws IOException if file read or file parse fails.
*/
public static void compareFiles(String actualFileName, String expectedFileName) throws IOException {
String actualContent = ExporterTestUtils.readFile(actualFileName);
String expectedContent = ExporterTestUtils.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());
}
Assert.fail(actualFileName + " does not match " + expectedFileName);
}
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestBackupRequestsClient method createBackupRequestsConfiguration.
@SuppressWarnings("unchecked")
private final Map<String, Object> createBackupRequestsConfiguration(int cost, String operation) throws JsonParseException, JsonMappingException, IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(cost);
brc.setOperation(operation);
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
return JacksonUtil.getObjectMapper().readValue(json, Map.class);
}
Aggregations