Skip to content

Commit 42eca93

Browse files
authored
Deprecate RunTransaction which takes a TransactionFunction. (#512)
* Deprecate RunTransaction which takes a TransactionFunction. * Update comments. * Don't use deprecated API in firestore TransactionTest * Address code review comments.
1 parent 8ad99ec commit 42eca93

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

firestore/integration_test_internal/src/includes_test.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ struct TestListener {
2424
void OnEvent(const int&, Error, const std::string&) {}
2525
};
2626

27-
struct TestTransactionFunction : TransactionFunction {
28-
Error Apply(Transaction&, std::string&) override { return Error::kErrorOk; }
29-
};
30-
3127
} // namespace
3228

3329
// This test makes sure that all the objects in Firestore public API are
@@ -68,7 +64,6 @@ TEST_F(IncludesTest, TestIncludingFirestoreHeaderIsSufficient) {
6864
WriteBatch write_batch;
6965

7066
TestListener test_listener;
71-
TestTransactionFunction test_transaction_function;
7267

7368
Timestamp timestamp;
7469
GeoPoint geo_point;

firestore/integration_test_internal/src/transaction_extra_test.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
namespace firebase {
1919
namespace firestore {
2020

21-
// We will be using lambda in the test instead of defining a
22-
// TransactionFunction for each of the test case.
23-
//
24-
// We do have a TransactionFunction-version of the test
25-
// TestGetNonexistentDocumentThenCreate to test the non-lambda API.
26-
2721
using TransactionExtraTest = FirestoreIntegrationTest;
2822

2923
TEST_F(TransactionExtraTest,

firestore/integration_test_internal/src/transaction_test.cc

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ namespace firestore {
3131

3232
using ::testing::HasSubstr;
3333

34-
// We will be using lambda in the test instead of defining a
35-
// TransactionFunction for each of the test case.
36-
//
37-
// We do have a TransactionFunction-version of the test
38-
// TestGetNonexistentDocumentThenCreate to test the non-lambda API.
39-
4034
class TransactionTest : public FirestoreIntegrationTest {
4135
protected:
4236
// We occasionally get transient error like "Could not reach Cloud Firestore
@@ -91,38 +85,25 @@ class TransactionTest : public FirestoreIntegrationTest {
9185
}
9286
};
9387

94-
class TestTransactionFunction : public TransactionFunction {
95-
public:
96-
TestTransactionFunction(DocumentReference doc) : doc_(doc) {}
97-
98-
Error Apply(Transaction& transaction, std::string& error_message) override {
99-
Error error = Error::kErrorUnknown;
100-
DocumentSnapshot snapshot = transaction.Get(doc_, &error, &error_message);
101-
EXPECT_EQ(Error::kErrorOk, error);
102-
EXPECT_FALSE(snapshot.exists());
103-
transaction.Set(doc_, MapFieldValue{{key_, FieldValue::String(value_)}});
104-
return error;
105-
}
106-
107-
std::string key() { return key_; }
108-
std::string value() { return value_; }
109-
110-
private:
111-
DocumentReference doc_;
112-
const std::string key_{"foo"};
113-
const std::string value_{"bar"};
114-
};
115-
116-
TEST_F(TransactionTest, TestGetNonexistentDocumentThenCreatePortableVersion) {
88+
TEST_F(TransactionTest, TestGetNonexistentDocumentThenCreate) {
11789
DocumentReference doc = TestFirestore()->Collection("towns").Document();
118-
TestTransactionFunction transaction{doc};
119-
Future<void> future = TestFirestore()->RunTransaction(&transaction);
90+
std::string key = "foo";
91+
std::string value = "bar";
92+
Future<void> future = TestFirestore()->RunTransaction(
93+
[&](Transaction& transaction, std::string& error_message) {
94+
Error error = Error::kErrorUnknown;
95+
DocumentSnapshot snapshot =
96+
transaction.Get(doc, &error, &error_message);
97+
EXPECT_EQ(Error::kErrorOk, error);
98+
EXPECT_FALSE(snapshot.exists());
99+
transaction.Set(doc, MapFieldValue{{key, FieldValue::String(value)}});
100+
return error;
101+
});
120102
Await(future);
121103

122104
EXPECT_EQ(Error::kErrorOk, future.error());
123105
DocumentSnapshot snapshot = ReadDocument(doc);
124-
EXPECT_EQ(FieldValue::String(transaction.value()),
125-
snapshot.Get(transaction.key()));
106+
EXPECT_EQ(FieldValue::String(value), snapshot.Get(key));
126107
}
127108

128109
class TransactionStage {

firestore/src/include/firebase/firestore.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,14 @@ class Firestore {
264264
* transaction is valid as long as the Future has not yet completed.)
265265
*
266266
* @return A Future that will be resolved when the transaction finishes.
267+
*
268+
* @deprecated This method was originally added to support the STLPort C++
269+
* runtime on Android. Firebase support for STLPort has been removed, and
270+
* consequently this method is deprecated and will be removed in a future
271+
* release.
267272
*/
268-
virtual Future<void> RunTransaction(TransactionFunction* update);
273+
FIREBASE_DEPRECATED virtual Future<void> RunTransaction(
274+
TransactionFunction* update);
269275

270276
/**
271277
* Sets the log verbosity of all Firestore instances.

0 commit comments

Comments
 (0)