def txn(): s = Session( id=self._get_or_create_session_key(), session_key=self.session_key, session_data=self.encode(session_data), expire_date=self.get_expiry_date() ) s.put()
def test_mapper_batch_size(self): """ Test the amount of sessions gets deleted is the same as the deferred_batch_size """ for i in range(0,20): s = Session(session_key='%s' % i, expire_date=datetime.utcnow()) s.put() mapper = DeleteMapper(Session, filters = {'lt': ('expire_date', datetime.utcnow())}, deferred_batch_size=10) mapper.transaction() #taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) # Should be 10 left self.assertEquals(Session.query().count(), 10) mapper.transaction() # Should be 0 session left self.assertEquals(Session.query().count(), 0)
def test_mapper(self): """ Test a session gets deleted and another one has been put on as a task to be deleted """ for i in range(0,2): s = Session(session_key='%s' % i, expire_date=datetime.utcnow()) s.put() mapper = DeleteMapper(Session, filters = {'lt': ('expire_date', datetime.utcnow())}, deferred_batch_size=1) mapper.transaction() taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) # One expired session left self.assertEquals(Session.query().count(), 1) tasks=taskqueue.GetTasks(mapper.queue) # Another deferred task in the queue to remove the next expired session self.assertEquals(len(tasks),1)
def test_mapper_batch_size(self): """ Test the amount of sessions gets deleted is the same as the deferred_batch_size """ for i in range(0, 20): s = Session(session_key="%s" % i, expire_date=datetime.utcnow()) s.put() mapper = DeleteMapper(Session, filters={"lt": ("expire_date", datetime.utcnow())}, deferred_batch_size=10) mapper.transaction() # taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) # Should be 10 left self.assertEquals(Session.query().count(), 10) mapper.transaction() # Should be 0 session left self.assertEquals(Session.query().count(), 0)
def test_mapper(self): """ Test a session gets deleted and another one has been put on as a task to be deleted """ for i in range(0, 2): s = Session(session_key="%s" % i, expire_date=datetime.utcnow()) s.put() mapper = DeleteMapper(Session, filters={"lt": ("expire_date", datetime.utcnow())}, deferred_batch_size=1) mapper.transaction() taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) # One expired session left self.assertEquals(Session.query().count(), 1) tasks = taskqueue.GetTasks(mapper.queue) # Another deferred task in the queue to remove the next expired session self.assertEquals(len(tasks), 1)
def test_mapper_session_data(self): """ Test the mapper only deletes the expired session and doesn't create a new task on queue """ s1 = Session(session_key='1', expire_date=datetime.utcnow() + timedelta(seconds=3600)) s1.put() s2 = Session(session_key='2', expire_date=datetime.utcnow()) s2.put() mapper = DeleteMapper(Session, filters = {'lt': ('expire_date', datetime.utcnow())}, deferred_batch_size=1) mapper.transaction() taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) tasks=taskqueue.GetTasks(mapper.queue) # Should be no task in the queue as # no more sessions to delete. self.assertEquals(len(tasks),0) # Should be 1 valid session left self.assertEquals(Session.query().count(), 1) self.assertEquals(Session.query().get().session_key,'1')
def test_mapper_session_data(self): """ Test the mapper only deletes the expired session and doesn't create a new task on queue """ s1 = Session(session_key="1", expire_date=datetime.utcnow() + timedelta(seconds=3600)) s1.put() s2 = Session(session_key="2", expire_date=datetime.utcnow()) s2.put() mapper = DeleteMapper(Session, filters={"lt": ("expire_date", datetime.utcnow())}, deferred_batch_size=1) mapper.transaction() taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME) tasks = taskqueue.GetTasks(mapper.queue) # Should be no task in the queue as # no more sessions to delete. self.assertEquals(len(tasks), 0) # Should be 1 valid session left self.assertEquals(Session.query().count(), 1) self.assertEquals(Session.query().get().session_key, "1")
def txn(): s = Session(id=self._get_or_create_session_key(), session_key=self.session_key, session_data=self.encode(session_data), expire_date=self.get_expiry_date()) s.put()