[fix] fix the SystemMetrics's compare logic (no effect yet)

This commit is contained in:
朱八 2020-08-03 00:25:06 +08:00
parent 32a9f446b0
commit 80faffb2db
2 changed files with 19 additions and 1 deletions

View File

@ -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();
}
/**

View File

@ -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);
}
}