Search in sources :

Example 16 with ConfigFileMetadata

use of com.tencent.polaris.configuration.api.core.ConfigFileMetadata in project polaris-java by polarismesh.

the class RemoteConfigFileRepoTest method testPullSuccess.

@Test
public void testPullSuccess() {
    ConfigFileMetadata configFileMetadata = ConfigFileTestUtils.assembleDefaultConfigFileMeta();
    ConfigFile configFile = new ConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName);
    String content = "hello world";
    long version = 100;
    configFile.setContent(content);
    configFile.setVersion(version);
    ConfigFileResponse configFileResponse = new ConfigFileResponse(ServerCodes.EXECUTE_SUCCESS, "", configFile);
    when(configFileConnector.getConfigFile(any())).thenReturn(configFileResponse);
    RemoteConfigFileRepo remoteConfigFileRepo = new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileConnector, configFileMetadata);
    verify(configFileConnector).getConfigFile(any());
    verify(configFileLongPollingService).addConfigFile(remoteConfigFileRepo);
    Assert.assertEquals(content, remoteConfigFileRepo.getContent());
    Assert.assertEquals(version, remoteConfigFileRepo.getConfigFileVersion());
}
Also used : ConfigFileResponse(com.tencent.polaris.api.plugin.configuration.ConfigFileResponse) ConfigFile(com.tencent.polaris.api.plugin.configuration.ConfigFile) ConfigFileMetadata(com.tencent.polaris.configuration.api.core.ConfigFileMetadata) Test(org.junit.Test)

Example 17 with ConfigFileMetadata

use of com.tencent.polaris.configuration.api.core.ConfigFileMetadata in project polaris-java by polarismesh.

the class RemoteConfigFileRepoTest method testPullWithRetryException.

@Test
public void testPullWithRetryException() {
    ConfigFileMetadata configFileMetadata = ConfigFileTestUtils.assembleDefaultConfigFileMeta();
    when(configFileConnector.getConfigFile(any())).thenThrow(new RetriableException(ErrorCode.API_TIMEOUT, ""));
    RemoteConfigFileRepo remoteConfigFileRepo = new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileConnector, configFileMetadata);
    // 重试三次
    verify(configFileConnector, times(3)).getConfigFile(any());
    verify(configFileLongPollingService).addConfigFile(remoteConfigFileRepo);
    Assert.assertNull(remoteConfigFileRepo.getContent());
    Assert.assertEquals(0, remoteConfigFileRepo.getConfigFileVersion());
}
Also used : ConfigFileMetadata(com.tencent.polaris.configuration.api.core.ConfigFileMetadata) RetriableException(com.tencent.polaris.api.exception.RetriableException) Test(org.junit.Test)

Aggregations

ConfigFileMetadata (com.tencent.polaris.configuration.api.core.ConfigFileMetadata)17 Test (org.junit.Test)12 ConfigFileResponse (com.tencent.polaris.api.plugin.configuration.ConfigFileResponse)8 ConfigFile (com.tencent.polaris.api.plugin.configuration.ConfigFile)7 RetriableException (com.tencent.polaris.api.exception.RetriableException)4 DefaultConfigFileMetadata (com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata)3 ErrorCode (com.tencent.polaris.api.exception.ErrorCode)2 ServerCodes (com.tencent.polaris.api.exception.ServerCodes)2 ConfigFileConnector (com.tencent.polaris.api.plugin.configuration.ConfigFileConnector)2 SDKContext (com.tencent.polaris.client.api.SDKContext)2 ConfigFileTestUtils (com.tencent.polaris.configuration.client.ConfigFileTestUtils)2 TimeUnit (java.util.concurrent.TimeUnit)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)2 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 Mock (org.mockito.Mock)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2