public String getContext() {
    return context;
  }
@Test
  public void testBuilderAppendIfAbsent() {
    Configuration conf = new Configuration();
    conf.set(HADOOP_CALLER_CONTEXT_SEPARATOR_KEY, "$");
    CallerContext.Builder builder = new CallerContext.Builder(null, conf);
    builder.append("key1", "value1");
    Assert.assertEquals("key1:value1",
        builder.build().getContext());

    // Append an existed key with different value.
    builder.appendIfAbsent("key1", "value2");
    String[] items = builder.build().getContext().split("\\$");
    Assert.assertEquals(1, items.length);
    Assert.assertEquals("key1:value1",
        builder.build().getContext());

    // Append an absent key.
    builder.appendIfAbsent("key2", "value2");
    String[] items2 = builder.build().getContext().split("\\$");
    Assert.assertEquals(2, items2.length);
    Assert.assertEquals("key1:value1$key2:value2",
        builder.build().getContext());

    // Append a key that is a substring of an existing key.
    builder.appendIfAbsent("key", "value");
    String[] items3 = builder.build().getContext().split("\\$");
    Assert.assertEquals(3, items3.length);
    Assert.assertEquals("key1:value1$key2:value2$key:value",
        builder.build().getContext());
  }