|
| 1 | +package org.tron.core.config.args; |
| 2 | + |
| 3 | +import org.junit.After; |
| 4 | +import org.junit.Assert; |
| 5 | +import org.junit.Before; |
| 6 | +import org.junit.Test; |
| 7 | +import org.tron.common.application.TronApplicationContext; |
| 8 | +import org.tron.common.parameter.CommonParameter; |
| 9 | +import org.tron.common.utils.FileUtil; |
| 10 | +import org.tron.common.utils.ReflectUtils; |
| 11 | +import org.tron.core.Constant; |
| 12 | +import org.tron.core.config.DefaultConfig; |
| 13 | +import org.tron.core.net.TronNetService; |
| 14 | +import org.tron.p2p.P2pConfig; |
| 15 | + |
| 16 | +import java.io.File; |
| 17 | + |
| 18 | +public class DynamicArgsTest { |
| 19 | + protected TronApplicationContext context; |
| 20 | + private DynamicArgs dynamicArgs; |
| 21 | + private String dbPath = "output-dynamic-config-test"; |
| 22 | + |
| 23 | + @Before |
| 24 | + public void init() { |
| 25 | + Args.setParam(new String[]{"--output-directory", dbPath}, |
| 26 | + Constant.TEST_CONF); |
| 27 | + context = new TronApplicationContext(DefaultConfig.class); |
| 28 | + dynamicArgs = context.getBean(DynamicArgs.class); |
| 29 | + |
| 30 | + } |
| 31 | + |
| 32 | + @After |
| 33 | + public void destroy() { |
| 34 | + Args.clearParam(); |
| 35 | + context.destroy(); |
| 36 | + FileUtil.deleteDir(new File(dbPath)); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void get() { |
| 41 | + CommonParameter parameter = Args.getInstance(); |
| 42 | + Assert.assertFalse(parameter.isDynamicConfigEnable()); |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void start() { |
| 48 | + dynamicArgs.start(); |
| 49 | + TronNetService tronNetService = context.getBean(TronNetService.class); |
| 50 | + ReflectUtils.setFieldValue(tronNetService, "p2pConfig", new P2pConfig()); |
| 51 | + dynamicArgs.reload(); |
| 52 | + dynamicArgs.close(); |
| 53 | + Assert.assertTrue((boolean)ReflectUtils.getFieldObject(dynamicArgs, "shutdown")); |
| 54 | + } |
| 55 | +} |
0 commit comments