mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[fix] fix the SystemMetrics's compare logic (no effect yet)
This commit is contained in:
parent
32a9f446b0
commit
80faffb2db
@ -34,7 +34,8 @@ public class SystemMetrics implements OmsSerializable, Comparable<SystemMetrics>
|
||||
|
||||
@Override
|
||||
public int compareTo(SystemMetrics that) {
|
||||
return this.calculateScore() - that.calculateScore();
|
||||
// 降序排列
|
||||
return that.calculateScore() - this.calculateScore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,11 +4,14 @@ import com.github.kfcfans.powerjob.common.model.SystemMetrics;
|
||||
import com.github.kfcfans.powerjob.common.utils.JsonUtils;
|
||||
import com.github.kfcfans.powerjob.worker.common.utils.SystemInfoUtils;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试监控指标
|
||||
@ -58,4 +61,18 @@ public class MonitorTest {
|
||||
SystemMetrics systemMetrics = SystemInfoUtils.getSystemMetrics();
|
||||
System.out.println(JsonUtils.toJSONString(systemMetrics));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortMetrics() {
|
||||
SystemMetrics high = new SystemMetrics();
|
||||
high.setScore(100);
|
||||
SystemMetrics low = new SystemMetrics();
|
||||
low.setScore(1);
|
||||
List<SystemMetrics> list = Lists.newArrayList(high, low);
|
||||
list.sort((o1, o2) -> o2.calculateScore() - o1.calculateScore());
|
||||
System.out.println(list);
|
||||
|
||||
Collections.sort(list);
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user