Search in sources :

Example 11 with SymbolTable

use of com.linkedin.data.codec.symbol.SymbolTable in project rest.li by linkedin.

the class TestCodec method perfTest.

private void perfTest(int count, DataMap map) throws IOException {
    List<DataCodec> codecs = new ArrayList<>();
    codecs.add(new JacksonDataCodec());
    codecs.add(new BsonDataCodec());
    codecs.add(new JacksonSmileDataCodec());
    Set<String> symbols = new HashSet<>();
    collectSymbols(symbols, map);
    final String sharedSymbolTableName = "SHARED";
    SymbolTable symbolTable = new InMemorySymbolTable(sharedSymbolTableName, new ArrayList<>(symbols));
    SymbolTableProvider provider = new SymbolTableProvider() {

        @Override
        public SymbolTable getSymbolTable(String symbolTableName) {
            if (sharedSymbolTableName.equals(symbolTableName)) {
                return symbolTable;
            }
            return null;
        }
    };
    SymbolTableProviderHolder.INSTANCE.setSymbolTableProvider(provider);
    codecs.add(new JacksonLICORBinaryDataCodec(symbolTable));
    codecs.add(new JacksonLICORTextDataCodec(symbolTable));
    codecs.add(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().setSymbolTable(symbolTable).build()));
    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 : SymbolTableProvider(com.linkedin.data.codec.symbol.SymbolTableProvider) ArrayList(java.util.ArrayList) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable) SymbolTable(com.linkedin.data.codec.symbol.SymbolTable) ByteString(com.linkedin.data.ByteString) HashSet(java.util.HashSet) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable)

Example 12 with SymbolTable

use of com.linkedin.data.codec.symbol.SymbolTable in project rest.li by linkedin.

the class TestStreamCodec method getCodecs.

private List<StreamDataCodec> getCodecs(int bufferSize, DataComplex data) {
    List<StreamDataCodec> codecs = new ArrayList<>();
    codecs.add(new JacksonSmileStreamDataCodec(bufferSize));
    codecs.add(new JacksonStreamDataCodec(bufferSize));
    codecs.add(new ProtobufStreamDataCodec(bufferSize));
    Set<String> symbols = new HashSet<>();
    if (data instanceof DataMap) {
        collectSymbols(symbols, (DataMap) data);
    } else {
        collectSymbols(symbols, (DataList) data);
    }
    final String sharedSymbolTableName = "SHARED";
    SymbolTable symbolTable = new InMemorySymbolTable(sharedSymbolTableName, new ArrayList<>(symbols));
    codecs.add(new JacksonLICORStreamDataCodec(bufferSize, true, symbolTable));
    codecs.add(new ProtobufStreamDataCodec(bufferSize, new ProtobufCodecOptions.Builder().setSymbolTable(symbolTable).setEnableASCIIOnlyStrings(true).build()));
    return codecs;
}
Also used : ArrayList(java.util.ArrayList) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable) SymbolTable(com.linkedin.data.codec.symbol.SymbolTable) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) ProtobufCodecOptions(com.linkedin.data.codec.ProtobufCodecOptions) HashSet(java.util.HashSet) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable)

Example 13 with SymbolTable

use of com.linkedin.data.codec.symbol.SymbolTable in project rest.li by linkedin.

the class TestRestLiSymbolTableRequestHandler method testReturnSelfSymbolTable.

@Test
public void testReturnSelfSymbolTable() throws Exception {
    SymbolTable symbolTable = new InMemorySymbolTable("TestName", ImmutableList.of("Haha", "Hehe", "Hoho"));
    URI uri = URI.create("/symbolTable");
    RestRequest request = new RestRequestBuilder(uri).build();
    when(_symbolTableProvider.getResponseSymbolTable(eq(uri), eq(Collections.emptyMap()))).thenReturn(symbolTable);
    CompletableFuture<RestResponse> future = new CompletableFuture<>();
    _requestHandler.handleRequest(request, mock(RequestContext.class), new Callback<RestResponse>() {

        @Override
        public void onError(Throwable e) {
            future.completeExceptionally(e);
        }

        @Override
        public void onSuccess(RestResponse result) {
            future.complete(result);
        }
    });
    Assert.assertFalse(future.isCompletedExceptionally());
    Assert.assertTrue(future.isDone());
    RestResponse response = future.get();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
    Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), ContentType.PROTOBUF2.getHeaderKey());
    Assert.assertEquals(symbolTable, SymbolTableSerializer.fromByteString(response.getEntity(), ContentType.PROTOBUF2.getCodec()));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable) SymbolTable(com.linkedin.data.codec.symbol.SymbolTable) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) InMemorySymbolTable(com.linkedin.data.codec.symbol.InMemorySymbolTable) Test(org.testng.annotations.Test)

Aggregations

SymbolTable (com.linkedin.data.codec.symbol.SymbolTable)13 InMemorySymbolTable (com.linkedin.data.codec.symbol.InMemorySymbolTable)12 Test (org.testng.annotations.Test)8 RestRequest (com.linkedin.r2.message.rest.RestRequest)6 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)6 URI (java.net.URI)6 ByteString (com.linkedin.data.ByteString)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 RequestContext (com.linkedin.r2.message.RequestContext)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)3 EmptySymbolTable (com.linkedin.data.codec.symbol.EmptySymbolTable)2 SymbolTableProvider (com.linkedin.data.codec.symbol.SymbolTableProvider)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DataMap (com.linkedin.data.DataMap)1 ProtobufCodecOptions (com.linkedin.data.codec.ProtobufCodecOptions)1 DefaultSymbolTableProvider (com.linkedin.data.codec.symbol.DefaultSymbolTableProvider)1 SymbolTableMetadata (com.linkedin.data.codec.symbol.SymbolTableMetadata)1