Skip to content

Commit

Permalink
fix(alibaba#12231): When inserting and updating configurations in the…
Browse files Browse the repository at this point in the history
… database, the time-related field values need to be set using the time obtained from the database's built-in time function.
  • Loading branch information
Bo-Qiu committed Jun 15, 2024
1 parent 8a66f62 commit 9392e78
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.mockito.Mockito;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -202,7 +201,7 @@ void testInsertOrUpdateBetaCasOfUpdate() {
//verify cas update to be invoked
embeddedStorageContextHolderMockedStatic.verify(
() -> EmbeddedStorageContextHolder.addSqlContext(anyString(), eq(configInfo.getContent()),
eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)), eq(betaIps), eq(srcIp), eq(srcUser), any(Timestamp.class),
eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)), eq(betaIps), eq(srcIp), eq(srcUser),
eq(appName), eq(dataId), eq(group), eq(tenant), eq(configInfo.getMd5())), times(1));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -216,7 +215,7 @@ void testInsertOrUpdateTagCasOfUpdate() {
ConfigOperateResult configOperateResult = embeddedConfigInfoTagPersistService.insertOrUpdateTagCas(configInfo, tag, srcIp, srcUser);
//verify update to be invoked
embeddedStorageContextHolderMockedStatic.verify(() -> EmbeddedStorageContextHolder.addSqlContext(anyString(), eq(content),
eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser), any(Timestamp.class), eq(appName),
eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser), eq(appName),
eq(dataId), eq(group), eq(tenant), eq(tag), eq(configInfo.getMd5())), times(1));
assertEquals(configInfoStateWrapper.getId(), configOperateResult.getId());
assertEquals(configInfoStateWrapper.getLastModified(), configOperateResult.getLastModified());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.support.TransactionTemplate;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -50,7 +49,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -257,7 +255,7 @@ void testInsertOrUpdateBetaCasOfUpdate() {
configInfo.setMd5("casMd5");
//mock cas update
when(jdbcTemplate.update(anyString(), eq(configInfo.getContent()), eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)),
eq(betaIps), eq(srcIp), eq(srcUser), any(Timestamp.class), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(betaIps), eq(srcIp), eq(srcUser), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(configInfo.getMd5()))).thenReturn(1);

ConfigOperateResult configOperateResult = externalConfigInfoBetaPersistService.insertOrUpdateBetaCas(configInfo, betaIps, srcIp,
Expand All @@ -268,7 +266,7 @@ void testInsertOrUpdateBetaCasOfUpdate() {
//verify cas update to be invoked
Mockito.verify(jdbcTemplate, times(1))
.update(anyString(), eq(configInfo.getContent()), eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)), eq(betaIps),
eq(srcIp), eq(srcUser), any(Timestamp.class), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(srcIp), eq(srcUser), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(configInfo.getMd5()));

}
Expand Down Expand Up @@ -334,7 +332,7 @@ void testInsertOrUpdateBetaCasOfException() {
configInfo.setMd5("casMd5");
// mock update throw CannotGetJdbcConnectionException
when(jdbcTemplate.update(anyString(), eq(configInfo.getContent()), eq(MD5Utils.md5Hex(content, Constants.PERSIST_ENCODE)),
eq(betaIps), eq(srcIp), eq(srcUser), any(Timestamp.class), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(betaIps), eq(srcIp), eq(srcUser), eq(appName), eq(dataId), eq(group), eq(tenant),
eq(configInfo.getMd5()))).thenThrow(new CannotGetJdbcConnectionException("mock fail"));
//execute of update& expect.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -213,13 +212,13 @@ void testInsertOrUpdateTagCasOfUpdate() {

//mock cas update return 1
Mockito.when(jdbcTemplate.update(anyString(), eq(configInfo.getContent()),
eq(MD5Utils.md5Hex(configInfo.getContent(), Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser), any(Timestamp.class),
eq(MD5Utils.md5Hex(configInfo.getContent(), Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser),
eq(appName), eq(dataId), eq(group), eq(tenant), eq(tag), eq(configInfo.getMd5()))).thenReturn(1);
ConfigOperateResult configOperateResult = externalConfigInfoTagPersistService.insertOrUpdateTagCas(configInfo, tag, srcIp, srcUser);
//verify update to be invoked
Mockito.verify(jdbcTemplate, times(1))
.update(anyString(), eq(configInfo.getContent()), eq(MD5Utils.md5Hex(configInfo.getContent(), Constants.PERSIST_ENCODE)),
eq(srcIp), eq(srcUser), any(Timestamp.class), eq(appName), eq(dataId), eq(group), eq(tenant), eq(tag),
eq(srcIp), eq(srcUser), eq(appName), eq(dataId), eq(group), eq(tenant), eq(tag),
eq(configInfo.getMd5()));
assertEquals(configInfoStateWrapper.getId(), configOperateResult.getId());
assertEquals(configInfoStateWrapper.getLastModified(), configOperateResult.getLastModified());
Expand Down Expand Up @@ -268,7 +267,7 @@ void testInsertOrUpdateTagCasOfException() {
Mockito.when(jdbcTemplate.queryForObject(anyString(), eq(new Object[] {dataId, group, tenant, tag}),
eq(CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER))).thenReturn(configInfoStateWrapper);
Mockito.when(jdbcTemplate.update(anyString(), eq(configInfo.getContent()),
eq(MD5Utils.md5Hex(configInfo.getContent(), Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser), any(Timestamp.class),
eq(MD5Utils.md5Hex(configInfo.getContent(), Constants.PERSIST_ENCODE)), eq(srcIp), eq(srcUser),
eq(appName), eq(dataId), eq(group), eq(tenant), eq(tag), eq(configInfo.getMd5())))
.thenThrow(new CannotGetJdbcConnectionException("throw exception update config tag"));
try {
Expand Down

0 comments on commit 9392e78

Please sign in to comment.