未验证 提交 6ecc95a3 编写于 作者: C CalvinKirs 提交者: GitHub

[FIX_BUG][*] fix some bugs from sonar analysis (#3322)

* [FIX_BUG][*] fix some bugs from sonar analysis

* remove invalid single test

* code smell

* remove exception catches that never happen

* delete invalid exception catch

* remove excess locks

* fix e2e test error

* recovery related exception removal
上级 27b296c4
......@@ -149,6 +149,7 @@ public class ZooKeeperState {
return sendThread.ret;
} catch (InterruptedException e) {
logger.error("send " + cmd + " to server " + host + ":" + port + " failed!", e);
Thread.currentThread().interrupt();
}
return "";
}
......
......@@ -74,7 +74,8 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT,result.getCode().intValue());
assert result != null;
Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
......
......@@ -78,7 +78,7 @@ public abstract class AbstractShell {
/**
* If or not script finished executing
*/
private volatile AtomicBoolean completed;
private AtomicBoolean completed;
public AbstractShell() {
this(0L);
......@@ -202,7 +202,7 @@ public abstract class AbstractShell {
} catch (InterruptedException ie) {
logger.warn("Interrupted while reading the error and in stream", ie);
}
completed.set(true);
completed.compareAndSet(false,true);
//the timeout thread handling
//taken care in finally block
if (exitCode != 0 || errMsg.length() > 0) {
......
......@@ -231,6 +231,8 @@ public class ThreadUtils {
public static void sleep(final long millis) {
try {
Thread.sleep(millis);
} catch (final InterruptedException ignore) {}
} catch (final InterruptedException ignore) {
Thread.currentThread().interrupt();
}
}
}
......@@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.common.utils;
import org.apache.dolphinscheduler.common.Constants;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
......@@ -26,6 +27,5 @@ public class PropertyUtilsTest {
@Test
public void getString() {
assertNotNull(PropertyUtils.getString(Constants.FS_DEFAULTFS));
assertNotNull(PropertyUtils.getInt("spring.redis.port"));
}
}
\ No newline at end of file
......@@ -63,7 +63,6 @@ public class AccessTokenMapperTest {
Integer userId = 1;
AccessToken accessToken = createAccessToken(userId);
assertNotNull(accessToken.getId());
assertThat(accessToken.getId(), greaterThan(0));
}
......
......@@ -54,7 +54,6 @@ public class AlertMapperTest {
@Test
public void testInsert(){
Alert expectedAlert = createAlert();
assertNotNull(expectedAlert.getId());
assertThat(expectedAlert.getId(), greaterThan(0));
}
......
......@@ -62,7 +62,6 @@ public class CommandMapperTest {
@Test
public void testInsert(){
Command command = createCommand();
assertNotNull(command.getId());
assertThat(command.getId(),greaterThan(0));
}
......
......@@ -71,7 +71,6 @@ public class DataSourceMapperTest {
@Test
public void testInsert(){
DataSource dataSource = createDataSource();
assertNotNull(dataSource.getId());
assertThat(dataSource.getId(), greaterThan(0));
}
......
......@@ -132,7 +132,7 @@ public class ProcessInstanceMapperTest {
processInstanceMapper.updateById(processInstance);
ProcessInstance processInstance1 = processInstanceMapper.queryDetailById(processInstance.getId());
Assert.assertNotEquals(processInstance1, 50);
Assert.assertNotNull(processInstance1);
processInstanceMapper.deleteById(processInstance.getId());
}
......
......@@ -89,6 +89,7 @@ public class TaskResponseService {
eventQueue.put(taskResponseEvent);
} catch (InterruptedException e) {
logger.error("put task : {} error :{}", taskResponseEvent,e);
Thread.currentThread().interrupt();
}
}
......
......@@ -1026,6 +1026,7 @@ public class MasterExecThread implements Runnable {
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
} catch (InterruptedException e) {
logger.error(e.getMessage(),e);
Thread.currentThread().interrupt();
}
updateProcessInstanceState();
}
......
......@@ -97,7 +97,7 @@ public class MasterSchedulerService extends Thread {
}
@Override
public void start(){
public synchronized void start(){
super.setName("MasterSchedulerService");
super.start();
}
......@@ -107,7 +107,9 @@ public class MasterSchedulerService extends Thread {
boolean terminated = false;
try {
terminated = masterExecService.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException ignore) {}
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
if(!terminated){
logger.warn("masterExecService shutdown without terminated, increase await time");
}
......
......@@ -100,6 +100,7 @@ public class LogPromise {
try {
latch.await(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
PROMISES.remove(opaque);
return this.result;
......
......@@ -83,6 +83,7 @@ public class ZookeeperCachedOperator extends ZookeeperOperator {
try {
Thread.sleep(500);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
super.close();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册