1 Star 0 Fork 0

廖永煌/lyh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
br_187.diff 5.59 KB
一键复制 编辑 原始数据 按行查看 历史
廖永煌 提交于 2025-02-20 16:55 +08:00 . 1
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
index 3494f7df0..1881542ac 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
@@ -731,6 +731,34 @@ void DistributedDBToolsUnitTest::BlockSync(RelationalStoreDelegate &delegate, co
}
}
+void DistributedDBToolsUnitTest::BlockSync(RelationalStoreDelegate &delegate, const Query &query,
+ DistributedDB::SyncMode syncMode, const std::vector<DistributedDB::DBStatus> exceptStatus,
+ const std::vector<std::string> &devices)
+{
+ std::map<std::string, std::vector<TableStatus>> statusMap;
+ SyncStatusCallback callBack = [&statusMap](
+ const std::map<std::string, std::vector<TableStatus>> &devicesMap) {
+ statusMap = devicesMap;
+ };
+ DBStatus callStatus = delegate.Sync(devices, syncMode, query, callBack, true);
+ EXPECT_EQ(callStatus, OK);
+ QueryExpression queryExpression = GetQueryInfo::GetQueryExpression(query);
+ std::vector<std::string> syncTables;
+ if (queryExpression.IsUseFromTables()) {
+ syncTables = queryExpression.GetTables();
+ } else {
+ syncTables = {queryExpression.GetTableName()};
+ }
+ for (const auto &tablesRes : statusMap) {
+ ASSERT_EQ(tablesRes.second.size(), syncTables.size());
+ ASSERT_EQ(exceptStatus.size(), syncTables.size());
+ for (uint32_t i = 0; i < syncTables.size(); i++) {
+ EXPECT_EQ(tablesRes.second[i].status, exceptStatus[i]);
+ EXPECT_EQ(tablesRes.second[i].tableName, syncTables[i]);
+ }
+ }
+}
+
KvStoreObserverUnitTest::KvStoreObserverUnitTest() : callCount_(0), isCleared_(false)
{}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
index beb1dd8f1..ff4b3bd33 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
@@ -235,6 +235,10 @@ public:
static void BlockSync(DistributedDB::RelationalStoreDelegate &delegate, const DistributedDB::Query &query,
DistributedDB::SyncMode syncMode, DistributedDB::DBStatus exceptStatus,
const std::vector<std::string> &devices);
+
+ static void BlockSync(DistributedDB::RelationalStoreDelegate &delegate, const DistributedDB::Query &query,
+ DistributedDB::SyncMode syncMode, const std::vector<DistributedDB::DBStatus> exceptStatus,
+ const std::vector<std::string> &devices);
private:
static int OpenMockMultiDb(DatabaseInfo &dbInfo, DistributedDB::OpenDbProperties &properties);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
index b9e154d49..143987a8b 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
@@ -2387,4 +2387,45 @@ HWTEST_F(DistributedDBRDBCollaborationTest, InvalidSync004, TestSize.Level0)
DBStatus callStatus = delegate_->Sync({deviceB_->GetDeviceId()}, SYNC_MODE_PUSH_ONLY, query, nullptr, true);
EXPECT_EQ(callStatus, INVALID_ARGS);
}
+
+/**
+ * @tc.name: InvalidSync005
+ * @tc.desc: Test sync with table witch non-existent table on the other end
+ * @tc.type: FUNC
+ * @tc.require:
+ * @tc.author: liaoyonghuang
+ */
+HWTEST_F(DistributedDBRDBCollaborationTest, InvalidSync005, TestSize.Level0)
+{
+ /**
+ * @tc.steps: step1. Init DB and create table "DEVICE_SYNC_TABLE" on both ends
+ * @tc.expected: step1.ok
+ */
+ ASSERT_NO_FATAL_FAILURE(InitDelegate());
+ auto schema = GetSchema();
+ auto distributedSchema = RDBDataGenerator::ParseSchema(schema, true);
+ deviceB_->SetDistributedSchema(distributedSchema);
+ EXPECT_EQ(delegate_->CreateDistributedTable(DEVICE_SYNC_TABLE, TableSyncType::DEVICE_COOPERATION), OK);
+ auto tableSchema = GetTableSchema();
+ ASSERT_EQ(RDBDataGenerator::InsertVirtualLocalDBData(0, 1, deviceB_, tableSchema), E_OK);
+ ASSERT_EQ(RDBDataGenerator::PrepareVirtualDeviceEnv(tableSchema.name, db_, deviceB_), E_OK);
+ /**
+ * @tc.steps: step2. Create a new table locally
+ * @tc.expected: step2.ok
+ */
+ std::string tableName = "newTable";
+ std::string sql = "CREATE TABLE IF NOT EXISTS " + tableName + "(integer_field1 INTEGER, integer_field2 INT);";
+ ASSERT_EQ(SQLiteUtils::ExecuteRawSQL(db_, sql), E_OK);
+ EXPECT_EQ(delegate_->CreateDistributedTable(tableName, TableSyncType::DEVICE_COOPERATION), OK);
+ auto newDistributedSchema = GetDistributedSchema(tableName, {"integer_field1", "integer_field2"});
+ distributedSchema.tables.push_back(newDistributedSchema.tables.front());
+ EXPECT_EQ(delegate_->SetDistributedSchema(distributedSchema), OK);
+ /**
+ * @tc.steps: step3. Sync with DEVICE_SYNC_TABLE and new table
+ * @tc.expected: step3. return SCHEMA_MISMATCH
+ */
+ Query query = Query::Select().FromTable({DEVICE_SYNC_TABLE, tableName});
+ DistributedDBToolsUnitTest::BlockSync(*delegate_, query, SYNC_MODE_PUSH_ONLY, {OK, SCHEMA_MISMATCH},
+ {deviceB_->GetDeviceId()});
+}
}
\ No newline at end of file
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liao-yonghuang/lyh.git
git@gitee.com:liao-yonghuang/lyh.git
liao-yonghuang
lyh
lyh
master

搜索帮助