Search in sources :

Example 1 with ConfigInfoBetaWrapper

use of com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper in project nacos by alibaba.

the class DumpAllBetaProcessor method process.

@Override
public boolean process(NacosTask task) {
    int rowCount = persistService.configInfoBetaCount();
    int pageCount = (int) Math.ceil(rowCount * 1.0 / PAGE_SIZE);
    int actualRowCount = 0;
    for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
        Page<ConfigInfoBetaWrapper> page = persistService.findAllConfigInfoBetaForDumpAll(pageNo, PAGE_SIZE);
        if (page != null) {
            for (ConfigInfoBetaWrapper cf : page.getPageItems()) {
                boolean result = ConfigCacheService.dumpBeta(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified(), cf.getBetaIps(), cf.getEncryptedDataKey());
                LogUtil.DUMP_LOG.info("[dump-all-beta-ok] result={}, {}, {}, length={}, md5={}", result, GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), cf.getContent().length(), cf.getMd5());
            }
            actualRowCount += page.getPageItems().size();
            DEFAULT_LOG.info("[all-dump-beta] {} / {}", actualRowCount, rowCount);
        }
    }
    return true;
}
Also used : ConfigInfoBetaWrapper(com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper)

Example 2 with ConfigInfoBetaWrapper

use of com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper in project nacos by alibaba.

the class ConfigServletInnerTest method testDoGetConfigV1.

@Test
public void testDoGetConfigV1() throws Exception {
    final MockedStatic<DiskUtil> diskUtil = Mockito.mockStatic(DiskUtil.class);
    final MockedStatic<ConfigCacheService> configCacheService = Mockito.mockStatic(ConfigCacheService.class);
    final MockedStatic<PropertyUtil> propertyUtil = Mockito.mockStatic(PropertyUtil.class);
    when(ConfigCacheService.tryReadLock(anyString())).thenReturn(1);
    // isBeta: true
    CacheItem cacheItem = new CacheItem("test");
    cacheItem.setBeta(true);
    List<String> ips4Beta = new ArrayList<>();
    ips4Beta.add("localhost");
    cacheItem.setIps4Beta(ips4Beta);
    when(ConfigCacheService.getContentCache(anyString())).thenReturn(cacheItem);
    // if direct read is true
    when(PropertyUtil.isDirectRead()).thenReturn(true);
    ConfigInfoBetaWrapper configInfoBetaWrapper = new ConfigInfoBetaWrapper();
    configInfoBetaWrapper.setDataId("test");
    configInfoBetaWrapper.setGroup("test");
    configInfoBetaWrapper.setContent("isBeta:true, direct read: true");
    when(persistService.findConfigInfo4Beta(anyString(), anyString(), anyString())).thenReturn(configInfoBetaWrapper);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("localhost:8080");
    request.addHeader(CLIENT_APPNAME_HEADER, "test");
    MockHttpServletResponse response = new MockHttpServletResponse();
    String actualValue = configServletInner.doGetConfig(request, response, "test", "test", "test", "", "true", "localhost");
    Assert.assertEquals(HttpServletResponse.SC_OK + "", actualValue);
    Assert.assertEquals("true", response.getHeader("isBeta"));
    Assert.assertEquals("isBeta:true, direct read: true", response.getContentAsString());
    // if direct read is false
    when(PropertyUtil.isDirectRead()).thenReturn(false);
    File file = tempFolder.newFile("test.txt");
    when(DiskUtil.targetBetaFile(anyString(), anyString(), anyString())).thenReturn(file);
    response = new MockHttpServletResponse();
    actualValue = configServletInner.doGetConfig(request, response, "test", "test", "test", "", "true", "localhost");
    Assert.assertEquals(HttpServletResponse.SC_OK + "", actualValue);
    Assert.assertEquals("true", response.getHeader("isBeta"));
    Assert.assertEquals("", response.getContentAsString());
    diskUtil.close();
    configCacheService.close();
    propertyUtil.close();
}
Also used : ConfigInfoBetaWrapper(com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PropertyUtil(com.alibaba.nacos.config.server.utils.PropertyUtil) DiskUtil(com.alibaba.nacos.config.server.utils.DiskUtil) CacheItem(com.alibaba.nacos.config.server.model.CacheItem) File(java.io.File) ConfigCacheService(com.alibaba.nacos.config.server.service.ConfigCacheService) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with ConfigInfoBetaWrapper

use of com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper in project nacos by alibaba.

the class ConfigControllerTest method testQueryBeta.

@Test
public void testQueryBeta() throws Exception {
    ConfigInfoBetaWrapper configInfoBetaWrapper = new ConfigInfoBetaWrapper();
    configInfoBetaWrapper.setDataId("test");
    configInfoBetaWrapper.setGroup("test");
    configInfoBetaWrapper.setContent("test");
    when(persistService.findConfigInfo4Beta("test", "test", "")).thenReturn(configInfoBetaWrapper);
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.CONFIG_CONTROLLER_PATH).param("beta", "true").param("dataId", "test").param("group", "test").param("tenant", "");
    String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
    String code = JacksonUtils.toObj(actualValue).get("code").toString();
    String data = JacksonUtils.toObj(actualValue).get("data").toString();
    ConfigInfoBetaWrapper resConfigInfoBetaWrapper = JacksonUtils.toObj(data, ConfigInfoBetaWrapper.class);
    Assert.assertEquals("200", code);
    Assert.assertEquals(configInfoBetaWrapper.getDataId(), resConfigInfoBetaWrapper.getDataId());
    Assert.assertEquals(configInfoBetaWrapper.getGroup(), resConfigInfoBetaWrapper.getGroup());
    Assert.assertEquals(configInfoBetaWrapper.getContent(), resConfigInfoBetaWrapper.getContent());
}
Also used : ConfigInfoBetaWrapper(com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ConfigInfoBetaWrapper (com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper)3 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CacheItem (com.alibaba.nacos.config.server.model.CacheItem)1 ConfigCacheService (com.alibaba.nacos.config.server.service.ConfigCacheService)1 DiskUtil (com.alibaba.nacos.config.server.utils.DiskUtil)1 PropertyUtil (com.alibaba.nacos.config.server.utils.PropertyUtil)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1