xxl-job

AdminBizTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.xxl.job.adminbiz;
  2. import com.xxl.job.core.biz.AdminBiz;
  3. import com.xxl.job.core.biz.model.RegistryParam;
  4. import com.xxl.job.core.biz.model.ReturnT;
  5. import com.xxl.job.core.enums.RegistryConfig;
  6. import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
  7. import com.xxl.rpc.remoting.invoker.call.CallType;
  8. import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
  9. import com.xxl.rpc.remoting.invoker.route.LoadBalance;
  10. import com.xxl.rpc.remoting.net.NetEnum;
  11. import com.xxl.rpc.serialize.Serializer;
  12. import org.junit.Assert;
  13. import org.junit.Test;
  14. /**
  15. * admin api test
  16. *
  17. * @author xuxueli 2017-07-28 22:14:52
  18. */
  19. public class AdminBizTest {
  20. // admin-client
  21. private static String addressUrl = "http://127.0.0.1:8080/xxl-job-admin".concat(AdminBiz.MAPPING);
  22. private static String accessToken = null;
  23. /**
  24. * registry executor
  25. *
  26. * @throws Exception
  27. */
  28. @Test
  29. public void registryTest() throws Exception {
  30. addressUrl = addressUrl.replace("http://", "");
  31. AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
  32. NetEnum.NETTY_HTTP,
  33. Serializer.SerializeEnum.HESSIAN.getSerializer(),
  34. CallType.SYNC,
  35. LoadBalance.ROUND,
  36. AdminBiz.class,
  37. null,
  38. 3000,
  39. addressUrl,
  40. accessToken,
  41. null,
  42. null).getObject();
  43. // test executor registry
  44. RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
  45. ReturnT<String> returnT = adminBiz.registry(registryParam);
  46. Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
  47. // stop invoker
  48. XxlRpcInvokerFactory.getInstance().stop();
  49. }
  50. /**
  51. * registry executor remove
  52. *
  53. * @throws Exception
  54. */
  55. @Test
  56. public void registryRemove() throws Exception {
  57. addressUrl = addressUrl.replace("http://", "");
  58. AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
  59. NetEnum.NETTY_HTTP,
  60. Serializer.SerializeEnum.HESSIAN.getSerializer(),
  61. CallType.SYNC,
  62. LoadBalance.ROUND,
  63. AdminBiz.class,
  64. null,
  65. 3000,
  66. addressUrl,
  67. accessToken,
  68. null,
  69. null).getObject();
  70. // test executor registry remove
  71. RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
  72. ReturnT<String> returnT = adminBiz.registryRemove(registryParam);
  73. Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
  74. // stop invoker
  75. XxlRpcInvokerFactory.getInstance().stop();
  76. }
  77. }