| Index: components/sync/core/shared_model_type_processor_unittest.cc
|
| diff --git a/components/sync/core/shared_model_type_processor_unittest.cc b/components/sync/core/shared_model_type_processor_unittest.cc
|
| index d5c7f08c1510e272a30e671241639f56e356236c..7d7337cbd94f50398c45c8255d874179b35412b1 100644
|
| --- a/components/sync/core/shared_model_type_processor_unittest.cc
|
| +++ b/components/sync/core/shared_model_type_processor_unittest.cc
|
| @@ -20,14 +20,10 @@
|
| #include "components/sync/base/model_type.h"
|
| #include "components/sync/base/time.h"
|
| #include "components/sync/core/activation_context.h"
|
| -#include "components/sync/core/data_batch_impl.h"
|
| -#include "components/sync/core/non_blocking_sync_common.h"
|
| #include "components/sync/core/simple_metadata_change_list.h"
|
| #include "components/sync/core/test/data_type_error_handler_mock.h"
|
| #include "components/sync/engine/commit_queue.h"
|
| -#include "components/sync/protocol/data_type_state.pb.h"
|
| #include "components/sync/protocol/sync.pb.h"
|
| -#include "components/sync/syncable/syncable_util.h"
|
| #include "components/sync/test/engine/mock_model_type_worker.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -39,15 +35,6 @@ namespace syncer_v2 {
|
|
|
| namespace {
|
|
|
| -std::string ClientTagFromKey(const std::string& key) {
|
| - return "ClientTag_" + key;
|
| -}
|
| -
|
| -std::string TagHashFromKey(const std::string& key) {
|
| - return syncer::syncable::GenerateSyncableHash(syncer::PREFERENCES,
|
| - ClientTagFromKey(key));
|
| -}
|
| -
|
| const char kKey1[] = "key1";
|
| const char kKey2[] = "key2";
|
| const char kKey3[] = "key3";
|
| @@ -56,138 +43,21 @@ const char kKey5[] = "key5";
|
| const char kValue1[] = "value1";
|
| const char kValue2[] = "value2";
|
| const char kValue3[] = "value3";
|
| -const std::string kHash1(TagHashFromKey(kKey1));
|
| -const std::string kHash2(TagHashFromKey(kKey2));
|
| -const std::string kHash3(TagHashFromKey(kKey3));
|
| -const std::string kHash4(TagHashFromKey(kKey4));
|
| -const std::string kHash5(TagHashFromKey(kKey5));
|
| +const std::string kHash1(FakeModelTypeService::TagHashFromKey(kKey1));
|
| +const std::string kHash2(FakeModelTypeService::TagHashFromKey(kKey2));
|
| +const std::string kHash3(FakeModelTypeService::TagHashFromKey(kKey3));
|
| +const std::string kHash4(FakeModelTypeService::TagHashFromKey(kKey4));
|
| +const std::string kHash5(FakeModelTypeService::TagHashFromKey(kKey5));
|
|
|
| // Typically used for verification after a delete. The specifics given to the
|
| // worker/processor will not have been initialized and thus empty.
|
| const EntitySpecifics kEmptySpecifics;
|
|
|
| -EntitySpecifics GenerateSpecifics(const std::string& name,
|
| - const std::string& value) {
|
| - EntitySpecifics specifics;
|
| - specifics.mutable_preference()->set_name(name);
|
| - specifics.mutable_preference()->set_value(value);
|
| - return specifics;
|
| -}
|
| -
|
| -std::unique_ptr<EntityData> GenerateEntityData(const std::string& key,
|
| - const std::string& value) {
|
| - std::unique_ptr<EntityData> entity_data = base::MakeUnique<EntityData>();
|
| - entity_data->client_tag_hash = TagHashFromKey(key);
|
| - entity_data->specifics = GenerateSpecifics(key, value);
|
| - entity_data->non_unique_name = key;
|
| - return entity_data;
|
| -}
|
| -
|
| -// It is intentionally very difficult to copy an EntityData, as in normal code
|
| -// we never want to. However, since we store the data as an EntityData for the
|
| -// test code here, this function is needed to manually copy it.
|
| -std::unique_ptr<EntityData> CopyEntityData(const EntityData& old_data) {
|
| - std::unique_ptr<EntityData> new_data(new EntityData());
|
| - new_data->id = old_data.id;
|
| - new_data->client_tag_hash = old_data.client_tag_hash;
|
| - new_data->non_unique_name = old_data.non_unique_name;
|
| - new_data->specifics = old_data.specifics;
|
| - new_data->creation_time = old_data.creation_time;
|
| - new_data->modification_time = old_data.modification_time;
|
| - return new_data;
|
| -}
|
| -
|
| syncer::SyncError CreateSyncError(syncer::SyncError::ErrorType error_type) {
|
| return syncer::SyncError(FROM_HERE, error_type, "TestError",
|
| syncer::PREFERENCES);
|
| }
|
|
|
| -// A basic in-memory storage mechanism for data and metadata. This makes it
|
| -// easier to test more complex behaviors involving when entities are written,
|
| -// committed, etc. Having a separate class helps keep the main one cleaner.
|
| -class SimpleStore {
|
| - public:
|
| - void PutData(const std::string& key, const EntityData& data) {
|
| - data_change_count_++;
|
| - data_store_[key] = CopyEntityData(data);
|
| - }
|
| -
|
| - void PutMetadata(const std::string& key, const EntityMetadata& metadata) {
|
| - metadata_change_count_++;
|
| - metadata_store_[key] = metadata;
|
| - }
|
| -
|
| - void RemoveData(const std::string& key) {
|
| - data_change_count_++;
|
| - data_store_.erase(key);
|
| - }
|
| -
|
| - void RemoveMetadata(const std::string& key) {
|
| - metadata_change_count_++;
|
| - metadata_store_.erase(key);
|
| - }
|
| -
|
| - bool HasData(const std::string& key) const {
|
| - return data_store_.find(key) != data_store_.end();
|
| - }
|
| -
|
| - bool HasMetadata(const std::string& key) const {
|
| - return metadata_store_.find(key) != metadata_store_.end();
|
| - }
|
| -
|
| - const std::map<std::string, std::unique_ptr<EntityData>>& GetAllData() const {
|
| - return data_store_;
|
| - }
|
| -
|
| - const EntityData& GetData(const std::string& key) const {
|
| - return *data_store_.find(key)->second;
|
| - }
|
| -
|
| - const std::string& GetValue(const std::string& key) const {
|
| - return GetData(key).specifics.preference().value();
|
| - }
|
| -
|
| - const EntityMetadata& GetMetadata(const std::string& key) const {
|
| - return metadata_store_.find(key)->second;
|
| - }
|
| -
|
| - size_t DataCount() const { return data_store_.size(); }
|
| - size_t MetadataCount() const { return metadata_store_.size(); }
|
| -
|
| - size_t DataChangeCount() const { return data_change_count_; }
|
| - size_t MetadataChangeCount() const { return metadata_change_count_; }
|
| -
|
| - const DataTypeState& data_type_state() const { return data_type_state_; }
|
| -
|
| - void set_data_type_state(const DataTypeState& data_type_state) {
|
| - data_type_state_ = data_type_state;
|
| - }
|
| -
|
| - std::unique_ptr<MetadataBatch> CreateMetadataBatch() const {
|
| - std::unique_ptr<MetadataBatch> metadata_batch(new MetadataBatch());
|
| - metadata_batch->SetDataTypeState(data_type_state_);
|
| - for (auto it = metadata_store_.begin(); it != metadata_store_.end(); it++) {
|
| - metadata_batch->AddMetadata(it->first, it->second);
|
| - }
|
| - return metadata_batch;
|
| - }
|
| -
|
| - void Reset() {
|
| - data_change_count_ = 0;
|
| - metadata_change_count_ = 0;
|
| - data_store_.clear();
|
| - metadata_store_.clear();
|
| - data_type_state_.Clear();
|
| - }
|
| -
|
| - private:
|
| - size_t data_change_count_ = 0;
|
| - size_t metadata_change_count_ = 0;
|
| - std::map<std::string, std::unique_ptr<EntityData>> data_store_;
|
| - std::map<std::string, EntityMetadata> metadata_store_;
|
| - DataTypeState data_type_state_;
|
| -};
|
| -
|
| } // namespace
|
|
|
| // Tests the various functionality of SharedModelTypeProcessor.
|
| @@ -212,8 +82,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| : FakeModelTypeService(
|
| base::Bind(&SharedModelTypeProcessor::CreateAsChangeProcessor)) {}
|
|
|
| - ~SharedModelTypeProcessorTest() override { CheckPostConditions(); }
|
| -
|
| void InitializeToMetadataLoaded() {
|
| CreateChangeProcessor();
|
| DataTypeState data_type_state(db_.data_type_state());
|
| @@ -254,26 +122,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| worker_ = nullptr;
|
| }
|
|
|
| - // Local data modification. Emulates signals from the model thread.
|
| - EntitySpecifics WriteItem(const std::string& key, const std::string& value) {
|
| - std::unique_ptr<EntityData> entity_data = GenerateEntityData(key, value);
|
| - EntitySpecifics specifics_copy = entity_data->specifics;
|
| - WriteItem(key, std::move(entity_data));
|
| - return specifics_copy;
|
| - }
|
| -
|
| - // Overloaded form to allow passing of custom entity data.
|
| - void WriteItem(const std::string& key,
|
| - std::unique_ptr<EntityData> entity_data) {
|
| - db_.PutData(key, *entity_data);
|
| - if (type_processor()) {
|
| - std::unique_ptr<MetadataChangeList> change_list(
|
| - new SimpleMetadataChangeList());
|
| - type_processor()->Put(key, std::move(entity_data), change_list.get());
|
| - ApplyMetadataChangeList(std::move(change_list));
|
| - }
|
| - }
|
| -
|
| // Writes data for |key| and simulates a commit response for it.
|
| EntitySpecifics WriteItemAndAck(const std::string& key,
|
| const std::string& value) {
|
| @@ -284,16 +132,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| return specifics;
|
| }
|
|
|
| - void DeleteItem(const std::string& key) {
|
| - db_.RemoveData(key);
|
| - if (type_processor()) {
|
| - std::unique_ptr<MetadataChangeList> change_list(
|
| - new SimpleMetadataChangeList());
|
| - type_processor()->Delete(key, change_list.get());
|
| - ApplyMetadataChangeList(std::move(change_list));
|
| - }
|
| - }
|
| -
|
| void ResetState() {
|
| clear_change_processor();
|
| db_.Reset();
|
| @@ -359,12 +197,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| conflict_resolution_.reset(new ConflictResolution(std::move(resolution)));
|
| }
|
|
|
| - // Sets the error that the next fallible call to the service will generate.
|
| - void SetServiceError(syncer::SyncError::ErrorType error_type) {
|
| - DCHECK(!service_error_.IsSet());
|
| - service_error_ = CreateSyncError(error_type);
|
| - }
|
| -
|
| // Sets the error type that OnReadyToConnect (our StartCallback) expects to
|
| // receive.
|
| void ExpectStartError(syncer::SyncError::ErrorType error_type) {
|
| @@ -372,8 +204,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| expected_start_error_ = error_type;
|
| }
|
|
|
| - const SimpleStore& db() const { return db_; }
|
| -
|
| MockModelTypeWorker* worker() { return worker_; }
|
|
|
| SharedModelTypeProcessor* type_processor() const {
|
| @@ -383,9 +213,9 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| syncer::DataTypeErrorHandlerMock* error_handler() { return &error_handler_; }
|
|
|
| private:
|
| - void CheckPostConditions() {
|
| + void CheckPostConditions() override {
|
| + FakeModelTypeService::CheckPostConditions();
|
| DCHECK(data_callback_.is_null());
|
| - DCHECK(!service_error_.IsSet());
|
| DCHECK_EQ(syncer::SyncError::UNSET, expected_start_error_);
|
| }
|
|
|
| @@ -411,115 +241,16 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
|
|
| // FakeModelTypeService overrides.
|
|
|
| - std::string GetClientTag(const EntityData& entity_data) override {
|
| - return ClientTagFromKey(entity_data.specifics.preference().name());
|
| - }
|
| -
|
| - std::string GetStorageKey(const EntityData& entity_data) override {
|
| - return entity_data.specifics.preference().name();
|
| - }
|
| -
|
| - std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override {
|
| - return std::unique_ptr<MetadataChangeList>(new SimpleMetadataChangeList());
|
| - }
|
| -
|
| - syncer::SyncError MergeSyncData(
|
| - std::unique_ptr<MetadataChangeList> metadata_changes,
|
| - EntityDataMap data_map) override {
|
| - if (service_error_.IsSet()) {
|
| - syncer::SyncError error = service_error_;
|
| - service_error_ = syncer::SyncError();
|
| - return error;
|
| - }
|
| - // Commit any local entities that aren't being overwritten by the server.
|
| - const auto& local_data = db_.GetAllData();
|
| - for (auto it = local_data.begin(); it != local_data.end(); it++) {
|
| - if (data_map.find(it->first) == data_map.end()) {
|
| - type_processor()->Put(it->first, CopyEntityData(*it->second),
|
| - metadata_changes.get());
|
| - }
|
| - }
|
| - // Store any new remote entities.
|
| - for (auto it = data_map.begin(); it != data_map.end(); it++) {
|
| - db_.PutData(it->first, it->second.value());
|
| - }
|
| - ApplyMetadataChangeList(std::move(metadata_changes));
|
| - return syncer::SyncError();
|
| - }
|
| -
|
| - syncer::SyncError ApplySyncChanges(
|
| - std::unique_ptr<MetadataChangeList> metadata_changes,
|
| - EntityChangeList entity_changes) override {
|
| - if (service_error_.IsSet()) {
|
| - syncer::SyncError error = service_error_;
|
| - service_error_ = syncer::SyncError();
|
| - return error;
|
| - }
|
| - for (const EntityChange& change : entity_changes) {
|
| - switch (change.type()) {
|
| - case EntityChange::ACTION_ADD:
|
| - EXPECT_FALSE(db_.HasData(change.storage_key()));
|
| - db_.PutData(change.storage_key(), change.data());
|
| - break;
|
| - case EntityChange::ACTION_UPDATE:
|
| - EXPECT_TRUE(db_.HasData(change.storage_key()));
|
| - db_.PutData(change.storage_key(), change.data());
|
| - break;
|
| - case EntityChange::ACTION_DELETE:
|
| - EXPECT_TRUE(db_.HasData(change.storage_key()));
|
| - db_.RemoveData(change.storage_key());
|
| - break;
|
| - }
|
| - }
|
| - ApplyMetadataChangeList(std::move(metadata_changes));
|
| - return syncer::SyncError();
|
| - }
|
| -
|
| - void ApplyMetadataChangeList(
|
| - std::unique_ptr<MetadataChangeList> change_list) {
|
| - DCHECK(change_list);
|
| - SimpleMetadataChangeList* changes =
|
| - static_cast<SimpleMetadataChangeList*>(change_list.get());
|
| - const auto& metadata_changes = changes->GetMetadataChanges();
|
| - for (auto it = metadata_changes.begin(); it != metadata_changes.end();
|
| - it++) {
|
| - switch (it->second.type) {
|
| - case SimpleMetadataChangeList::UPDATE:
|
| - db_.PutMetadata(it->first, it->second.metadata);
|
| - break;
|
| - case SimpleMetadataChangeList::CLEAR:
|
| - EXPECT_TRUE(db_.HasMetadata(it->first));
|
| - db_.RemoveMetadata(it->first);
|
| - break;
|
| - }
|
| - }
|
| - if (changes->HasDataTypeStateChange()) {
|
| - const SimpleMetadataChangeList::DataTypeStateChange& state_change =
|
| - changes->GetDataTypeStateChange();
|
| - switch (state_change.type) {
|
| - case SimpleMetadataChangeList::UPDATE:
|
| - db_.set_data_type_state(state_change.state);
|
| - break;
|
| - case SimpleMetadataChangeList::CLEAR:
|
| - db_.set_data_type_state(DataTypeState());
|
| - break;
|
| - }
|
| - }
|
| + void CaptureDataCallback(DataCallback callback,
|
| + syncer::SyncError error,
|
| + std::unique_ptr<DataBatch> data) {
|
| + data_callback_ = base::Bind(callback, error, base::Passed(std::move(data)));
|
| }
|
|
|
| void GetData(StorageKeyList keys, DataCallback callback) override {
|
| - if (service_error_.IsSet()) {
|
| - data_callback_ = base::Bind(callback, service_error_, nullptr);
|
| - service_error_ = syncer::SyncError();
|
| - return;
|
| - }
|
| - std::unique_ptr<DataBatchImpl> batch(new DataBatchImpl());
|
| - for (const std::string& key : keys) {
|
| - DCHECK(db_.HasData(key)) << "No data for " << key;
|
| - batch->Put(key, CopyEntityData(db_.GetData(key)));
|
| - }
|
| - data_callback_ =
|
| - base::Bind(callback, syncer::SyncError(), base::Passed(&batch));
|
| + FakeModelTypeService::GetData(
|
| + keys, base::Bind(&SharedModelTypeProcessorTest::CaptureDataCallback,
|
| + base::Unretained(this), callback));
|
| }
|
|
|
| ConflictResolution ResolveConflict(
|
| @@ -541,15 +272,9 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
|
| // Stores the data callback between GetData() and OnPendingCommitDataLoaded().
|
| base::Closure data_callback_;
|
|
|
| - // Contains all of the data and metadata state for these tests.
|
| - SimpleStore db_;
|
| -
|
| // The processor's error handler.
|
| syncer::DataTypeErrorHandlerMock error_handler_;
|
|
|
| - // The error to produce on the next service call.
|
| - syncer::SyncError service_error_;
|
| -
|
| // The error to expect in OnReadyToConnect().
|
| syncer::SyncError::ErrorType expected_start_error_ = syncer::SyncError::UNSET;
|
| };
|
| @@ -564,8 +289,8 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) {
|
| WriteItem(kKey1, kValue1);
|
|
|
| // Has data, but no metadata, entity in the processor, or commit request.
|
| - EXPECT_EQ(1U, db().DataCount());
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().data_count());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
|
|
| @@ -574,8 +299,8 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) {
|
|
|
| // Now have data and metadata for both items, as well as a commit request for
|
| // the local item.
|
| - EXPECT_EQ(2U, db().DataCount());
|
| - EXPECT_EQ(2U, db().MetadataCount());
|
| + EXPECT_EQ(2U, db().data_count());
|
| + EXPECT_EQ(2U, db().metadata_count());
|
| EXPECT_EQ(2U, ProcessorEntityCount());
|
| EXPECT_EQ(1, db().GetMetadata(kKey1).sequence_number());
|
| EXPECT_EQ(0, db().GetMetadata(kKey2).sequence_number());
|
| @@ -853,7 +578,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalCreateItem) {
|
| EXPECT_EQ(kKey1, tag1_data.specifics.preference().name());
|
| EXPECT_EQ(kValue1, tag1_data.specifics.preference().value());
|
|
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| const EntityMetadata metadata = db().GetMetadata(kKey1);
|
| EXPECT_TRUE(metadata.has_client_tag_hash());
|
| EXPECT_FALSE(metadata.has_server_id());
|
| @@ -866,7 +591,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalCreateItem) {
|
| EXPECT_TRUE(metadata.has_specifics_hash());
|
|
|
| worker()->AckOnePendingCommit();
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| const EntityMetadata acked_metadata = db().GetMetadata(kKey1);
|
| EXPECT_TRUE(acked_metadata.has_server_id());
|
| EXPECT_EQ(1, acked_metadata.sequence_number());
|
| @@ -905,7 +630,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemWithOverrides) {
|
| EXPECT_EQ(1U, worker()->GetNumPendingCommits());
|
| ASSERT_FALSE(worker()->HasPendingCommitForHash(kHash3));
|
| ASSERT_TRUE(worker()->HasPendingCommitForHash(kHash1));
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| const EntityData& out_entity1 =
|
| worker()->GetLatestPendingCommitForHash(kHash1).entity.value();
|
| const EntityMetadata metadata_v1 = db().GetMetadata(kKey1);
|
| @@ -930,7 +655,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemWithOverrides) {
|
| EXPECT_EQ(2U, worker()->GetNumPendingCommits());
|
| ASSERT_FALSE(worker()->HasPendingCommitForHash(kHash3));
|
| ASSERT_TRUE(worker()->HasPendingCommitForHash(kHash1));
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| const EntityData& out_entity2 =
|
| worker()->GetLatestPendingCommitForHash(kHash1).entity.value();
|
| const EntityMetadata metadata_v2 = db().GetMetadata(kKey1);
|
| @@ -951,7 +676,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItem) {
|
| InitializeToReadyState();
|
|
|
| WriteItem(kKey1, kValue1);
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| worker()->ExpectPendingCommits({kHash1});
|
|
|
| const CommitRequestData& request_data_v1 =
|
| @@ -960,7 +685,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItem) {
|
| const EntityMetadata metadata_v1 = db().GetMetadata(kKey1);
|
|
|
| WriteItem(kKey1, kValue2);
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| worker()->ExpectPendingCommits({kHash1, kHash1});
|
|
|
| const CommitRequestData& request_data_v2 =
|
| @@ -1003,7 +728,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItem) {
|
| TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemRedundant) {
|
| InitializeToReadyState();
|
| WriteItem(kKey1, kValue1);
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| worker()->ExpectPendingCommits({kHash1});
|
|
|
| WriteItem(kKey1, kValue1);
|
| @@ -1014,8 +739,8 @@ TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemRedundant) {
|
| TEST_F(SharedModelTypeProcessorTest, ServerCreateItem) {
|
| InitializeToReadyState();
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1));
|
| - EXPECT_EQ(1U, db().DataCount());
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().data_count());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| EXPECT_EQ(1U, ProcessorEntityCount());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
|
|
| @@ -1055,19 +780,19 @@ TEST_F(SharedModelTypeProcessorTest, ServerUpdateItem) {
|
|
|
| // Local add writes data and metadata; ack writes metadata again.
|
| WriteItemAndAck(kKey1, kValue1);
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| - EXPECT_EQ(2U, db().MetadataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| + EXPECT_EQ(2U, db().metadata_change_count());
|
|
|
| // Redundant update from server doesn't write data but updates metadata.
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1));
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| - EXPECT_EQ(3U, db().MetadataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| + EXPECT_EQ(3U, db().metadata_change_count());
|
|
|
| // A reflection (update already received) is ignored completely.
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1),
|
| 0 /* version_offset */);
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| - EXPECT_EQ(3U, db().MetadataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| + EXPECT_EQ(3U, db().metadata_change_count());
|
| }
|
|
|
| // Tests locally deleting an acknowledged item.
|
| @@ -1083,9 +808,9 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteItem) {
|
| EXPECT_EQ(1, metadata_v1.server_version());
|
|
|
| DeleteItem(kKey1);
|
| - EXPECT_EQ(0U, db().DataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| // Metadata is not removed until the commit response comes back.
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| EXPECT_EQ(1U, ProcessorEntityCount());
|
| worker()->ExpectPendingCommits({kHash1});
|
|
|
| @@ -1097,7 +822,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteItem) {
|
|
|
| // Ack the delete and check that the metadata is cleared.
|
| worker()->AckOnePendingCommit();
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| }
|
|
|
| @@ -1117,8 +842,8 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteItemInterleaved) {
|
| EXPECT_EQ(kUncommittedVersion, metadata_v1.server_version());
|
|
|
| DeleteItem(kKey1);
|
| - EXPECT_EQ(0U, db().DataCount());
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| EXPECT_EQ(1U, ProcessorEntityCount());
|
| worker()->ExpectPendingCommits({kHash1, kHash1});
|
|
|
| @@ -1137,8 +862,8 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteItemInterleaved) {
|
|
|
| // A response for the first commit doesn't change much.
|
| worker()->AckOnePendingCommit();
|
| - EXPECT_EQ(0U, db().DataCount());
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| EXPECT_EQ(1U, ProcessorEntityCount());
|
|
|
| const EntityMetadata metadata_v3 = db().GetMetadata(kKey1);
|
| @@ -1149,7 +874,7 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteItemInterleaved) {
|
|
|
| worker()->AckOnePendingCommit();
|
| // The delete was acked so the metadata should now be cleared.
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| }
|
|
|
| @@ -1157,14 +882,14 @@ TEST_F(SharedModelTypeProcessorTest, ServerDeleteItem) {
|
| InitializeToReadyState();
|
| WriteItemAndAck(kKey1, kValue1);
|
| EXPECT_EQ(1U, ProcessorEntityCount());
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| - EXPECT_EQ(1U, db().DataCount());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| + EXPECT_EQ(1U, db().data_count());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
|
|
| worker()->TombstoneFromServer(kHash1);
|
| // Delete from server should clear the data and all the metadata.
|
| - EXPECT_EQ(0U, db().DataCount());
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
| }
|
| @@ -1174,8 +899,8 @@ TEST_F(SharedModelTypeProcessorTest, ServerDeleteItem) {
|
| TEST_F(SharedModelTypeProcessorTest, LocalDeleteUnknown) {
|
| InitializeToReadyState();
|
| DeleteItem(kKey1);
|
| - EXPECT_EQ(0U, db().DataCount());
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
| }
|
| @@ -1185,8 +910,8 @@ TEST_F(SharedModelTypeProcessorTest, LocalDeleteUnknown) {
|
| TEST_F(SharedModelTypeProcessorTest, ServerDeleteUnknown) {
|
| InitializeToReadyState();
|
| worker()->TombstoneFromServer(kHash1);
|
| - EXPECT_EQ(0U, db().DataCount());
|
| - EXPECT_EQ(0U, db().MetadataCount());
|
| + EXPECT_EQ(0U, db().data_count());
|
| + EXPECT_EQ(0U, db().metadata_count());
|
| EXPECT_EQ(0U, ProcessorEntityCount());
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
| }
|
| @@ -1198,16 +923,16 @@ TEST_F(SharedModelTypeProcessorTest, TwoIndependentItems) {
|
| EXPECT_EQ(0U, worker()->GetNumPendingCommits());
|
|
|
| WriteItem(kKey1, kValue1);
|
| - EXPECT_EQ(1U, db().DataCount());
|
| - EXPECT_EQ(1U, db().MetadataCount());
|
| + EXPECT_EQ(1U, db().data_count());
|
| + EXPECT_EQ(1U, db().metadata_count());
|
| const EntityMetadata metadata1 = db().GetMetadata(kKey1);
|
|
|
| // There should be one commit request for this item only.
|
| worker()->ExpectPendingCommits({kHash1});
|
|
|
| WriteItem(kKey2, kValue2);
|
| - EXPECT_EQ(2U, db().DataCount());
|
| - EXPECT_EQ(2U, db().MetadataCount());
|
| + EXPECT_EQ(2U, db().data_count());
|
| + EXPECT_EQ(2U, db().metadata_count());
|
| const EntityMetadata metadata2 = db().GetMetadata(kKey2);
|
|
|
| // The second write should trigger another single-item commit request.
|
| @@ -1227,9 +952,9 @@ TEST_F(SharedModelTypeProcessorTest, TwoIndependentItems) {
|
| TEST_F(SharedModelTypeProcessorTest, ConflictResolutionChangesMatch) {
|
| InitializeToReadyState();
|
| EntitySpecifics specifics = WriteItem(kKey1, kValue1);
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| EXPECT_EQ(kValue1, db().GetValue(kKey1));
|
| - EXPECT_EQ(1U, db().MetadataChangeCount());
|
| + EXPECT_EQ(1U, db().metadata_change_count());
|
| EXPECT_EQ(kUncommittedVersion, db().GetMetadata(kKey1).server_version());
|
| worker()->ExpectPendingCommits({kHash1});
|
| worker()->ExpectNthPendingCommit(0, kHash1, specifics);
|
| @@ -1238,7 +963,7 @@ TEST_F(SharedModelTypeProcessorTest, ConflictResolutionChangesMatch) {
|
| worker()->UpdateFromServer(kHash1, specifics);
|
|
|
| // Updated metadata but not data; no new commit request.
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| EXPECT_EQ(1, db().GetMetadata(kKey1).server_version());
|
| worker()->ExpectPendingCommits({kHash1});
|
| }
|
| @@ -1251,8 +976,8 @@ TEST_F(SharedModelTypeProcessorTest, ConflictResolutionUseLocal) {
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue2));
|
|
|
| // Updated metadata but not data; new commit request.
|
| - EXPECT_EQ(1U, db().DataChangeCount());
|
| - EXPECT_EQ(2U, db().MetadataChangeCount());
|
| + EXPECT_EQ(1U, db().data_change_count());
|
| + EXPECT_EQ(2U, db().metadata_change_count());
|
| EXPECT_EQ(1, db().GetMetadata(kKey1).server_version());
|
| worker()->ExpectPendingCommits({kHash1, kHash1});
|
| worker()->ExpectNthPendingCommit(1, kHash1, specifics);
|
| @@ -1265,9 +990,9 @@ TEST_F(SharedModelTypeProcessorTest, ConflictResolutionUseRemote) {
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue2));
|
|
|
| // Updated client data and metadata; no new commit request.
|
| - EXPECT_EQ(2U, db().DataChangeCount());
|
| + EXPECT_EQ(2U, db().data_change_count());
|
| EXPECT_EQ(kValue2, db().GetValue(kKey1));
|
| - EXPECT_EQ(2U, db().MetadataChangeCount());
|
| + EXPECT_EQ(2U, db().metadata_change_count());
|
| EXPECT_EQ(1, db().GetMetadata(kKey1).server_version());
|
| worker()->ExpectPendingCommits({kHash1});
|
| }
|
| @@ -1279,9 +1004,9 @@ TEST_F(SharedModelTypeProcessorTest, ConflictResolutionUseNew) {
|
| ConflictResolution::UseNew(GenerateEntityData(kKey1, kValue3)));
|
|
|
| worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue2));
|
| - EXPECT_EQ(2U, db().DataChangeCount());
|
| + EXPECT_EQ(2U, db().data_change_count());
|
| EXPECT_EQ(kValue3, db().GetValue(kKey1));
|
| - EXPECT_EQ(2U, db().MetadataChangeCount());
|
| + EXPECT_EQ(2U, db().metadata_change_count());
|
| EXPECT_EQ(1, db().GetMetadata(kKey1).server_version());
|
| worker()->ExpectPendingCommits({kHash1, kHash1});
|
| worker()->ExpectNthPendingCommit(1, kHash1,
|
|
|