Esempio n. 1
0
File: perf.py Progetto: bgnori/tonic
class PerfMemcached(Perf):
  def setUp(self):
    IP = '127.0.0.1'
    PORT = 22222
    self.memcached = MemcacheTestingServer(IP, PORT)
    hub.connect('memcache', ['%s:%i'%(IP, PORT)])
  def tearDown(self):
    hub.purge()
    self.memcached.close()
Esempio n. 2
0
File: test.py Progetto: bgnori/tonic
class MemcacheTestingServerTest(unittest.TestCase):
  def testA(self):
    ip = '127.0.0.1'
    port = 22222
    self.server = MemcacheTestingServer(ip, port)
    self.assertEqual(self.server.s , 
          '/usr/bin/memcached -l 127.0.0.1 -p 22222')
    self.server.close()

  def testB(self):
    ip = '127.0.0.1'
    port = 22222
    self.server = MemcacheTestingServer(ip, port, memory=2048)
    self.assertEqual(self.server.s , 
          '/usr/bin/memcached -l 127.0.0.1 -p 22222 -m 2048')
    self.server.close()
Esempio n. 3
0
File: test.py Progetto: bgnori/tonic
class MemcacheTest(unittest.TestCase):
  def setUp(self):
    ip = '127.0.0.1'
    port = 22222
    self.server = MemcacheTestingServer(ip, port)
    hub.connect(Memcache(['%s:%i'%(ip, port)]))
    
  def tearDown(self):
    hub.purge()
    hub.close()
    self.server.close()

  def test_HelloWorld(self):
    hw = 'Hello World!'
    hub.set('test1', hw)
    time.sleep(0.01) #wait for cache to be written
    value = hub.get('test1')
    mtime = hub.mtime('test1')
    now = time.time()
    self.assertAlmostEqual(now, mtime, 1)
    self.assertEqual(value, hw)

  def test_purge(self):
    hw = 'Hello World!'
    hub.set('test1', hw)
    time.sleep(0.01) #wait for cache to be written
    hub.purge()
    try:
      value = hub.get('test1')
      self.assert_(False)
    except NotInCache:
      pass

  def test_mtime(self):
    hw = 'Hello World!'
    zero = 0.0 #time.ctime(0)
    hub.set('test1', hw, mtime=zero)
    mtime = hub.mtime('test1')
    value = hub.get('test1')
    self.assert_(zero - mtime < 1.0) #disk acess is so slow.
    self.assertEqual(value, hw)

    try:
      value = hub.mtime('test2')
    except NotInCache:
      pass