Skip to content

Commit

Permalink
【fix】修改动态配置UT失败
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbingleixue committed Jun 19, 2023
1 parent 066c5b3 commit d13de64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
import com.huawei.dynamic.config.DynamicConfiguration;
import com.huawei.dynamic.config.RefreshNotifier;

import com.huaweicloud.sermant.core.operation.OperationManager;
import com.huaweicloud.sermant.core.operation.converter.api.YamlConverter;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.service.dynamicconfig.common.DynamicConfigEvent;
import com.huaweicloud.sermant.core.service.dynamicconfig.common.DynamicConfigEventType;
import com.huaweicloud.sermant.implement.operation.converter.YamlConverterImpl;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockedStatic;
Expand All @@ -41,6 +46,14 @@ public class SpringEventPublisherTest {
@Mock
private ApplicationEventPublisher applicationEventPublisher;

private MockedStatic<OperationManager> operationManagerMockedStatic;

@Before
public void setUp() {
operationManagerMockedStatic = Mockito.mockStatic(OperationManager.class);
operationManagerMockedStatic.when(() -> OperationManager.getOperation(YamlConverter.class)).thenReturn(new YamlConverterImpl());
}

@Test
public void test() {
MockitoAnnotations.openMocks(this);
Expand All @@ -58,4 +71,9 @@ public void test() {
originConfigCenterDisableListenerTest.getListeners().clear();
}
}

@After
public void tearDown() {
operationManagerMockedStatic.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import com.huaweicloud.sermant.core.config.ConfigManager;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.entity.InstanceInfo;
import com.huaweicloud.sermant.entity.RequestCountData;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.util.Iterator;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -84,10 +86,12 @@ public void testProcessData() throws InterruptedException {
Thread.sleep(15000);
InstanceInfo info = InstanceCache.INSTANCE_MAP.get(KEY);
Assert.assertTrue(info != null && info.getCountDataList().size() > 0);
info.getCountDataList().forEach(requestCountData -> {
Iterator<RequestCountData> requestCountDataIterator = info.getCountDataList().iterator();
while (requestCountDataIterator.hasNext()) {
RequestCountData requestCountData = requestCountDataIterator.next();
Assert.assertEquals(REQ_NUM, requestCountData.getRequestNum());
Assert.assertEquals(REQ_FAIL_NUM, requestCountData.getRequestFailNum());
});
}
}

@AfterClass
Expand Down

0 comments on commit d13de64

Please sign in to comment.