Skip to content

Commit

Permalink
Move StandaloneDatabaseOperateImpl to persistent module.
Browse files Browse the repository at this point in the history
  • Loading branch information
KomachiSion committed May 8, 2023
1 parent 5762254 commit 3d4014a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 21 deletions.
6 changes: 5 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-common</artifactId>
<artifactId>nacos-common</artifactId>ne
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-consistency</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-persistence</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.config.server.service.repository.embedded;
package com.alibaba.nacos.persistence.repository.embedded.operate;

import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.model.RestResultUtils;
Expand All @@ -23,7 +23,6 @@
import com.alibaba.nacos.persistence.configuration.condition.ConditionStandaloneEmbedStorage;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.repository.embedded.operate.BaseDatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;
import com.alibaba.nacos.sys.utils.DiskUtils;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.persistence.repository.embedded.operate;

import java.util.Objects;

public class MockConfigInfo {

private long id;

private String dataId;

private String group;

private String content;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getDataId() {
return dataId;
}

public void setDataId(String dataId) {
this.dataId = dataId;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MockConfigInfo)) {
return false;
}
MockConfigInfo that = (MockConfigInfo) o;
return id == that.id && Objects.equals(dataId, that.dataId) && Objects.equals(group, that.group) && Objects
.equals(content, that.content);
}

@Override
public int hashCode() {
return Objects.hash(id, dataId, group, content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*/

package com.alibaba.nacos.config.server.service.repository.embedded;
package com.alibaba.nacos.persistence.repository.embedded.operate;

import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;
import org.junit.Assert;
Expand Down Expand Up @@ -56,7 +55,7 @@ public class StandaloneDatabaseOperateImplTest {
private StandaloneDatabaseOperateImpl operate;

@Mock
private RowMapper<ConfigInfo> rowMapper;
private RowMapper<MockConfigInfo> rowMapper;

@Mock
private JdbcTemplate jdbcTemplate;
Expand Down Expand Up @@ -92,19 +91,19 @@ public void testQueryOne1() {
@Test
public void testQueryOne2() {
final String sql = "SELECT * FROM config_info WHERE id = ? AND data_id = ? AND group_id = ?";
ConfigInfo configInfo = new ConfigInfo();
MockConfigInfo configInfo = new MockConfigInfo();
configInfo.setId(1L);
configInfo.setDataId("test");
configInfo.setGroup("test");
Object[] args = new Object[] {configInfo.getId(), configInfo.getDataId(), configInfo.getGroup()};
when(jdbcTemplate.queryForObject(sql, args, ConfigInfo.class)).thenReturn(configInfo);
Assert.assertEquals(operate.queryOne(sql, args, ConfigInfo.class), configInfo);
when(jdbcTemplate.queryForObject(sql, args, MockConfigInfo.class)).thenReturn(configInfo);
Assert.assertEquals(operate.queryOne(sql, args, MockConfigInfo.class), configInfo);
}

@Test
public void testQueryOne3() {
final String sql = "SELECT * FROM config_info WHERE id = ? AND data_id = ? AND group_id = ?";
ConfigInfo configInfo = new ConfigInfo();
MockConfigInfo configInfo = new MockConfigInfo();
configInfo.setId(1L);
configInfo.setDataId("test");
configInfo.setGroup("test");
Expand All @@ -125,19 +124,19 @@ public void testQueryOne4() {
@Test
public void testQueryOne5() {
final String sql = "SELECT * FROM config_info WHERE id = ? AND data_id = ? AND group_id = ?";
ConfigInfo configInfo = new ConfigInfo();
MockConfigInfo configInfo = new MockConfigInfo();
configInfo.setId(1L);
configInfo.setDataId("test");
configInfo.setGroup("test");
Object[] args = new Object[] {configInfo.getId(), configInfo.getDataId(), configInfo.getGroup()};
when(tempJdbcTemplate.queryForObject(sql, args, ConfigInfo.class)).thenReturn(configInfo);
Assert.assertEquals(operate.queryOne(tempJdbcTemplate, sql, args, ConfigInfo.class), configInfo);
when(tempJdbcTemplate.queryForObject(sql, args, MockConfigInfo.class)).thenReturn(configInfo);
Assert.assertEquals(operate.queryOne(tempJdbcTemplate, sql, args, MockConfigInfo.class), configInfo);
}

@Test
public void testQueryOne6() {
final String sql = "SELECT * FROM config_info WHERE id = ? AND data_id = ? AND group_id = ?";
ConfigInfo configInfo = new ConfigInfo();
MockConfigInfo configInfo = new MockConfigInfo();
configInfo.setId(1L);
configInfo.setDataId("test");
configInfo.setGroup("test");
Expand All @@ -150,11 +149,11 @@ public void testQueryOne6() {
public void testQueryMany1() {
final String sql = "SELECT * FROM config_info WHERE id >= ? AND id <= ?";
final Object[] args = new Object[] {1, 2};
ConfigInfo configInfo1 = new ConfigInfo();
MockConfigInfo configInfo1 = new MockConfigInfo();
configInfo1.setId(1);
ConfigInfo configInfo2 = new ConfigInfo();
MockConfigInfo configInfo2 = new MockConfigInfo();
configInfo2.setId(2);
List<ConfigInfo> configInfos = new ArrayList<>();
List<MockConfigInfo> configInfos = new ArrayList<>();
configInfos.add(configInfo1);
configInfos.add(configInfo2);
when(jdbcTemplate.query(eq(sql), eq(args), any(RowMapper.class))).thenReturn(configInfos);
Expand Down Expand Up @@ -238,11 +237,11 @@ public void testQueryMany5() {
public void testQueryMany6() {
final String sql = "SELECT * FROM config_info WHERE id >= ? AND id <= ?";
final Object[] args = new Object[] {1, 2};
ConfigInfo configInfo1 = new ConfigInfo();
MockConfigInfo configInfo1 = new MockConfigInfo();
configInfo1.setId(1);
ConfigInfo configInfo2 = new ConfigInfo();
MockConfigInfo configInfo2 = new MockConfigInfo();
configInfo2.setId(2);
List<ConfigInfo> configInfos = new ArrayList<>();
List<MockConfigInfo> configInfos = new ArrayList<>();
configInfos.add(configInfo1);
configInfos.add(configInfo2);
when(tempJdbcTemplate.query(eq(sql), eq(args), any(RowMapper.class))).thenReturn(configInfos);
Expand Down

0 comments on commit 3d4014a

Please sign in to comment.