Repository: apache/hadoop
File: hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/appmaster/TestAMSimulator.java (Java)

Code before:
          FairSchedulerMetrics.Metric.values()) {
        String key = "variable.app." + appId + "." + metric.getValue() +
            ".memory";
        Assertions.assertTrue(metricRegistry.getGauges().containsKey(key));
        Assertions.assertNotNull(metricRegistry.getGauges().get(key).getValue());
      }
    }
  }

  private void createMetricOutputDir() {
    Path testDir =
        Paths.get(System.getProperty("test.build.data", "target/test-dir"));
    try {
      metricOutputDir = Files.createTempDirectory(testDir, "output");
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  private void createNodeLabelsStoreDir() {
    Path testDir =
        Paths.get(System.getProperty("test.build.data", "target/test-dir"));
    try {
      nodeLabelsStoreDir = Files.createTempDirectory(testDir, "node-labels");
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  private void deleteMetricOutputDir() {
    try {
      FileUtils.deleteDirectory(metricOutputDir.toFile());
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  private void deleteNodeLabelsStoreDir() {
    try {
      FileUtils.deleteDirectory(nodeLabelsStoreDir.toFile());
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  @ParameterizedTest
  @MethodSource("params")
  public void testAMSimulator(Class<?> pSlsScheduler, Class<?> pScheduler) throws Exception {
    initTestAMSimulator(pSlsScheduler, pScheduler);
    // Register one app
    MockAMSimulator app = new MockAMSimulator();

Review comment (bug):
Optional: consider just letting this exception propagate to fail the test.

Code after:
      for (FairSchedulerMetrics.Metric metric :
          FairSchedulerMetrics.Metric.values()) {
        String key = "variable.app." + appId + "." + metric.getValue() +
            ".memory";
        Assertions.assertTrue(metricRegistry.getGauges().containsKey(key));
        Assertions.assertNotNull(metricRegistry.getGauges().get(key).getValue());
      }
    }
  }

  private void createMetricOutputDir() {
    Path testDir =
        Paths.get(System.getProperty("test.build.data", "target/test-dir"));
    try {
      metricOutputDir = Files.createTempDirectory(testDir, "output");
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  private void createNodeLabelsStoreDir() throws IOException {
    Path testDir =
        Paths.get(System.getProperty("test.build.data", "target/test-dir"));
    nodeLabelsStoreDir = Files.createTempDirectory(testDir, "node-labels");
  }

  private void deleteMetricOutputDir() {
    try {
      FileUtils.deleteDirectory(metricOutputDir.toFile());
    } catch (IOException e) {
      Assertions.fail(e.toString());
    }
  }

  private void deleteNodeLabelsStoreDir() throws IOException {
    FileUtils.deleteDirectory(nodeLabelsStoreDir.toFile());
  }

  @ParameterizedTest
  @MethodSource("params")
  public void testAMSimulator(Class<?> pSlsScheduler, Class<?> pScheduler) throws Exception {
    initTestAMSimulator(pSlsScheduler, pScheduler);
    // Register one app
    MockAMSimulator app = new MockAMSimulator();
    String appId = "app1";
    String queue = "default";
    List<ContainerSimulator> containers = new ArrayList<>();
    HashMap<ApplicationId, AMSimulator> map = new HashMap<>();

    UserName mockUser = mock(UserName.class);
    when(mockUser.getValue()).thenReturn("user1");