Search in sources :

Example 1 with PTest

use of org.apache.hive.ptest.execution.PTest in project hive by apache.

the class TestTestConfiguration method testPTest.

@Test
public void testPTest() throws Exception {
    Host testHost = new Host("test", "test", new String[1], 1);
    Set<Host> testHosts = new HashSet<Host>();
    testHosts.add(testHost);
    TestConfiguration conf = TestConfiguration.fromInputStream(Resources.getResource("test-configuration.properties").openStream(), LOG);
    ExecutionContext execContext = new ExecutionContext(null, testHosts, "test", null);
    PTest.Builder mPTestBuilder = new PTest.Builder();
    PTest ptest = mPTestBuilder.build(conf, execContext, "1234", baseDir.newFolder(), null, null, null, null);
    Map<String, String> templateDefaults = ptest.getTemplateDefaults();
    Assert.assertEquals("git://github.com/apache/hive.git", templateDefaults.get("repository"));
    Assert.assertEquals("apache-github", templateDefaults.get("repositoryName"));
    Assert.assertEquals("trunk", templateDefaults.get("branch"));
    Assert.assertEquals("-Dtest.continue.on.failure=true -Dtest.silent=false", templateDefaults.get("antArgs"));
    Assert.assertEquals("hadoop-1,hadoop-2", templateDefaults.get("additionalProfiles"));
}
Also used : ExecutionContext(org.apache.hive.ptest.execution.context.ExecutionContext) PTest(org.apache.hive.ptest.execution.PTest) HashSet(java.util.HashSet) Test(org.junit.Test) PTest(org.apache.hive.ptest.execution.PTest)

Example 2 with PTest

use of org.apache.hive.ptest.execution.PTest in project hive by apache.

the class TestExecutor method run.

@Override
public void run() {
    while (execute) {
        Test test = null;
        PrintStream logStream = null;
        Logger logger = null;
        try {
            // start a log cleaner at the start of each test
            LogDirectoryCleaner cleaner = new LogDirectoryCleaner(new File(mExecutionContextConfiguration.getGlobalLogDirectory()), mExecutionContextConfiguration.getMaxLogDirectoriesPerProfile());
            cleaner.setName("LogCleaner-" + mExecutionContextConfiguration.getGlobalLogDirectory());
            cleaner.setDaemon(true);
            cleaner.start();
            test = mTestQueue.poll(30, TimeUnit.MINUTES);
            if (!execute) {
                terminateExecutionContext();
                break;
            }
            if (test == null) {
                terminateExecutionContext();
            } else {
                test.setStatus(Status.inProgress());
                test.setDequeueTime(System.currentTimeMillis());
                if (mExecutionContext == null) {
                    mExecutionContext = createExceutionContext();
                }
                test.setExecutionStartTime(System.currentTimeMillis());
                TestStartRequest startRequest = test.getStartRequest();
                String profile = startRequest.getProfile();
                File profileConfFile = new File(mExecutionContextConfiguration.getProfileDirectory(), String.format("%s.properties", profile));
                LOG.info("Attempting to run using profile file: {}", profileConfFile);
                if (!profileConfFile.isFile()) {
                    test.setStatus(Status.illegalArgument("Profile " + profile + " not found in directory " + mExecutionContextConfiguration.getProfileDirectory()));
                    test.setExecutionFinishTime(System.currentTimeMillis());
                } else {
                    File logDir = Dirs.create(new File(mExecutionContextConfiguration.getGlobalLogDirectory(), test.getStartRequest().getTestHandle()));
                    File logFile = new File(logDir, "execution.txt");
                    test.setOutputFile(logFile);
                    logStream = new PrintStream(logFile);
                    logger = new TestLogger(logStream, TestLogger.LEVEL.DEBUG);
                    TestConfiguration testConfiguration = TestConfiguration.fromFile(profileConfFile, logger);
                    testConfiguration.setPatch(startRequest.getPatchURL());
                    testConfiguration.setJiraName(startRequest.getJiraName());
                    testConfiguration.setClearLibraryCache(startRequest.isClearLibraryCache());
                    LocalCommandFactory localCommandFactory = new LocalCommandFactory(logger);
                    PTest ptest = mPTestBuilder.build(testConfiguration, mExecutionContext, test.getStartRequest().getTestHandle(), logDir, localCommandFactory, new SSHCommandExecutor(logger), new RSyncCommandExecutor(logger, mExecutionContextConfiguration.getMaxRsyncThreads(), localCommandFactory), logger);
                    int result = ptest.run();
                    if (result == Constants.EXIT_CODE_SUCCESS) {
                        test.setStatus(Status.ok());
                    } else {
                        test.setStatus(Status.failed("Tests failed with exit code " + result));
                    }
                    logStream.flush();
                    // if all drones where abandoned on a host, try replacing them.
                    mExecutionContext.replaceBadHosts();
                }
            }
        } catch (Exception e) {
            LOG.error("Unxpected Error", e);
            if (test != null) {
                test.setStatus(Status.failed("Tests failed with exception " + e.getClass().getName() + ": " + e.getMessage()));
                if (logger != null) {
                    String msg = "Error executing " + test.getStartRequest().getTestHandle();
                    logger.error(msg, e);
                }
            }
            // if we died for any reason lets get a new set of hosts
            terminateExecutionContext();
        } finally {
            if (test != null) {
                test.setExecutionFinishTime(System.currentTimeMillis());
            }
            if (logStream != null) {
                logStream.flush();
                logStream.close();
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) TestConfiguration(org.apache.hive.ptest.execution.conf.TestConfiguration) SSHCommandExecutor(org.apache.hive.ptest.execution.ssh.SSHCommandExecutor) Logger(org.slf4j.Logger) PTest(org.apache.hive.ptest.execution.PTest) CreateHostsFailedException(org.apache.hive.ptest.execution.context.CreateHostsFailedException) ServiceNotAvailableException(org.apache.hive.ptest.execution.context.ServiceNotAvailableException) LogDirectoryCleaner(org.apache.hive.ptest.execution.LogDirectoryCleaner) PTest(org.apache.hive.ptest.execution.PTest) RSyncCommandExecutor(org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor) TestStartRequest(org.apache.hive.ptest.api.request.TestStartRequest) LocalCommandFactory(org.apache.hive.ptest.execution.LocalCommandFactory) File(java.io.File)

Example 3 with PTest

use of org.apache.hive.ptest.execution.PTest in project hive by apache.

the class TestTestExecutor method setup.

@Before
public void setup() throws Exception {
    startRequest = new TestStartRequest();
    startRequest.setProfile(PROFILE);
    startRequest.setTestHandle(TEST_HANDLE);
    test = new Test(startRequest, Status.pending(), System.currentTimeMillis());
    testQueue = new ArrayBlockingQueue<Test>(1);
    executionContextConfiguration = mock(ExecutionContextConfiguration.class);
    executionContextProvider = mock(ExecutionContextProvider.class);
    ptest = mock(PTest.class);
    Set<Host> hosts = Sets.newHashSet();
    String baseDirPath = baseDir.getRoot().getAbsolutePath();
    executionContext = new ExecutionContext(executionContextProvider, hosts, baseDirPath, PRIVATE_KEY);
    profileProperties = new File(baseDirPath, PROFILE + ".properties");
    when(executionContextConfiguration.getProfileDirectory()).thenReturn(baseDirPath);
    when(executionContextConfiguration.getGlobalLogDirectory()).thenReturn(baseDirPath);
    when(executionContextProvider.createExecutionContext()).thenReturn(executionContext);
    Assert.assertTrue(profileProperties.toString(), profileProperties.createNewFile());
    OutputStream profilePropertiesOutputStream = new FileOutputStream(profileProperties);
    Resources.copy(Resources.getResource("test-configuration.properties"), profilePropertiesOutputStream);
    profilePropertiesOutputStream.close();
    ptestBuilder = new PTest.Builder() {

        @Override
        public PTest build(TestConfiguration configuration, ExecutionContext executionContext, String buildTag, File logDir, LocalCommandFactory localCommandFactory, SSHCommandExecutor sshCommandExecutor, RSyncCommandExecutor rsyncCommandExecutor, Logger logger) throws Exception {
            return ptest;
        }
    };
    testExecutor = new TestExecutor(executionContextConfiguration, executionContextProvider, testQueue, ptestBuilder);
    testExecutor.setDaemon(true);
    testExecutor.start();
    TimeUnit.MILLISECONDS.sleep(100);
}
Also used : ExecutionContextConfiguration(org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TestConfiguration(org.apache.hive.ptest.execution.conf.TestConfiguration) Host(org.apache.hive.ptest.execution.conf.Host) SSHCommandExecutor(org.apache.hive.ptest.execution.ssh.SSHCommandExecutor) Logger(org.slf4j.Logger) PTest(org.apache.hive.ptest.execution.PTest) ExecutionContext(org.apache.hive.ptest.execution.context.ExecutionContext) PTest(org.apache.hive.ptest.execution.PTest) RSyncCommandExecutor(org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor) FileOutputStream(java.io.FileOutputStream) TestStartRequest(org.apache.hive.ptest.api.request.TestStartRequest) LocalCommandFactory(org.apache.hive.ptest.execution.LocalCommandFactory) ExecutionContextProvider(org.apache.hive.ptest.execution.context.ExecutionContextProvider) File(java.io.File) Before(org.junit.Before)

Example 4 with PTest

use of org.apache.hive.ptest.execution.PTest in project hive by apache.

the class TestTestConfiguration method testGettersSetters.

@Test
public void testGettersSetters() throws Exception {
    ExecutionContextConfiguration execConf = ExecutionContextConfiguration.fromInputStream(Resources.getResource("test-configuration.properties").openStream());
    TestConfiguration conf = TestConfiguration.fromInputStream(Resources.getResource("test-configuration.properties").openStream(), LOG);
    Set<Host> expectedHosts = Sets.newHashSet(new Host("localhost", "hiveptest", new String[] { "/home/hiveptest" }, 2));
    ExecutionContext executionContext = execConf.getExecutionContextProvider().createExecutionContext();
    Assert.assertEquals(expectedHosts, executionContext.getHosts());
    Assert.assertEquals("/tmp/hive-ptest-units/working/dir", execConf.getWorkingDirectory());
    Assert.assertEquals("/etc/hiveptest/conf", execConf.getProfileDirectory());
    Assert.assertEquals("/tmp/hive-ptest-units/working/dir/logs", execConf.getGlobalLogDirectory());
    Assert.assertEquals("/home/brock/.ssh/id_rsa", executionContext.getPrivateKey());
    Assert.assertEquals("git://github.com/apache/hive.git", conf.getRepository());
    Assert.assertEquals("apache-github", conf.getRepositoryName());
    Assert.assertEquals("trunk", conf.getBranch());
    Assert.assertEquals("/tmp/hive-ptest-units/working/dir/working", executionContext.getLocalWorkingDirectory());
    Assert.assertEquals("-Dtest.continue.on.failure=true -Dtest.silent=false", conf.getAntArgs());
    Assert.assertEquals("hadoop-1,hadoop-2", conf.getAdditionalProfiles());
    Assert.assertNotNull(conf.toString());
    Assert.assertEquals("", conf.getPatch());
    conf.setPatch("Patch");
    Assert.assertEquals("Patch", conf.getPatch());
    conf.setRepository("Repository");
    Assert.assertEquals("Repository", conf.getRepository());
    conf.setRepositoryName("RepositoryName");
    Assert.assertEquals("RepositoryName", conf.getRepositoryName());
    conf.setBranch("Branch");
    Assert.assertEquals("Branch", conf.getBranch());
    conf.setAntArgs("AntArgs");
    Assert.assertEquals("AntArgs", conf.getAntArgs());
}
Also used : ExecutionContext(org.apache.hive.ptest.execution.context.ExecutionContext) Test(org.junit.Test) PTest(org.apache.hive.ptest.execution.PTest)

Aggregations

PTest (org.apache.hive.ptest.execution.PTest)4 ExecutionContext (org.apache.hive.ptest.execution.context.ExecutionContext)3 File (java.io.File)2 TestStartRequest (org.apache.hive.ptest.api.request.TestStartRequest)2 LocalCommandFactory (org.apache.hive.ptest.execution.LocalCommandFactory)2 TestConfiguration (org.apache.hive.ptest.execution.conf.TestConfiguration)2 RSyncCommandExecutor (org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor)2 SSHCommandExecutor (org.apache.hive.ptest.execution.ssh.SSHCommandExecutor)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 HashSet (java.util.HashSet)1 LogDirectoryCleaner (org.apache.hive.ptest.execution.LogDirectoryCleaner)1 ExecutionContextConfiguration (org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration)1 Host (org.apache.hive.ptest.execution.conf.Host)1 CreateHostsFailedException (org.apache.hive.ptest.execution.context.CreateHostsFailedException)1 ExecutionContextProvider (org.apache.hive.ptest.execution.context.ExecutionContextProvider)1 ServiceNotAvailableException (org.apache.hive.ptest.execution.context.ServiceNotAvailableException)1