@Test
public void testEncode() throws Exception {

    SofaTracerSpan sofaTracerSpan = (SofaTracerSpan) this.sofaTracer
        .buildSpan("spanOperationName").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
        .withTag(SpanTags.CURR_APP_TAG.getKey(), appName).start();
    SofaTracerSpanContext sofaTracerSpanContext = sofaTracerSpan.getSofaTracerSpanContext();
    Exception exception = new RuntimeException("CommonSpanEncoderTest");
    String errorType = "timeout_error";
    String[] errorSources = new String[] { "trade", "rpc" };
    Map<String, String> context = new HashMap<String, String>();
    context.put("serviceName", "service");
    context.put("methodName", "methodCall");
    sofaTracerSpan.setBaggageItem("baggage", "value");
    sofaTracerSpan.setBaggageItem("baggage1", "value1");
    sofaTracerSpan.setBaggageItem("baggage2", "value2");
    //Record an error log
    sofaTracerSpan.reportError(errorType, context, exception, appName, errorSources);
    //Record a client log
    sofaTracerSpan.finish();
    TestUtil.waitForAsyncLog();
    //Check client logs
    List<String> clientDigestContents = FileUtils.readLines(new File(logDirectoryPath
                                                                     + File.separator
                                                                     + clientLogType));
    assertTrue(clientDigestContents.size() == 1);
    assertTrue(clientDigestContents.get(0).contains(sofaTracerSpanContext.getTraceId()));
    //error log
    List<String> errorContents = FileUtils
        .readLines(customFileLog(TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName()));
    //Error stack
    assertTrue(errorContents.size() > 1);
    assertTrue(errorContents.get(0).contains(sofaTracerSpanContext.getTraceId()));
    //remove head
    String fileContent = errorContents.get(0).substring(errorContents.get(0).indexOf(",") + 1);
    //remove end
    fileContent = fileContent.substring(0, fileContent.lastIndexOf(","));
    //construct result
    List<String> params = new ArrayList<>();
    params.add(sofaTracerSpan.getTagsWithStr().get(SpanTags.CURR_APP_TAG.getKey()));
    params.add(sofaTracerSpanContext.getTraceId());
    params.add(sofaTracerSpanContext.getSpanId());
    params.add(Thread.currentThread().getName());
    params.add(errorType);
    params.add(StringUtils.arrayToString(errorSources, ARRAY_SEPARATOR, "", ""));
    params.add(MAP_PREFIX + StringUtils.mapToString(context));
    params.add(MAP_PREFIX + StringUtils.mapToString(sofaTracerSpanContext.getBizBaggage()));
    Assert.assertTrue("Content Checkout error", checkResult(params, fileContent));
}