| 29 | |
| 30 | DEFINE_string(server, "localhost:11210", "IP Address of server"); |
| 31 | int performOperations(brpc::CouchbaseOperations& couchbase_ops) { |
| 32 | std::string add_key = "user::test_brpc_binprot"; |
| 33 | std::string add_value = |
| 34 | R"({"name": "John Doe", "age": 30, "email": "john@example.com"})"; |
| 35 | |
| 36 | brpc::CouchbaseOperations::Result add_result = |
| 37 | couchbase_ops.add(add_key, add_value); |
| 38 | if (add_result.success) { |
| 39 | std::cout << GREEN << "ADD operation successful" << RESET << std::endl; |
| 40 | } else { |
| 41 | std::cout << RED << "ADD operation failed: " << add_result.error_message |
| 42 | << RESET << std::endl; |
| 43 | } |
| 44 | |
| 45 | // Try to ADD the same key again (should fail with key exists) |
| 46 | brpc::CouchbaseOperations::Result add_result2 = |
| 47 | couchbase_ops.add(add_key, add_value); |
| 48 | if (add_result2.success) { |
| 49 | std::cout << GREEN << "Second ADD operation unexpectedly successful" |
| 50 | << RESET << std::endl; |
| 51 | } else { |
| 52 | std::cout << RED << "Second ADD operation failed as expected: " |
| 53 | << add_result2.error_message << RESET << std::endl; |
| 54 | } |
| 55 | // Get operation using high-level method |
| 56 | brpc::CouchbaseOperations::Result get_result = couchbase_ops.get(add_key); |
| 57 | if (get_result.success) { |
| 58 | std::cout << GREEN << "GET operation successful" << RESET << std::endl; |
| 59 | std::cout << "GET value: " << get_result.value << std::endl; |
| 60 | } else { |
| 61 | std::cout << RED << "GET operation failed: " << get_result.error_message |
| 62 | << RESET << std::endl; |
| 63 | } |
| 64 | |
| 65 | // Add binprot item1 using high-level method |
| 66 | std::string item1_key = "binprot_item1"; |
| 67 | brpc::CouchbaseOperations::Result item1_result = |
| 68 | couchbase_ops.add(item1_key, add_value); |
| 69 | if (item1_result.success) { |
| 70 | std::cout << GREEN << "ADD binprot item1 successful" << RESET << std::endl; |
| 71 | } else { |
| 72 | std::cout << RED |
| 73 | << "ADD binprot item1 failed: " << item1_result.error_message |
| 74 | << RESET << std::endl; |
| 75 | } |
| 76 | |
| 77 | // Add binprot item2 using high-level method |
| 78 | std::string item2_key = "binprot_item2"; |
| 79 | brpc::CouchbaseOperations::Result item2_result = |
| 80 | couchbase_ops.add(item2_key, add_value); |
| 81 | if (item2_result.success) { |
| 82 | std::cout << GREEN << "ADD binprot item2 successful" << RESET << std::endl; |
| 83 | } else { |
| 84 | std::cout << RED |
| 85 | << "ADD binprot item2 failed: " << item2_result.error_message |
| 86 | << RESET << std::endl; |
| 87 | } |
| 88 |
no test coverage detected