예제 #1
0
 def test_remove_old_dashboard_data(self):
   zookeeper = flexmock()
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   dsg = flexmock(dsg)
   dsg.should_receive("register_db_accessor").and_return(FakeDistributedDB())
   dsg.DASHBOARD_DATA_MODELS = [FakeEntity]
   self.assertRaises(Exception, dsg.remove_old_dashboard_data)
예제 #2
0
 def test_initialize_kind(self):
   zookeeper = flexmock()
   flexmock(entity_pb).should_receive('EntityProto').and_return(FakeEntity())
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   dsg = flexmock(dsg)
   dsg.initialize_kind('app_id', 'kind')
   self.assertEquals(dsg.stats, {'app_id': {'kind': {'size': 0, 'number': 0}}}) 
예제 #3
0
 def test_create_global_stat_entry(self):
     zookeeper = flexmock()
     stats = flexmock(db.stats)
     stats.should_receive("KindStat").and_return(FakeEntity())
     dsg = groomer.DatastoreGroomer(zookeeper, "cassandra",
                                    "localhost:8888")
     self.assertRaises(Exception, dsg.create_kind_stat_entry, 0, 0, 0)
예제 #4
0
    def test_process_statistics(self):
        zookeeper = flexmock()
        flexmock(utils).should_receive("get_entity_kind").and_return("kind")

        dsg = groomer.DatastoreGroomer(zookeeper, "cassandra",
                                       "localhost:8888")
        dsg = flexmock(dsg)
        dsg.stats['app_id'] = {'kind': {'size': 0, 'number': 0}}

        # This one gets ignored
        dsg.should_receive("initialize_kind")
        self.assertEquals(True, dsg.process_statistics("key", FakeEntity(), 1))
        self.assertEquals(dsg.stats,
                          {'app_id': {
                              'kind': {
                                  'size': 1,
                                  'number': 1
                              }
                          }})
        self.assertEquals(True, dsg.process_statistics("key", FakeEntity(), 1))
        self.assertEquals(dsg.stats,
                          {'app_id': {
                              'kind': {
                                  'size': 2,
                                  'number': 2
                              }
                          }})
예제 #5
0
 def test_hard_delete_row(self):
     zookeeper = flexmock()
     dsg = groomer.DatastoreGroomer(zookeeper, "cassandra",
                                    "localhost:8888")
     dsg = flexmock(dsg)
     dsg.db_access = FakeDatastore()
     self.assertEquals(False, dsg.hard_delete_row("some_key"))
예제 #6
0
 def test_register_db_accessor(self):
   zookeeper = flexmock()
   fake_ds = FakeDatastore()
   flexmock(datastore_distributed).should_receive('DatastoreDistributed').\
     and_return(fake_ds)
   flexmock(apiproxy_stub_map.apiproxy).should_receive('RegisterStub')
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   self.assertEquals(fake_ds, dsg.register_db_accessor("app_id"))
예제 #7
0
 def test_remove_old_statistics(self):
   zookeeper = flexmock()
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   dsg = flexmock(dsg)
   dsg.should_receive("register_db_accessor").and_return(FakeDistributedDB())
   dsg.stats['app_id'] = {'kind': {'size': 0, 'number': 0}}
   dsg.stats['app_id1'] = {'kind': {'size': 0, 'number': 0}}
   self.assertRaises(Exception, dsg.remove_old_statistics)
예제 #8
0
 def test_reset_statistics(self):
     zookeeper = flexmock()
     flexmock(entity_pb).should_receive('EntityProto').and_return(
         FakeEntity())
     dsg = groomer.DatastoreGroomer(zookeeper, "cassandra",
                                    "localhost:8888")
     dsg.reset_statistics()
     self.assertEquals(dsg.stats, {})
예제 #9
0
  def test_process_entity(self):
    zookeeper = flexmock()
    flexmock(entity_pb).should_receive('EntityProto').and_return(FakeEntity())

    dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
    dsg = flexmock(dsg)
    dsg.should_receive('process_statistics')
    self.assertEquals(True,
      dsg.process_entity({'key':{dbconstants.APP_ENTITY_SCHEMA[0]:'ent',
      dbconstants.APP_ENTITY_SCHEMA[1]:'version'}}))
예제 #10
0
 def test_run_groomer(self):
   zookeeper = flexmock()
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   dsg = flexmock(dsg)
   dsg.should_receive("get_entity_batch").and_return([])
   dsg.should_receive("process_entity")
   dsg.should_receive("update_statistics").and_raise(Exception)
   dsg.should_receive("remove_old_logs").and_return()
   dsg.should_receive("remove_old_tasks_entities").and_return()
   ds_factory = flexmock(appscale_datastore_batch.DatastoreFactory)
   ds_factory.should_receive("getDatastore").and_return(FakeDatastore())
   self.assertRaises(Exception, dsg.run_groomer)
예제 #11
0
 def test_update_statistics(self):
   zookeeper = flexmock()
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   dsg = flexmock(dsg)
   dsg.should_receive("register_db_accessor").and_return(FakeDistributedDB())
   dsg.should_receive("create_global_stat_entry").and_return(True)
   dsg.should_receive("create_kind_stat_entry").and_return(True)
   dsg.stats['app_id'] = {'kind': {'size': 0, 'number': 0}}
   dsg.stats['app_id1'] = {'kind': {'size': 0, 'number': 0}}
   # Should loop twice and on the second raise an exception.
   self.assertEquals(True, dsg.update_statistics(datetime.datetime.now()))
   dsg.should_receive("create_kind_stat_entry").and_return(False)
   self.assertEquals(False, dsg.update_statistics(datetime.datetime.now()))
예제 #12
0
    def test_update_statistics(self):
        zookeeper = flexmock()
        dsg = groomer.DatastoreGroomer(zookeeper, "cassandra",
                                       "localhost:8888")
        dsg = flexmock(dsg)
        dsg.should_receive("register_db_accessor").and_return(
            FakeDistributedDB())
        dsg.should_receive("create_global_stat_entry").and_return(True)
        dsg.should_receive("create_kind_stat_entry")
        dsg.stats['app_id'] = {'kind': {'size': 0, 'number': 0}}
        dsg.stats['app_id1'] = {'kind': {'size': 0, 'number': 0}}

        dsg.update_statistics(datetime.datetime.now())
        dsg.should_receive("create_kind_stat_entry").\
          and_raise(datastore_errors.BadRequestError)
        # BadRequestErrors should be ignored when generating stats because they are
        # expected for undeployed projects and it's better to continue generating
        # stats for other projects rather than stopping altogether.
        dsg.update_statistics(datetime.datetime.now())
예제 #13
0
 def test_get_groomer_lock(self):
   zookeeper = flexmock()
   zookeeper.should_receive("get_lock_with_path").and_return(True)
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")
   self.assertEquals(True, dsg.get_groomer_lock())
예제 #14
0
 def test_init(self):
   zookeeper = flexmock()
   dsg = groomer.DatastoreGroomer(zookeeper, "cassandra", "localhost:8888")