public static <T extends DataflowWorkerHarnessOptions> T initializeGlobalStateAndPipelineOptions(
      Class<?> workerHarnessClass, Class<T> harnessOptionsClass) throws Exception {
    /* Extract pipeline options. */
    T pipelineOptions =
        WorkerPipelineOptionsFactory.createFromSystemProperties(harnessOptionsClass);
    pipelineOptions.setAppName(workerHarnessClass.getSimpleName());

    /* Configure logging with job-specific properties. */
    DataflowWorkerLoggingMDC.setJobId(pipelineOptions.getJobId());
    DataflowWorkerLoggingMDC.setWorkerId(pipelineOptions.getWorkerId());

    ExperimentContext ec = ExperimentContext.parseFrom(pipelineOptions);

    String experimentName = Experiment.EnableConscryptSecurityProvider.getName();
    if (ec.isEnabled(Experiment.EnableConscryptSecurityProvider)) {
      /* Enable fast SSL provider. */
      LOG.info(
          "Dataflow runner is using conscrypt SSL. To disable this feature, "
              + "remove the pipeline option --experiments={}",
          experimentName);
      Security.insertProviderAt(new OpenSSLProvider(), 1);
    } else {
      LOG.info(
          "Not using conscrypt SSL. Note this is the default Java behavior, but may "
              + "have reduced performance. To use conscrypt SSL pass pipeline option "
              + "--experiments={}",
          experimentName);
    }
    return pipelineOptions;
  }
@Test
  public void testLoggingConfiguration() throws Exception {
    DataflowWorkerHarnessOptions pipelineOptions =
        PipelineOptionsFactory.as(DataflowWorkerHarnessOptions.class);
    pipelineOptions.setJobId(JOB_ID);
    pipelineOptions.setWorkerId(WORKER_ID);
    String serializedOptions = new ObjectMapper().writeValueAsString(pipelineOptions);
    File file = tmpFolder.newFile();
    Files.write(Paths.get(file.getPath()), serializedOptions.getBytes(StandardCharsets.UTF_8));
    System.setProperty("sdk_pipeline_options_file", file.getPath());

    DataflowWorkerHarnessOptions generatedOptions =
        DataflowWorkerHarnessHelper.initializeGlobalStateAndPipelineOptions(
            DataflowBatchWorkerHarnessTest.class, DataflowWorkerHarnessOptions.class);
    // Assert that the returned options are correct.
    assertThat(generatedOptions.getJobId(), equalTo(JOB_ID));
    assertThat(generatedOptions.getWorkerId(), equalTo(WORKER_ID));

    // Assert that the global logging configuration was properly initialized.
    assertThat(DataflowWorkerLoggingMDC.getJobId(), equalTo(JOB_ID));
    assertThat(DataflowWorkerLoggingMDC.getWorkerId(), equalTo(WORKER_ID));
  }