PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/gmonitor/gmonitor-core/src/test/java/com/zdingke/gmonitor/model/test/TestModelClass.java

https://gitlab.com/zhengdingke/gmonitor
Java | 61 lines | 50 code | 11 blank | 0 comment | 0 complexity | 3c39bf49ffa4805409e81fe008c6cf5d MD5 | raw file
  1. package com.zdingke.gmonitor.model.test;
  2. import java.io.File;
  3. import java.util.Arrays;
  4. import java.util.Date;
  5. import org.junit.Test;
  6. import com.alibaba.fastjson.JSON;
  7. import com.zdingke.gmonitor.common.StringFileTransUtil;
  8. import com.zdingke.gmonitor.model.ComponentInfo;
  9. import com.zdingke.gmonitor.model.JVMInfo;
  10. import com.zdingke.gmonitor.model.MetricInfo;
  11. import com.zdingke.gmonitor.model.ModuleInfo;
  12. import com.zdingke.gmonitor.model.RequestContent;
  13. public class TestModelClass {
  14. @Test
  15. public void generateComponentJsonFile() {
  16. MetricInfo minfo = new MetricInfo("memory", Arrays.asList(new String[]{"memory1","memory2"}),"memory");
  17. ModuleInfo moinfo = new ModuleInfo("nimbus", "nb", "1.1.1.1", "111", Arrays.asList(minfo));
  18. ComponentInfo cinfo = new ComponentInfo("storm", Arrays.asList(moinfo), "1.1.1.1:1111");
  19. StringFileTransUtil.string2File(JSON.toJSONString(cinfo, true), new File(TestModelClass.class.getResource("/").getFile().toString() + "storm.json"));
  20. }
  21. @Test
  22. public void generateJvmJosnFile(){
  23. MetricInfo minfo = new MetricInfo("memory", Arrays.asList(new String[]{"memory1","memory2"}),"memory");
  24. JVMInfo jinfo = new JVMInfo();
  25. jinfo.setMetrics(Arrays.asList(minfo));
  26. StringFileTransUtil.string2File(JSON.toJSONString(jinfo, true), new File(TestModelClass.class.getResource("/").getFile().toString() + "jvm.json"));
  27. }
  28. @Test
  29. public void combineJvm() {
  30. String jvm = StringFileTransUtil.file2String(new File(TestModelClass.class.getResource("/").getFile().toString() + "jvm.json"), "GBK");
  31. JVMInfo jinfo = JSON.parseObject(jvm, JVMInfo.class);
  32. jinfo.getMetrics().stream().forEach(m -> System.out.println(m.toString()));
  33. }
  34. @Test
  35. public void replaceName() {
  36. String jvm = StringFileTransUtil.file2String(new File(TestModelClass.class.getResource("/").getFile().toString() + "jvm.json"), "GBK");
  37. System.out.println(jvm);
  38. System.out.println(jvm.replace("${name}", "nimbus"));
  39. }
  40. @Test
  41. public void testRequestContentToString() {
  42. RequestContent rc = new RequestContent("problem", "127.0.0.1", "CHECKGANGLIA CRITICAL: load_one is 3.56");
  43. System.out.println(rc.toString());
  44. }
  45. @Test
  46. public void testRequestContentDataTransform() {
  47. Date date1 = new Date("Mon Nov 28 18:01:52 CST 2016");
  48. System.out.println(date1.toLocaleString());
  49. }
  50. }