Search in sources :

Example 11 with JacksonDataCodec

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);
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with JacksonDataCodec

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());
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with JacksonDataCodec

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);
    }
}
Also used : PsonDataCodec(com.linkedin.data.codec.PsonDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) DataCodec(com.linkedin.data.codec.DataCodec) TextDataCodec(com.linkedin.data.codec.TextDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) ArrayList(java.util.ArrayList)

Example 14 with JacksonDataCodec

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();
                }
            }
        });
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) RestLiServer(com.linkedin.restli.server.RestLiServer) CompoundKey(com.linkedin.restli.common.CompoundKey) RestResponse(com.linkedin.r2.message.rest.RestResponse) IOException(java.io.IOException) DataMap(com.linkedin.data.DataMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) PrototypeResourceFactory(com.linkedin.restli.server.resources.PrototypeResourceFactory) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) RestLiConfig(com.linkedin.restli.server.RestLiConfig) Test(org.testng.annotations.Test)

Example 15 with JacksonDataCodec

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);
    }
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) DataMap(com.linkedin.data.DataMap)

Aggregations

JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)27 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)7 DataMap (com.linkedin.data.DataMap)6 BeforeTest (org.testng.annotations.BeforeTest)5 BackupRequestsConfiguration (com.linkedin.d2.BackupRequestsConfiguration)3 BoundedCostBackupRequests (com.linkedin.d2.BoundedCostBackupRequests)3 DataCodec (com.linkedin.data.codec.DataCodec)3 ByteString (com.linkedin.data.ByteString)2 BsonDataCodec (com.linkedin.data.codec.BsonDataCodec)2 PsonDataCodec (com.linkedin.data.codec.PsonDataCodec)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)1