Search in sources :

Example 1 with TestBatch

use of org.apache.hive.ptest.execution.conf.TestBatch in project hive by apache.

the class ExecutionPhase method execute.

@Override
public void execute() throws Throwable {
    long start = System.currentTimeMillis();
    List<TestBatch> testBatches = Lists.newArrayList();
    for (TestBatch batch : testBatchSupplier.get()) {
        testBatches.add(batch);
        if (batch.isParallel()) {
            parallelWorkQueue.add(batch);
        } else {
            isolatedWorkQueue.add(batch);
        }
    }
    logger.info("ParallelWorkQueueSize={}, IsolatedWorkQueueSize={}", parallelWorkQueue.size(), isolatedWorkQueue.size());
    if (logger.isDebugEnabled()) {
        for (TestBatch testBatch : parallelWorkQueue) {
            logger.debug("PBatch: {}", testBatch);
        }
        for (TestBatch testBatch : isolatedWorkQueue) {
            logger.debug("IBatch: {}", testBatch);
        }
    }
    try {
        int expectedNumHosts = hostExecutors.size();
        initalizeHosts();
        do {
            replaceBadHosts(expectedNumHosts);
            List<ListenableFuture<Void>> results = Lists.newArrayList();
            for (HostExecutor hostExecutor : ImmutableList.copyOf(hostExecutors)) {
                results.add(hostExecutor.submitTests(parallelWorkQueue, isolatedWorkQueue, failedTestResults));
            }
            Futures.allAsList(results).get();
        } while (!(parallelWorkQueue.isEmpty() && isolatedWorkQueue.isEmpty()));
        for (TestBatch batch : testBatches) {
            File batchLogDir;
            if (failedTestResults.contains(batch)) {
                batchLogDir = new File(failedLogDir, batch.getName());
            } else {
                batchLogDir = new File(succeededLogDir, batch.getName());
            }
            JUnitReportParser parser = new JUnitReportParser(logger, batchLogDir);
            executedTests.addAll(parser.getAllExecutedTests());
            for (String failedTest : parser.getAllFailedTests()) {
                failedTests.add(failedTest + " (batchId=" + batch.getBatchId() + ")");
            }
            // if the TEST*.xml was not generated or was corrupt, let someone know
            if (parser.getTestClassesWithReportAvailable().size() < batch.getTestClasses().size()) {
                Set<String> expTestClasses = new HashSet<>(batch.getTestClasses());
                expTestClasses.removeAll(parser.getTestClassesWithReportAvailable());
                for (String testClass : expTestClasses) {
                    StringBuilder messageBuilder = new StringBuilder();
                    messageBuilder.append(testClass).append(" - did not produce a TEST-*.xml file (likely timed out)").append(" (batchId=").append(batch.getBatchId()).append(")");
                    if (batch instanceof QFileTestBatch) {
                        Collection<String> tests = ((QFileTestBatch) batch).getTests();
                        if (tests.size() != 0) {
                            messageBuilder.append("\n\t[");
                            messageBuilder.append(Joiner.on(",").join(tests));
                            messageBuilder.append("]");
                        }
                    }
                    failedTests.add(messageBuilder.toString());
                }
            }
        }
    } finally {
        long elapsed = System.currentTimeMillis() - start;
        logger.info("PERF: exec phase " + TimeUnit.MINUTES.convert(elapsed, TimeUnit.MILLISECONDS) + " minutes");
    }
}
Also used : TestBatch(org.apache.hive.ptest.execution.conf.TestBatch) QFileTestBatch(org.apache.hive.ptest.execution.conf.QFileTestBatch) QFileTestBatch(org.apache.hive.ptest.execution.conf.QFileTestBatch) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with TestBatch

use of org.apache.hive.ptest.execution.conf.TestBatch in project hive by apache.

the class TestHostExecutor method setup.

@Before
public void setup() throws Exception {
    baseDir = AbstractTestPhase.createBaseDir(getClass().getSimpleName());
    logDir = Dirs.create(new File(baseDir, "logs"));
    scratchDir = Dirs.create(new File(baseDir, "scratch"));
    succeededLogDir = Dirs.create(new File(logDir, "succeeded"));
    failedLogDir = Dirs.create(new File(logDir, "failed"));
    parallelWorkQueue = new LinkedBlockingQueue<TestBatch>();
    isolatedWorkQueue = new LinkedBlockingQueue<TestBatch>();
    failedTestResults = Sets.newHashSet();
    AtomicInteger unitTestBatchCounter = new AtomicInteger(1);
    testBatchParallel1 = new UnitTestBatch(unitTestBatchCounter, "testcase", Arrays.asList(DRIVER_PARALLEL_1), "fakeModule1", true);
    testBatchParallel2 = new UnitTestBatch(unitTestBatchCounter, "testcase", Arrays.asList(DRIVER_PARALLEL_2), "fakeModule2", true);
    testBatchIsolated1 = new UnitTestBatch(unitTestBatchCounter, "testcase", Arrays.asList(DRIVER_ISOLATED_1), "fakeModule3", false);
    testBatchIsolated2 = new UnitTestBatch(unitTestBatchCounter, "testcase", Arrays.asList(DRIVER_ISOLATED_2), "fakeModule4", false);
    executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
    localCommandFactory = new MockLocalCommandFactory(LOG);
    localCommand = mock(LocalCommand.class);
    localCommandFactory.setInstance(localCommand);
    sshCommandExecutor = spy(new MockSSHCommandExecutor(LOG));
    rsyncCommandExecutor = spy(new MockRSyncCommandExecutor(LOG));
    logger = LOG;
    templateDefaults = ImmutableMap.<String, String>builder().put("localDir", LOCAL_DIR).put("workingDir", WORKING_DIR).put("instanceName", INSTANCE_NAME).put("branch", BRANCH).put("logDir", logDir.getAbsolutePath()).put("repository", REPOSITORY).put("repositoryName", REPOSITORY_NAME).build();
    host = new Host(HOST, USER, new String[] { LOCAL_DIR }, 2);
}
Also used : UnitTestBatch(org.apache.hive.ptest.execution.conf.UnitTestBatch) UnitTestBatch(org.apache.hive.ptest.execution.conf.UnitTestBatch) TestBatch(org.apache.hive.ptest.execution.conf.TestBatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Host(org.apache.hive.ptest.execution.conf.Host) File(java.io.File) Before(org.junit.Before)

Example 3 with TestBatch

use of org.apache.hive.ptest.execution.conf.TestBatch in project hive by apache.

the class HostExecutor method executeTests.

/**
 * Executes parallel test until the parallel work queue is empty. Then
 * executes the isolated tests on the host. During each phase if a
 * AbortDroneException is thrown the drone is removed possibly
 * leaving this host with zero functioning drones. If all drones
 * are removed the host will be replaced before the next run.
 */
private void executeTests(final BlockingQueue<TestBatch> parallelWorkQueue, final BlockingQueue<TestBatch> isolatedWorkQueue, final Set<TestBatch> failedTestResults) throws Exception {
    if (mShutdown) {
        mLogger.warn("Shutting down host " + mHost.getName());
        return;
    }
    mLogger.info("Starting parallel execution on " + mHost.getName());
    List<ListenableFuture<Void>> droneResults = Lists.newArrayList();
    for (final Drone drone : ImmutableList.copyOf(mDrones)) {
        droneResults.add(mExecutor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                TestBatch batch = null;
                Stopwatch sw = Stopwatch.createUnstarted();
                try {
                    do {
                        batch = parallelWorkQueue.poll(mNumPollSeconds, TimeUnit.SECONDS);
                        if (mShutdown) {
                            mLogger.warn("Shutting down host " + mHost.getName());
                            return null;
                        }
                        if (batch != null) {
                            numParallelBatchesProcessed++;
                            sw.reset().start();
                            try {
                                if (!executeTestBatch(drone, batch, failedTestResults)) {
                                    failedTestResults.add(batch);
                                }
                            } finally {
                                sw.stop();
                                mLogger.info("Finished processing parallel batch [{}] on host {}. ElapsedTime(ms)={}", new Object[] { batch.getName(), getHost().toShortString(), sw.elapsed(TimeUnit.MILLISECONDS) });
                            }
                        }
                    } while (!mShutdown && !parallelWorkQueue.isEmpty());
                } catch (AbortDroneException ex) {
                    // return value not checked due to concurrent access
                    mDrones.remove(drone);
                    mLogger.error("Aborting drone during parallel execution", ex);
                    if (batch != null) {
                        Preconditions.checkState(parallelWorkQueue.add(batch), "Could not add batch to parallel queue " + batch);
                    }
                }
                return null;
            }
        }));
    }
    if (mShutdown) {
        mLogger.warn("Shutting down host " + mHost.getName());
        return;
    }
    Futures.allAsList(droneResults).get();
    mLogger.info("Starting isolated execution on " + mHost.getName());
    for (Drone drone : ImmutableList.copyOf(mDrones)) {
        TestBatch batch = null;
        Stopwatch sw = Stopwatch.createUnstarted();
        try {
            do {
                batch = isolatedWorkQueue.poll(mNumPollSeconds, TimeUnit.SECONDS);
                if (batch != null) {
                    numIsolatedBatchesProcessed++;
                    sw.reset().start();
                    try {
                        if (!executeTestBatch(drone, batch, failedTestResults)) {
                            failedTestResults.add(batch);
                        }
                    } finally {
                        sw.stop();
                        mLogger.info("Finished processing isolated batch [{}] on host {}. ElapsedTime(ms)={}", new Object[] { batch.getName(), getHost().toShortString(), sw.elapsed(TimeUnit.MILLISECONDS) });
                    }
                }
            } while (!mShutdown && !isolatedWorkQueue.isEmpty());
        } catch (AbortDroneException ex) {
            // return value not checked due to concurrent access
            mDrones.remove(drone);
            mLogger.error("Aborting drone during isolated execution", ex);
            if (batch != null) {
                Preconditions.checkState(isolatedWorkQueue.add(batch), "Could not add batch to isolated queue " + batch);
            }
        }
    }
}
Also used : TestBatch(org.apache.hive.ptest.execution.conf.TestBatch) Stopwatch(com.google.common.base.Stopwatch) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Callable(java.util.concurrent.Callable)

Aggregations

TestBatch (org.apache.hive.ptest.execution.conf.TestBatch)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 File (java.io.File)2 Stopwatch (com.google.common.base.Stopwatch)1 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Host (org.apache.hive.ptest.execution.conf.Host)1 QFileTestBatch (org.apache.hive.ptest.execution.conf.QFileTestBatch)1 UnitTestBatch (org.apache.hive.ptest.execution.conf.UnitTestBatch)1 Before (org.junit.Before)1