public static @Nullable MetricsContainer setCurrentContainer(
      @Nullable MetricsContainer container) {
    MetricsContainerHolder holder = CONTAINER_FOR_THREAD.get();
    @Nullable MetricsContainer previous = holder.container;
    holder.container = container;
    return previous;
  }
@Test
  public void testUsesAppropriateMetricsContainer() {
    Counter counter = Metrics.counter("ns", "name");

    MetricsContainer c1 = Mockito.mock(MetricsContainer.class);
    MetricsContainer c2 = Mockito.mock(MetricsContainer.class);
    Counter counter1 = Mockito.mock(Counter.class);
    Counter counter2 = Mockito.mock(Counter.class);
    when(c1.getCounter(MetricName.named("ns", "name"))).thenReturn(counter1);
    when(c2.getCounter(MetricName.named("ns", "name"))).thenReturn(counter2);

    assertNull(MetricsEnvironment.setCurrentContainer(c1));
    counter.inc();
    assertEquals(c1, MetricsEnvironment.setCurrentContainer(c2));
    counter.dec();
    assertEquals(c2, MetricsEnvironment.setCurrentContainer(null));

    verify(counter1).inc(1L);
    verify(counter2).inc(-1L);
    verifyNoMoreInteractions(counter1, counter2);
  }