use of com.linkedin.data.codec.symbol.InMemorySymbolTable in project rest.li by linkedin.
the class TestRuntimeSymbolTableGenerator method testSymbolTableGenerator.
@Test
public void testSymbolTableGenerator() {
DataSchema schema = DataTemplateUtil.getSchema(SimpleGreeting.class);
SymbolTableNameHandler handler = new SymbolTableNameHandler("Haha", "https://localhost:1000/service");
InMemorySymbolTable symbolTable = RuntimeSymbolTableGenerator.generate(handler, Collections.singleton(schema));
Assert.assertEquals(37, symbolTable.size());
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable 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);
}
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable 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;
}
use of com.linkedin.data.codec.symbol.InMemorySymbolTable 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()));
}
Aggregations