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

fix: sonar fix #692

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class PriorityLoopArrayQueueTest {
AtomicInteger productCounter = new AtomicInteger();
AtomicInteger consumerCounter = new AtomicInteger();
Random rand = new Random();

@Test
public void testConcurrentPutAndTake() throws Exception {
Expand All @@ -39,7 +40,7 @@ public void testConcurrentPutAndTake() throws Exception {
// 获取开始时间的毫秒数
long startTime = System.currentTimeMillis();
// 三分钟的毫秒数
long threeMinutesInMillis = 1 * 30 * 1000;
long threeMinutesInMillis = 30 * 1000L;
int genLen = 5;
int getLen = 7;
final CountDownLatch latch = new CountDownLatch(genLen + getLen + 1);
Expand All @@ -48,7 +49,7 @@ public void testConcurrentPutAndTake() throws Exception {
final int id = i;
new Thread(() -> {
try{
Thread.sleep(100 * id);
Thread.sleep(100L * id);
latch.countDown();
latch.await();
} catch (InterruptedException e){
Expand Down Expand Up @@ -193,7 +194,6 @@ private void printEvent(String opt, SchedulerEvent event) {
System.out.println("【" + Thread.currentThread().getName() + "】" + opt + ":" + event.getId() + ", priority: " + event.getPriority() + ", index: " + event.getIndex());
}
private int getRandom(int bound){
Random rand = new Random();
int res = rand.nextInt(bound);
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public boolean equals(Object obj) {
}
return false;
}

@Override
public int hashCode() {
return getNode().getServiceInstance().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public YarnQueueInfo getResources(
realQueueName = queueName;
JsonNode childQueues = getChildQueuesOfCapacity(schedulerInfo);
Optional<JsonNode> queue = getQueueOfCapacity(childQueues, realQueueName);
if (queue == null || !queue.isPresent()) {
if (!queue.isPresent()) {
logger.debug(
"cannot find any information about queue " + queueName + ", response: " + resp);
throw new RMWarnException(
Expand All @@ -241,7 +241,7 @@ public YarnQueueInfo getResources(
JsonNode childQueues = getChildQueues(schedulerInfo.path("rootQueue"));
queue = getQueue(childQueues, realQueueName);
}
if (queue == null || !queue.isPresent()) {
if (!queue.isPresent()) {
logger.debug(
"cannot find any information about queue " + queueName + ", response: " + resp);
throw new RMWarnException(
Expand Down Expand Up @@ -414,7 +414,7 @@ public String getAndUpdateActiveRmWebAddress(ExternalResourceProvider provider)
String haAddress = (String) provider.getConfigMap().get("rmWebAddress");
String activeAddress = rmAddressMap.get(haAddress);
if (StringUtils.isBlank(activeAddress)) {
synchronized (haAddress.intern()) {
synchronized (haAddress.intern()) { // NOSONAR
if (StringUtils.isBlank(activeAddress)) {
if (logger.isDebugEnabled()) {
logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public boolean equals(Object other) {
}
}

@Override
public int hashCode() {
return getClusterName().hashCode() + getClusterType().hashCode();
}

@Override
public void valueCheck(String stringValue) throws LabelErrorException {
if (!StringUtils.isEmpty(stringValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.linkis.manager.common.exception.ResourceWarnException;

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.AbstractMap;
import java.util.HashMap;
Expand Down Expand Up @@ -292,11 +293,11 @@ public boolean equalsTo(Resource r) {
if (v instanceof Integer && rsV instanceof Integer) {
return (int) v != (int) rsV;
} else if (v instanceof Double && rsV instanceof Double) {
return (double) v != (double) rsV;
return !BigDecimal.valueOf((double) v).equals(BigDecimal.valueOf((double) rsV));
} else if (v instanceof Long && rsV instanceof Long) {
return (long) v != (long) rsV;
} else if (v instanceof Float && rsV instanceof Float) {
return (float) v != (float) rsV;
return !BigDecimal.valueOf((float) v).equals(BigDecimal.valueOf((float) rsV));
} else if (v instanceof Short && rsV instanceof Short) {
return (short) v != (short) rsV;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public final class FileUtils {

public static final String PACKAGE_SEPARATOR = ".";

public static final Random rnd = new Random();

// ------------------------------------------------------------------------

public static void writeCompletely(WritableByteChannel channel, ByteBuffer src)
Expand Down Expand Up @@ -91,7 +93,6 @@ public static Path[] listDirectory(Path directory) throws IOException {
* @return the generated random filename with the given prefix
*/
public static String getRandomFilename(final String prefix) {
final Random rnd = new Random();
final StringBuilder stringBuilder = new StringBuilder(prefix);

for (int i = 0; i < RANDOM_FILE_NAME_LENGTH; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static KubernetesClient getKubernetesClient(
kubeConfigFile,
k8sMasterUrl);

if (StringUtils.isBlank(kubeConfigFile) && StringUtils.isBlank(kubeConfigFile)) {
if (StringUtils.isBlank(kubeConfigFile)) {
throw new KubernetesClientException(
"Both kubeConfigFile and k8sMasterUrl are empty. Initializing KubernetesClient failed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void jdbcUnfinishedAlertScan() {
long id =
Optional.ofNullable(CacheUtils.cacheBuilder.getIfPresent("jdbcUnfinishedAlertScan"))
.orElse(MonitorConfig.JOB_HISTORY_TIME_EXCEED.getValue());
long intervalMs = 7200 * 1000;
long intervalMs = 7200 * 1000L;
long maxIntervalMs = Constants.ERRORCODE_MAX_INTERVALS_SECONDS() * 1000;
long endTime = System.currentTimeMillis();
long startTime = endTime - intervalMs;
Expand All @@ -254,7 +254,7 @@ public void jdbcUnfinishedKillScan() {
long id =
Optional.ofNullable(CacheUtils.cacheBuilder.getIfPresent("jdbcUnfinishedKillScan"))
.orElse(MonitorConfig.JOB_HISTORY_TIME_EXCEED.getValue());
long intervalMs = 7200 * 1000;
long intervalMs = 7200 * 1000L;
long maxIntervalMs = Constants.ERRORCODE_MAX_INTERVALS_SECONDS() * 1000;
long endTime = System.currentTimeMillis();
long startTime = endTime - intervalMs;
Expand Down
Loading