void HttpConnectionManagerImplTest::setupFilterChain(int num_decoder_filters,
                                                     int num_encoder_filters, int num_requests) {
  // NOTE: The length/repetition in this routine allows InSequence to work correctly in an outer
  // scope.
  for (int i = 0; i < num_decoder_filters * num_requests; i++) {
    decoder_filters_.push_back(new NiceMock<MockStreamDecoderFilter>());
  }

  for (int i = 0; i < num_encoder_filters * num_requests; i++) {
    encoder_filters_.push_back(new NiceMock<MockStreamEncoderFilter>());
  }

  InSequence s;
  for (int req = 0; req < num_requests; req++) {
    EXPECT_CALL(filter_factory_, createFilterChain(_))
        .WillOnce(Invoke([num_decoder_filters, num_encoder_filters, req,
                          this](FilterChainFactoryCallbacks& callbacks) -> void {
          if (log_handler_.get()) {
            callbacks.addAccessLogHandler(log_handler_);
          }
          for (int i = 0; i < num_decoder_filters; i++) {
            callbacks.addStreamDecoderFilter(
                StreamDecoderFilterSharedPtr{decoder_filters_[req * num_decoder_filters + i]});
          }

          for (int i = 0; i < num_encoder_filters; i++) {
            callbacks.addStreamEncoderFilter(
                StreamEncoderFilterSharedPtr{encoder_filters_[req * num_encoder_filters + i]});
          }
        }));

    for (int i = 0; i < num_decoder_filters; i++) {
      EXPECT_CALL(*decoder_filters_[req * num_decoder_filters + i], setDecoderFilterCallbacks(_));
    }

    for (int i = 0; i < num_encoder_filters; i++) {
      EXPECT_CALL(*encoder_filters_[req * num_encoder_filters + i], setEncoderFilterCallbacks(_));
    }
  }
}
void HttpConnectionManagerImplTest::setupFilterChain(int num_decoder_filters,
                                                     int num_encoder_filters, int num_requests) {
   
   
  for (int i = 0; i < num_decoder_filters * num_requests; i++) {
    decoder_filters_.push_back(new NiceMock<MockStreamDecoderFilter>());
  }

  for (int i = 0; i < num_encoder_filters * num_requests; i++) {
    encoder_filters_.push_back(new NiceMock<MockStreamEncoderFilter>());
  }

  InSequence s;
  for (int req = 0; req < num_requests; req++) {
    EXPECT_CALL(filter_factory_, createFilterChain(_))
        .WillOnce(Invoke([num_decoder_filters, num_encoder_filters, req,
                          this](FilterChainFactoryCallbacks& callbacks) -> void {
          if (log_handler_.get()) {
            callbacks.addAccessLogHandler(log_handler_);
          }
          for (int i = 0; i < num_decoder_filters; i++) {
            callbacks.addStreamDecoderFilter(
                StreamDecoderFilterSharedPtr{decoder_filters_[req * num_decoder_filters + i]});
          }

          for (int i = 0; i < num_encoder_filters; i++) {
            callbacks.addStreamEncoderFilter(
                StreamEncoderFilterSharedPtr{encoder_filters_[req * num_encoder_filters + i]});
          }
        }));

    for (int i = 0; i < num_decoder_filters; i++) {
      EXPECT_CALL(*decoder_filters_[req * num_decoder_filters + i], setDecoderFilterCallbacks(_));
    }

    for (int i = 0; i < num_encoder_filters; i++) {
      EXPECT_CALL(*encoder_filters_[req * num_encoder_filters + i], setEncoderFilterCallbacks(_));
    }
  }
}