Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code quality improvement: clear the issues reported by SonarLint Plugin in some Test classes #3727

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -42,9 +43,9 @@
*
* @author zhengyangyong
*/
public class DefaultCoordinatorMetricsTest {
class DefaultCoordinatorMetricsTest {
@Test
public void test() throws IOException, TransactionException, InterruptedException {
void test() throws IOException, TransactionException, InterruptedException {
SessionHolder.init(null);
DefaultCoordinator coordinator = new DefaultCoordinator(new MockServerMessageSender());
coordinator.init();
Expand Down Expand Up @@ -72,7 +73,7 @@ public void test() throws IOException, TransactionException, InterruptedExceptio
coordinator.doGlobalCommit(commitRequest, new GlobalCommitResponse(), new RpcContext());

//we need sleep for a short while because default canBeCommittedAsync() is true
Thread.sleep(200);
TimeUnit.MILLISECONDS.sleep(200);

measurements.clear();
MetricsManager.get().getRegistry().measure().forEach(
Expand Down Expand Up @@ -105,7 +106,7 @@ public void test() throws IOException, TransactionException, InterruptedExceptio
rollbackRequest.setXid(response.getXid());
coordinator.doGlobalRollback(rollbackRequest, new GlobalRollbackResponse(), new RpcContext());

Thread.sleep(200);
TimeUnit.MILLISECONDS.sleep(200);

measurements.clear();
MetricsManager.get().getRegistry().measure().forEach(
Expand Down
Expand Up @@ -64,7 +64,7 @@
*
* @author leizhiyuan
*/
public class DefaultCoordinatorTest {
class DefaultCoordinatorTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

报错了。这个public先恢复过来吧。

private static DefaultCoordinator defaultCoordinator;

private static final String applicationId = "demo-child-app";
Expand Down Expand Up @@ -106,7 +106,7 @@ public void tearUp() throws IOException {
}

@Test
public void branchCommit() throws TransactionException {
void branchCommit() throws TransactionException {
BranchStatus result = null;
String xid = null;
GlobalSession globalSession = null;
Expand All @@ -124,10 +124,12 @@ public void branchCommit() throws TransactionException {
globalSession.end();
}



@Disabled
@ParameterizedTest
@MethodSource("xidAndBranchIdProviderForRollback")
public void branchRollback(String xid, Long branchId) {
void branchRollback(String xid, Long branchId) {
BranchStatus result = null;
GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
try {
Expand All @@ -140,14 +142,14 @@ public void branchRollback(String xid, Long branchId) {


@Test
public void test_handleRetryRollbacking() throws TransactionException, InterruptedException {
void test_handleRetryRollbacking() throws TransactionException, InterruptedException {

String xid = core.begin(applicationId, txServiceGroup, txName, 10);
Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);

Assertions.assertNotNull(branchId);

Thread.sleep(100);
TimeUnit.MILLISECONDS.sleep(100);
defaultCoordinator.timeoutCheck();
defaultCoordinator.handleRetryRollbacking();

Expand All @@ -157,7 +159,7 @@ public void test_handleRetryRollbacking() throws TransactionException, Interrupt
}

@Test
public void test_handleRetryRollbackingTimeOut() throws TransactionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
void test_handleRetryRollbackingTimeOut() throws TransactionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
String xid = core.begin(applicationId, txServiceGroup, txName, 10);
Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);

Expand All @@ -182,7 +184,7 @@ public void test_handleRetryRollbackingTimeOut() throws TransactionException, In
}

@Test
public void test_handleRetryRollbackingTimeOut_unlock() throws TransactionException, InterruptedException,
void test_handleRetryRollbackingTimeOut_unlock() throws TransactionException, InterruptedException,
NoSuchFieldException, IllegalAccessException {
String xid = core.begin(applicationId, txServiceGroup, txName, 10);
Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);
Expand All @@ -201,7 +203,7 @@ public void test_handleRetryRollbackingTimeOut_unlock() throws TransactionExcept

int lockSize = globalSession.getBranchSessions().get(0).getLockHolder().size();
try {
Assertions.assertTrue(lockSize == 0);
Assertions.assertEquals(0, lockSize);
} finally {
globalSession.closeAndClean();
ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT",
Expand Down
Expand Up @@ -38,7 +38,7 @@
/**
* @author zhangsen
*/
public class DataBaseLockManagerImplTest {
class DataBaseLockManagerImplTest {

static LockManager lockManager = null;

Expand Down Expand Up @@ -83,7 +83,7 @@ private static void prepareTable(BasicDataSource dataSource) {
}

@Test
public void acquireLock() throws TransactionException, SQLException {
void acquireLock() throws TransactionException, SQLException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:786756");
branchSession.setTransactionId(123543465);
Expand Down Expand Up @@ -125,7 +125,7 @@ public void acquireLock() throws TransactionException, SQLException {
}

@Test
public void re_acquireLock() throws TransactionException, SQLException {
void re_acquireLock() throws TransactionException, SQLException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:65867978");
branchSession.setTransactionId(123543465);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void re_acquireLock() throws TransactionException, SQLException {
}

@Test
public void unLock() throws TransactionException, SQLException {
void unLock() throws TransactionException, SQLException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:56867");
branchSession.setTransactionId(1236765);
Expand Down Expand Up @@ -219,7 +219,7 @@ public void unLock() throws TransactionException, SQLException {
}

@Test
public void isLockable() throws TransactionException, SQLException {
void isLockable() throws TransactionException, SQLException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:56877898");
branchSession.setTransactionId(245686786);
Expand Down
Expand Up @@ -35,7 +35,7 @@
/**
* @author zhangsen
*/
public class DataBaseLockStoreDAOTest {
class DataBaseLockStoreDAOTest {

static LockStoreDataBaseDAO dataBaseLockStoreDAO = null;

Expand Down Expand Up @@ -76,7 +76,7 @@ private static void prepareTable(BasicDataSource dataSource) {
}

@Test
public void test_acquireLocks() throws SQLException {
void test_acquireLocks() throws SQLException {
List<LockDO> lockDOs = new ArrayList<>();
for(int i = 0; i < 3; i++){
LockDO lock = new LockDO();
Expand Down Expand Up @@ -113,7 +113,7 @@ public void test_acquireLocks() throws SQLException {


@Test
public void test_re_acquireLocks() throws SQLException {
void test_re_acquireLocks() throws SQLException {
List<LockDO> lockDOs = new ArrayList<>();
for(int i = 0; i < 3; i++){
LockDO lock = new LockDO();
Expand Down Expand Up @@ -152,7 +152,7 @@ public void test_re_acquireLocks() throws SQLException {
}

@Test
public void tes_unLocks() throws SQLException {
void tes_unLocks() throws SQLException {
List<LockDO> lockDOs = new ArrayList<>();
for(int i = 0; i < 3; i++){
LockDO lock = new LockDO();
Expand Down Expand Up @@ -200,7 +200,7 @@ public void tes_unLocks() throws SQLException {


@Test
public void test_isLockable_can(){
void test_isLockable_can(){
List<LockDO> lockDOs = new ArrayList<>();
for(int i = 0; i < 3; i++){
LockDO lock = new LockDO();
Expand All @@ -222,7 +222,7 @@ public void test_isLockable_can(){
}

@Test
public void test_isLockable_cannot() throws SQLException {
void test_isLockable_cannot() throws SQLException {
List<LockDO> lockDOs = new ArrayList<>();
for(int i = 0; i < 3; i++){
LockDO lock = new LockDO();
Expand Down
Expand Up @@ -30,7 +30,7 @@
* @author tianming.xm @gmail.com
* @since 2019 /1/23
*/
public class BranchSessionTest {
class BranchSessionTest {

/**
* Codec test.
Expand All @@ -39,7 +39,7 @@ public class BranchSessionTest {
*/
@ParameterizedTest
@MethodSource("branchSessionProvider")
public void codecTest(BranchSession branchSession) {
void codecTest(BranchSession branchSession) {
byte[] result = branchSession.encode();
Assertions.assertNotNull(result);
BranchSession expected = new BranchSession();
Expand Down
Expand Up @@ -46,7 +46,7 @@
*
* @author zhangsen
*/
public class DataBaseSessionManagerTest {
class DataBaseSessionManagerTest {

static SessionManager sessionManager = null;

Expand Down Expand Up @@ -109,7 +109,7 @@ private static void prepareTable(BasicDataSource dataSource) {


@Test
public void test_addGlobalSession() throws TransactionException, SQLException {
void test_addGlobalSession() throws TransactionException, SQLException {
GlobalSession session = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(session.getTransactionId());
Expand Down Expand Up @@ -143,7 +143,7 @@ public void test_addGlobalSession() throws TransactionException, SQLException {


@Test
public void test_updateGlobalSessionStatus() throws TransactionException, SQLException {
void test_updateGlobalSessionStatus() throws TransactionException, SQLException {
GlobalSession session = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(session.getTransactionId());
Expand Down Expand Up @@ -180,7 +180,7 @@ public void test_updateGlobalSessionStatus() throws TransactionException, SQLExc
}

@Test
public void test_removeGlobalSession() throws Exception {
void test_removeGlobalSession() throws Exception {
GlobalSession session = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(session.getTransactionId());
Expand Down Expand Up @@ -225,7 +225,7 @@ public void test_removeGlobalSession() throws Exception {
}

@Test
public void test_findGlobalSession() throws Exception {
void test_findGlobalSession() throws Exception {
GlobalSession session = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(session.getTransactionId());
Expand Down Expand Up @@ -264,7 +264,7 @@ public void test_findGlobalSession() throws Exception {


@Test
public void test_addBranchSession() throws Exception {
void test_addBranchSession() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
Expand Down Expand Up @@ -309,7 +309,7 @@ public void test_addBranchSession() throws Exception {


@Test
public void test_updateBranchSessionStatus() throws Exception {
void test_updateBranchSessionStatus() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
Expand Down Expand Up @@ -346,7 +346,7 @@ public void test_updateBranchSessionStatus() throws Exception {
Assertions.assertTrue(true);
Assertions.assertEquals(rs.getInt("status"), BranchStatus.PhaseOne_Timeout.getCode());
}else{
Assertions.assertTrue(false);
Assertions.fail();
}

conn.createStatement().execute(delSql);
Expand All @@ -358,7 +358,7 @@ public void test_updateBranchSessionStatus() throws Exception {
}

@Test
public void test_removeBranchSession() throws Exception {
void test_removeBranchSession() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
Expand Down Expand Up @@ -406,7 +406,7 @@ public void test_removeBranchSession() throws Exception {


@Test
public void test_allSessions() throws Exception {
void test_allSessions() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test",
"test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
Expand Down Expand Up @@ -474,7 +474,7 @@ public void test_allSessions() throws Exception {
}

@Test
public void test_findGlobalSessions() throws TransactionException, SQLException {
void test_findGlobalSessions() throws TransactionException, SQLException {
String xid = null;
{
GlobalSession globalSession = GlobalSession.createGlobalSession("test",
Expand Down Expand Up @@ -557,7 +557,7 @@ public void test_findGlobalSessions() throws TransactionException, SQLException
}

@Test
public void test_transactionNameGreaterDbSize() throws Exception {
void test_transactionNameGreaterDbSize() throws Exception {

int transactionNameColumnSize = logStoreDataBaseDAO.getTransactionNameColumnSize();
StringBuilder sb = new StringBuilder("test");
Expand Down
Expand Up @@ -25,7 +25,7 @@
/**
* @author: will
*/
public class AbstractDataSourceProviderTest {
class AbstractDataSourceProviderTest {

private final String dbcpDatasourceType = "dbcp";

Expand All @@ -34,19 +34,19 @@ public class AbstractDataSourceProviderTest {
private final String hikariDatasourceType = "hikari";

@Test
public void testDbcpDataSourceProvider() {
void testDbcpDataSourceProvider() {
DataSource dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, dbcpDatasourceType).provide();
Assertions.assertNotNull(dataSource);
}

@Test
public void testDruidDataSourceProvider() {
void testDruidDataSourceProvider() {
DataSource dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, druidDatasourceType).provide();
Assertions.assertNotNull(dataSource);
}

@Test
public void testHikariDataSourceProvider() {
void testHikariDataSourceProvider() {
DataSource dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, hikariDatasourceType).provide();
Assertions.assertNotNull(dataSource);
}
Expand Down