def populate_db(sqluri, service, nodes, user_range, host="loadtest.local"): """Create a bunch of users for the given service. The resulting users will have an adress in the form of <uid>@<host> where uid is an int from 0 to :param user_range:. This function is useful to populate the database during the loadtest. It allows to test a specific behaviour: making sure that we are not reading the values from memory when retrieving the node information. :param sqluri: the sqluri string used to connect to the database :param service: the service to assign the users to. :param nodes: the list of availables nodes for this service :param user_range: the number of users to create :param host: the hostname to use when generating users """ params = { 'service': service, 'generation': 0, 'client_state': '', 'timestamp': int(time.time() * 1000), } # for each user in the range, assign him to a node md = SQLMetadata(sqluri, create_tables=True) for idx in range(0, user_range): email = "%s@%s" % (idx, host) node = random.choice(nodes) md._safe_execute(_CREATE_USER_RECORD, email=email, node=node, **params)
def setUp(self): super(TestSQLDB, self).setUp() self.backend = SQLMetadata(_SQLURI, create_tables=True) # adding a node with 100 slots self.backend._safe_execute( """insert into nodes (`node`, `service`, `available`, `capacity`, `current_load`, `downed`, `backoff`) values ("phx12", "sync", 100, 100, 0, 0, 0)""") self._sqlite = self.backend._engine.driver == 'pysqlite'
def setUp(self): self.backend = SQLMetadata(self._SQLURI, create_tables=True) super(TestSQLDB, self).setUp()