Multithreaded Test Case Execution and Database Standards

The article shares practical experiences on running test cases concurrently using Java multithreading and a custom thread pool, and outlines MySQL database naming, null handling, and schema design guidelines, including full code examples for the case runner and thread pool implementation.

FunTester
FunTester
FunTester
Multithreaded Test Case Execution and Database Standards

Recently I have been busy debugging, realizing that after deployment there are many more issues; this is my first experience from requirement to production, and I share two insights: multithreaded test case execution and database standards.

Multithreaded Test Case Execution

Batch running test cases with multithreading and aggregating results for front‑end display significantly improves performance; in my rough test 40 interface test cases finish in as little as 700 ms, essentially invisible to users.

The implementation involves handling associated test users and multithread locks, as described in my previous article My Development Diary (Part 3) .

package com.okay.family.common;

import com.okay.family.common.basedata.OkayConstant;
import com.okay.family.common.bean.testcase.CaseRunRecord;
import com.okay.family.common.bean.testcase.request.CaseDataBean;
import com.okay.family.common.enums.RunResult;
import com.okay.family.utils.RunCaseUtil;

import java.util.concurrent.CountDownLatch;

public class CaseRunThread implements Runnable {

    CaseDataBean bean;
    CaseRunRecord record;
    CountDownLatch countDownLatch;

    public CaseRunRecord getRecord() {
        return record;
    }

    private CaseRunThread() {

    }

    public CaseRunThread(CaseDataBean bean, CountDownLatch countDownLatch, int runId) {
        this.bean = bean;
        this.countDownLatch = countDownLatch;
        this.record = new CaseRunRecord();
        record.setRunId(runId);
        record.setUid(bean.getUid());
        record.setParams(bean.getParams());
        record.setCaseId(bean.getId());
        record.setMark(OkayConstant.RUN_MARK.getAndIncrement());
        bean.getHeaders().put(OkayConstant.MARK_HEADER, record.getMark());
        record.setHeaders(bean.getHeaders());
    }

    @Override
    public void run() {
        try {
            RunCaseUtil.run(bean, record);
        } catch (Exception e) {
            record.setResult(RunResult.UNRUN.getCode());
        } finally {
            countDownLatch.countDown();
        }
    }
}

The thread pool implementation is straightforward; parameters are still being tuned due to limited hardware resources.

package com.okay.family.common;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class OkayThreadPool {

    private static ThreadPoolExecutor executor = createPool();

    public static void addSyncWork(Runnable runnable) {
        executor.execute(runnable);
    }

    private static ThreadPoolExecutor createPool() {
        return new ThreadPoolExecutor(5, 50, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(1000));
    }
}

Database Standards

Using MySQL, I discovered many conventions: prohibited keywords, naming and comment rules, field design, unified encoding, auto‑increment IDs, and the restriction that no field may be null, which caused numerous bugs.

Below are some of my SQL statements for testing, including table creation and insertion examples.

CREATE TABLE `qa_case_available_status` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
  `name` varchar(8) NOT NULL COMMENT '名称',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试用例可用状态对照表-QA-FunTester-20200709';

INSERT INTO `qa_case_available_status` (id,`name`) VALUES (1, '可用');
INSERT INTO `qa_case_available_status` (id,`name`) VALUES (2, '不可用');

CREATE TABLE `qa_case_collection` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
  `uid` int(10) NOT NULL COMMENT '创建者ID',
  `envId` int(10) NOT NULL COMMENT '环境ID',
  `name` varchar(64) NOT NULL DEFAULT '' COMMENT '用例集名称',
  `pub` int(10) NOT NULL DEFAULT '0' COMMENT '共享状态',
  `editor` int(10) NOT NULL COMMENT '最后编辑者ID',
  `state` int(10) NOT NULL DEFAULT '1' COMMENT '最后运行状态',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_name` (`envId`, `name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='测试用例集-QA-FunTester-20200709';

Debugging delayed two days, testing proceeds smoothly; tomorrow begins formal testing, with me handling API testing and a colleague handling Web testing before launch.

Follow the FunTester public account for more original articles; please do not repost without permission.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javasqltestingThreadPoolMySQLmultithreadingDatabase design
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.