Esempio n. 1
0
/// Test the real memcached server.  Alternate version that doesn't expect to work.
TEST_F(MemcachedStoreTest, SimpleMemcachedAlt)
{
  SCOPED_TRACE("memcached");
  Store* store;

  // Test 2.1 - create a MemcachedStore instance and connect to a single server.
  std::list<std::string> servers;
  servers.push_back(std::string("localhost:11209"));
  store = create_memcached_store(servers, 10);

  // Test 2.2 - flush the server.
  store->flush_all();

  // Test 2.3 - get an initial empty AoR record and add a binding.
  AoR* aor_data1 = store->get_aor_data(std::string("*****@*****.**"));
  ASSERT_EQ(NULL, aor_data1);

  // Test 2.8 - destroy the MemcachedStore instance.
  destroy_memcached_store(store);
}
Esempio n. 2
0
/// Test the server.
void MemcachedStoreTest::do_test_simple(Store& store)
{
  AoR* aor_data1;
  AoR::Bindings::const_iterator i1;
  AoR::Bindings::const_iterator i2;
  AoR::Binding* b1;
  bool rc;
  int now;
  std::string s;

  // Test sequence 2 - getting/setting/querying a single registration for a single AoR

  // Test 2.2 - flush the server.
  store.flush_all();

  // Test 2.3 - get an initial empty AoR record and add a binding.
  now = time(NULL);
  aor_data1 = store.get_aor_data(std::string("*****@*****.**"));
  ASSERT_TRUE(aor_data1 != NULL);
  EXPECT_EQ(0u, aor_data1->bindings().size());
  b1 = aor_data1->get_binding(std::string("urn:uuid:00000000-0000-0000-0000-b4dd32817622:1"));
  b1->_uri = std::string("<sip:[email protected]:59934;transport=tcp;ob>");
  b1->_cid = std::string("gfYHoZGaFaRNxhlV0WIwoS-f91NoJ2gq");
  b1->_cseq = 17038;
  b1->_expires = now + 300;
  b1->_priority = 0;
  b1->_params.push_back(std::make_pair("+sip.instance", "\"<urn:uuid:00000000-0000-0000-0000-b4dd32817622>\""));
  b1->_params.push_back(std::make_pair("reg-id", "1"));
  b1->_params.push_back(std::make_pair("+sip.ice", ""));

  // Test 2.4 - add the AoR record to the server.
  rc = store.set_aor_data(std::string("*****@*****.**"), aor_data1);
  EXPECT_TRUE(rc);
  delete aor_data1;

  // Test 2.5 - get the AoR record from the server.
  aor_data1 = store.get_aor_data(std::string("*****@*****.**"));
  EXPECT_EQ(1u, aor_data1->bindings().size());
  EXPECT_EQ(std::string("urn:uuid:00000000-0000-0000-0000-b4dd32817622:1"), aor_data1->bindings().begin()->first);
  b1 = aor_data1->bindings().begin()->second;
  EXPECT_EQ(std::string("<sip:[email protected]:59934;transport=tcp;ob>"), b1->_uri);
  EXPECT_EQ(std::string("gfYHoZGaFaRNxhlV0WIwoS-f91NoJ2gq"), b1->_cid);
  EXPECT_EQ(17038, b1->_cseq);
  EXPECT_EQ(now + 300, b1->_expires);
  EXPECT_EQ(0, b1->_priority);

  // Test 2.6 - update AoR record at the server and check it.
  b1->_cseq = 17039;
  rc = store.set_aor_data(std::string("*****@*****.**"), aor_data1);
  EXPECT_TRUE(rc);
  delete aor_data1;
  aor_data1 = store.get_aor_data(std::string("*****@*****.**"));
  EXPECT_EQ(1u, aor_data1->bindings().size());
  EXPECT_EQ(std::string("urn:uuid:00000000-0000-0000-0000-b4dd32817622:1"), aor_data1->bindings().begin()->first);
  b1 = aor_data1->bindings().begin()->second;
  EXPECT_EQ(std::string("<sip:[email protected]:59934;transport=tcp;ob>"), b1->_uri);
  EXPECT_EQ(std::string("gfYHoZGaFaRNxhlV0WIwoS-f91NoJ2gq"), b1->_cid);
  EXPECT_EQ(17039, b1->_cseq);
  EXPECT_EQ(now + 300, b1->_expires);
  EXPECT_EQ(0, b1->_priority);

  // Test 2.7 - update AoR record again at the server and check it, this time using get_binding.
  b1->_cseq = 17040;
  rc = store.set_aor_data(std::string("*****@*****.**"), aor_data1);
  EXPECT_TRUE(rc);
  delete aor_data1;
  aor_data1 = store.get_aor_data(std::string("*****@*****.**"));
  EXPECT_EQ(1u, aor_data1->bindings().size());
  b1 = aor_data1->get_binding(std::string("urn:uuid:00000000-0000-0000-0000-b4dd32817622:1"));
  EXPECT_EQ(std::string("<sip:[email protected]:59934;transport=tcp;ob>"), b1->_uri);
  EXPECT_EQ(std::string("gfYHoZGaFaRNxhlV0WIwoS-f91NoJ2gq"), b1->_cid);
  EXPECT_EQ(17040, b1->_cseq);
  EXPECT_EQ(now + 300, b1->_expires);
  EXPECT_EQ(0, b1->_priority);

  // Now check the maximum expiry is what we think.
  int max_exp = store.expire_bindings(aor_data1, now + 299);
  EXPECT_EQ(1u, aor_data1->bindings().size());
  EXPECT_EQ(now + 300, max_exp);

  // Now expire a binding by pretending the time is in the future.
  max_exp = store.expire_bindings(aor_data1, now + 301);
  EXPECT_EQ(0u, aor_data1->bindings().size());
  EXPECT_EQ(now + 301, max_exp);

  delete aor_data1;
}