@Test
 public void findStructuredGroups() {
   Pattern pattern = compile("\\{\\w*\\}");
   Matcher matcher = pattern.matcher("/{parameter1}/some/path/{parameter2}/end");
   while (matcher.find()) {
     log.info("Found parameter: [" + matcher.group().replaceAll("\\{|\\}", "") + "]");
   }
   String output = matcher.replaceAll("(.*)");
   log.info("Replaced output: [" + output + "]");
 }
  @Test
  public void findsMultipleGroups() {
    Pattern pattern = compile("\\w* ");

    Matcher matcher = pattern.matcher("this is a sentance");
    log.info("GroupCount: " + matcher.groupCount());
    while (matcher.find()) {
      log.info("Found group : [" + matcher.group().trim() + "]");
    }
  }
 @Test
 public void findStructuredGroupsWithParenthesis() {
   Pattern pattern = compile("\\([^\\)]*\\)");
   Matcher matcher =
       pattern.matcher("Some sentance (parameter 1d) /some/path/ (parameter 2 ) /end");
   while (matcher.find()) {
     log.info("Found parameter: [" + matcher.group().replaceAll("\\(|\\)", "") + "]");
   }
   String output = matcher.replaceAll("(.*)");
   log.info("Replaced output: [" + output + "]");
 }
 private void takeHeapDump(File dumpDir, int i) {
   InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
   CommandLine commandLine =
       CommandLine.createCommandLine("jmap")
           .withArgs(
               "-J-d64",
               String.format("-dump:format=b,file=%s/%s.hprof", dumpDir.getAbsoluteFile(), i),
               ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
   LOGGER.info(commandLine.describe());
   int exitCode = commandLine.run(outputStreamConsumer, "thread" + i);
   LOGGER.info(outputStreamConsumer.getAllOutput());
   assertThat(exitCode, is(0));
   LOGGER.info(String.format("Heap dump available at %s", dumpDir.getAbsolutePath()));
 }
 private void run(
     Runnable runnable, int numberOfRequests, final ConcurrentHashMap<String, Boolean> results)
     throws InterruptedException {
   Boolean finalResult = true;
   LOGGER.info("Tests start now!");
   final ArrayList<Thread> threads = new ArrayList<>();
   for (int i = 0; i < numberOfRequests; i++) {
     Thread t = new Thread(runnable, "pipeline" + i);
     threads.add(t);
   }
   for (Thread t : threads) {
     Thread.sleep(1000 * (new Random().nextInt(3) + 1));
     t.setUncaughtExceptionHandler(
         new Thread.UncaughtExceptionHandler() {
           public void uncaughtException(Thread t, Throwable e) {
             LOGGER.error("Exception " + e + " from thread " + t);
             results.put(t.getName(), false);
           }
         });
     t.start();
   }
   for (Thread t : threads) {
     int i = threads.indexOf(t);
     if (i == (numberOfRequests - 1)) {
       //                takeHeapDump(dumpDir, i);
     }
     t.join();
   }
   for (String threadId : results.keySet()) {
     finalResult = results.get(threadId) && finalResult;
   }
   assertThat(finalResult, is(true));
 }
  private void setupPipelines(Integer numberOfPipelinesToBeCreated) throws Exception {
    String groupName = "jumbo";
    String configFile = "<FULL PATH TO YOUR CONFIG FILE>";
    String xml = FileUtil.readContentFromFile(new File(configFile));
    xml = goConfigMigration.upgradeIfNecessary(xml);
    goConfigService
        .fileSaver(false)
        .saveConfig(xml, goConfigService.getConfigForEditing().getMd5());
    LOGGER.info(
        String.format(
            "Total number of pipelines in this config: %s",
            goConfigService.getConfigForEditing().allPipelines().size()));
    if (goConfigService.getConfigForEditing().hasPipelineGroup(groupName)) {
      ((BasicPipelineConfigs) goConfigService.getConfigForEditing().findGroup(groupName)).clear();
    }
    final CruiseConfig configForEditing = goConfigService.getConfigForEditing();
    for (int i = 0; i < numberOfPipelinesToBeCreated; i++) {
      JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job"));
      StageConfig stageConfig =
          new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(jobConfig));
      PipelineConfig pipelineConfig =
          new PipelineConfig(
              new CaseInsensitiveString("pipeline" + i),
              new MaterialConfigs(new GitMaterialConfig("FOO")),
              stageConfig);
      configForEditing.addPipeline(groupName, pipelineConfig);
    }

    goConfigService.updateConfig(
        new UpdateConfigCommand() {
          @Override
          public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            return configForEditing;
          }
        });
  }