TEST_F(ClientTxnTest, testTxnRollback) { util::CountDownLatch memberRemovedLatch(1); std::string queueName = "testTxnRollback"; MyLifecycleListener myLifecycleListener(memberRemovedLatch); client->getCluster().addMembershipListener(&myLifecycleListener); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalQueue<std::string> queue = context.getQueue<std::string>(queueName); queue.offer("item"); server->shutdown(); ASSERT_THROW(context.commitTransaction(), exception::IException); context.rollbackTransaction(); ASSERT_TRUE(memberRemovedLatch.await(10)); IQueue<std::string> q = client->getQueue<std::string>(queueName); try { ASSERT_EQ(0, q.size()); ASSERT_EQ(q.poll().get(), (std::string *)NULL); } catch (exception::IException& e) { std::cout << e.what() << std::endl; } }
void ClientTxnMapTest::testKeySetAndValuesWithPredicates() { std::string name = "testKeysetAndValuesWithPredicates"; IMap<Employee, Employee> map = client->getMap<Employee, Employee>(name); Employee emp1("abc-123-xvz", 34); Employee emp2("abc-123-xvz", 20); map.put(emp1, emp1); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalMap<Employee, Employee> txMap = context.getMap<Employee, Employee>(name); assertNull(txMap.put(emp2, emp2).get()); assertEqual(2, (int)txMap.size()); assertEqual(2, (int)txMap.keySet().size()); query::SqlPredicate predicate("a = 10"); assertEqual(0, (int)txMap.keySet(&predicate).size()); assertEqual(0, (int)txMap.values(&predicate).size()); predicate.setSql("a >= 10"); assertEqual(2, (int)txMap.keySet(&predicate).size()); assertEqual(2, (int)txMap.values(&predicate).size()); context.commitTransaction(); assertEqual(2, (int)map.size()); assertEqual(2, (int)map.values().size()); }
TEST_F(ClientTxnQueueTest, testTransactionalOfferPoll1) { std::string name = "defQueue"; TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalQueue<std::string> q = context.getQueue<std::string>(name); ASSERT_TRUE(q.offer("ali")); ASSERT_EQ(1, q.size()); ASSERT_EQ("ali", *(q.poll())); ASSERT_EQ(0, q.size()); context.commitTransaction(); ASSERT_EQ(0, client->getQueue<std::string>(name).size()); }
void ClientTxnMapTest::testPutGet() { std::string name = "defMap"; TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalMap<std::string, std::string> map = context.getMap<std::string, std::string>(name); assertNull(map.put("key1", "value1").get()); assertEqual("value1", *(map.get("key1"))); assertNull(client->getMap<std::string, std::string>(name).get("key1").get()); context.commitTransaction(); assertEqual("value1", *(client->getMap<std::string, std::string>(name).get("key1"))); }
void ClientTxnSetTest::testAddRemove() { ISet<std::string> s = client->getSet<std::string>("testAddRemove"); s.add("item1"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalSet<std::string> set = context.getSet<std::string>("testAddRemove"); assertTrue(set.add("item2")); assertEqual(2, set.size()); assertEqual(1, s.size()); assertFalse(set.remove("item3")); assertTrue(set.remove("item1")); context.commitTransaction(); assertEqual(1, s.size()); }
TEST_F(ClientTxnQueueTest, testTransactionalOfferPoll2) { util::CountDownLatch latch(1); util::Thread t(testTransactionalOfferPoll2Thread, &latch, client.get()); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalQueue<std::string> q0 = context.getQueue<std::string>("defQueue0"); TransactionalQueue<std::string> q1 = context.getQueue<std::string>("defQueue1"); boost::shared_ptr<std::string> s; latch.countDown(); s = q0.poll(10 * 1000); ASSERT_EQ("item0", *s); ASSERT_TRUE(q1.offer(*s)); ASSERT_NO_THROW(context.commitTransaction()); ASSERT_EQ(0, client->getQueue<std::string>("defQueue0").size()); ASSERT_EQ("item0", *(client->getQueue<std::string>("defQueue1").poll())); }
void putGetRemoveTestThread(util::ThreadArgs& args) { MultiMap<std::string, std::string> *mm = (MultiMap<std::string, std::string > *)args.arg0; HazelcastClient *client = (HazelcastClient *)args.arg1; util::CountDownLatch *latch = (util::CountDownLatch *)args.arg2; std::string key = util::IOUtil::to_string(util::Thread::getThreadID()); client->getMultiMap<std::string, std::string>("testPutGetRemove").put(key, "value"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalMultiMap<std::string, std::string> originalMultiMap = context.getMultiMap<std::string, std::string >("testPutGetRemove"); client::adaptor::RawPointerTransactionalMultiMap<std::string, std::string> multiMap(originalMultiMap); ASSERT_FALSE(multiMap.put(key, "value")); ASSERT_TRUE(multiMap.put(key, "value1")); ASSERT_TRUE(multiMap.put(key, "value2")); ASSERT_EQ(3, (int)multiMap.get(key)->size()); context.commitTransaction(); ASSERT_EQ(3, (int)mm->get(key).size()); latch->countDown(); }
void ClientTxnMapTest::testKeySetValues() { std::string name = "testKeySetValues"; IMap<std::string, std::string> map = client->getMap<std::string, std::string>(name); map.put("key1", "value1"); map.put("key2", "value2"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalMap<std::string, std::string> txMap = context.getMap<std::string, std::string>(name); assertNull(txMap.put("key3", "value3").get()); assertEqual(3, (int)txMap.size()); assertEqual(3, (int)txMap.keySet().size()); assertEqual(3, (int)txMap.values().size()); context.commitTransaction(); assertEqual(3, (int)map.size()); assertEqual(3, (int)map.keySet().size()); assertEqual(3, (int)map.values().size()); }