view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialXmlLogParserTest.java @ 976:7bf4d943d5bb

Update copyright
author pavel.sher
date Mon, 22 Jan 2018 11:39:20 +0100
parents 31a1aca3305c
children 10dc26b32c35
line wrap: on
line source
/*
 * Copyright 2000-2018 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.MercurialXmlLogParser;
import jetbrains.buildServer.util.TestFor;
import org.testng.annotations.Test;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

@Test
public class MercurialXmlLogParserTest {

  @TestFor(issues = {"TW-24864", "TW-24214"})
  public void parse_date() throws Exception {
    final SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    final List<Exception> errors = new ArrayList<Exception>();
    final CountDownLatch countDown = new CountDownLatch(1);
    Runnable parseLog = new Runnable() {
      public void run() {
        try {
          countDown.await();
          MercurialXmlLogParser parser = new MercurialXmlLogParser();
          SAXParser saxParser = saxFactory.newSAXParser();
          String logOutput =
                  "<?xml version=\"1.0\"?>" +
                  "<log>" +
                  "<logentry revision=\"11774\" shortnode=\"b1b6ed3cd705\">" +
                  "<parent revision=\"11770\" shortnode=\"7e30fc4a3cda\"/>" +
                  "<author original=\"Mikhail.Pilin\"/>" +
                  "<date>Fri Dec 14 12:22:31 2012 +0100</date>" +
                  "<msg xml:space=\"preserve\">Fix SDK installer.</msg>" +
                  "<paths>" +
                  "<path action=\"M\">.hgsubstate</path>" +
                  "</paths>" +
                  "</logentry>" +
                  "</log>";
          saxParser.parse(new ByteArrayInputStream(logOutput.getBytes("UTF-8")), parser);
          parser.getChangeSets();
        } catch (Exception e) {
          errors.add(e);
        }
      }
    };

    ExecutorService exec = Executors.newFixedThreadPool(10);
    for (int i = 0; i < 10; i++)
      exec.execute(parseLog);

    countDown.countDown();
    exec.shutdown();
    exec.awaitTermination(10, TimeUnit.SECONDS);

    if (!errors.isEmpty())
      throw errors.get(0);
  }

}