use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.
the class ConfigDerbyImport_CITCase method testDerbyImport.
@Test()
public void testDerbyImport() throws Throwable {
DatabaseOperate operate = context.getBean(DatabaseOperate.class);
File file = DiskUtils.createTmpFile("derby_import" + System.currentTimeMillis(), ".tmp");
DiskUtils.writeFile(file, ByteUtils.toBytes(SQL_SCRIPT_CONTEXT), false);
try {
List<Integer> ids = operate.queryMany("SELECT id FROM config_info", new Object[] {}, Integer.class);
for (Integer each : ids) {
System.out.println("current id in table config_info contain: " + each);
}
CompletableFuture<RestResult<String>> future = operate.dataImport(file);
RestResult<String> result = future.join();
System.out.println(result);
Assert.assertTrue(result.ok());
final String queryDataId = "people";
final String queryGroup = "DEFAULT_GROUP";
final String expectContent = "people.enable=true";
PersistService persistService = context.getBean(PersistService.class);
ConfigInfo configInfo = persistService.findConfigInfo(queryDataId, queryGroup, "");
System.out.println(configInfo);
Assert.assertNotNull(configInfo);
Assert.assertEquals(queryDataId, configInfo.getDataId());
Assert.assertEquals(queryGroup, configInfo.getGroup());
Assert.assertEquals("", configInfo.getTenant());
Assert.assertEquals(expectContent, configInfo.getContent());
} finally {
DiskUtils.deleteQuietly(file);
}
}
use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.
the class ConfigDerbyRaft_DITCase method test_b_publish_config.
@Test
public void test_b_publish_config() throws Exception {
ThreadUtils.sleep(5000);
boolean result = iconfig8.publishConfig("raft_test", "cluster_test_2", "this.is.raft_cluster=lessspring_8");
Assert.assertTrue(result);
ThreadUtils.sleep(5000);
ConfigurableApplicationContext context7 = applications.get("8847");
ConfigurableApplicationContext context8 = applications.get("8848");
ConfigurableApplicationContext context9 = applications.get("8849");
PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
String s7 = operate7.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8" });
}
use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.
the class ConfigDerbyRaft_DITCase method test_d_modify_config.
@Test
public void test_d_modify_config() throws Exception {
boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7_it_is_for_modify");
Assert.assertTrue(result);
ThreadUtils.sleep(5000);
ConfigurableApplicationContext context7 = applications.get("8847");
ConfigurableApplicationContext context8 = applications.get("8848");
ConfigurableApplicationContext context9 = applications.get("8849");
PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
String s7 = operate7.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_7_it_is_for_modify", "this.is.raft_cluster=lessspring_7_it_is_for_modify", "this.is.raft_cluster=lessspring_7_it_is_for_modify" });
}
use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.
the class ConfigDerbyRaft_DITCase method test_a_publish_config.
@Test
public void test_a_publish_config() throws Exception {
boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
Assert.assertTrue(result);
ThreadUtils.sleep(5000);
ConfigurableApplicationContext context7 = applications.get("8847");
ConfigurableApplicationContext context8 = applications.get("8848");
ConfigurableApplicationContext context9 = applications.get("8849");
PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
String s7 = operate7.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7" });
}
use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.
the class DumpProcessor method process.
@Override
public boolean process(NacosTask task) {
final PersistService persistService = dumpService.getPersistService();
DumpTask dumpTask = (DumpTask) task;
String[] pair = GroupKey2.parseKey(dumpTask.getGroupKey());
String dataId = pair[0];
String group = pair[1];
String tenant = pair[2];
long lastModified = dumpTask.getLastModified();
String handleIp = dumpTask.getHandleIp();
boolean isBeta = dumpTask.isBeta();
String tag = dumpTask.getTag();
ConfigDumpEvent.ConfigDumpEventBuilder build = ConfigDumpEvent.builder().namespaceId(tenant).dataId(dataId).group(group).isBeta(isBeta).tag(tag).lastModifiedTs(lastModified).handleIp(handleIp);
if (isBeta) {
// if publish beta, then dump config, update beta cache
ConfigInfo4Beta cf = persistService.findConfigInfo4Beta(dataId, group, tenant);
build.remove(Objects.isNull(cf));
build.betaIps(Objects.isNull(cf) ? null : cf.getBetaIps());
build.content(Objects.isNull(cf) ? null : cf.getContent());
build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
return DumpConfigHandler.configDump(build.build());
}
if (StringUtils.isBlank(tag)) {
ConfigInfo cf = persistService.findConfigInfo(dataId, group, tenant);
build.remove(Objects.isNull(cf));
build.content(Objects.isNull(cf) ? null : cf.getContent());
build.type(Objects.isNull(cf) ? null : cf.getType());
build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
} else {
ConfigInfo4Tag cf = persistService.findConfigInfo4Tag(dataId, group, tenant, tag);
build.remove(Objects.isNull(cf));
build.content(Objects.isNull(cf) ? null : cf.getContent());
}
return DumpConfigHandler.configDump(build.build());
}
Aggregations