@Test
public void testInvalidateUpstreamFormatAdjustment() {

  AtomicReference<String> label = new AtomicReference<>("label1");
  sampleQueue =
      new SampleQueue(allocator, mockDrmSessionManager) {
        @Override
        public Format getAdjustedUpstreamFormat(Format format) {
          return super.getAdjustedUpstreamFormat(format.copyWithLabel(label.get()));
        }
      };
  writeFormat(FORMAT_1);
  writeSample(DATA, /* timestampUs= */ 0, BUFFER_FLAG_KEY_FRAME);
  // Make a change that'll affect the SampleQueue's format adjustment, and invalidate it.
  label.set("label2");
  sampleQueue.invalidateUpstreamFormatAdjustment();
  writeSample(DATA, /* timestampUs= */ 1, /* sampleFlags= */ 0);
  assertReadFormat(/* formatRequired= */ false, FORMAT_1.copyWithLabel("label1"));
  assertReadSample(
      /* timeUs= */ 0,
      /* isKeyFrame= */ true,
      /* isEncrypted= */ false,
      DATA,
      /* offset= */ 0,
      DATA.length);
  assertReadFormat(/* formatRequired= */ false, FORMAT_1.copyWithLabel("label2"));
  assertReadSample(
      /* timeUs= */ 1,
      /* isKeyFrame= */ false,
      /* isEncrypted= */ false,
      DATA,
      /* offset= */ 0,
      DATA.length);
  assertReadEndOfStream(/* formatRequired= */ false);
}