示例#1
0
class VerifierTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.hubTasks = HubTasks(BatchUser(), self.client)
        self.hubTasks.start()

    @task(10000)
    def write(self):
        bulk = ""
        for x in range(0, 50):
            bulk += "--abcdefg\r\n"
            bulk += "Content-Type: application/json\r\n\r\n"
            bulk += '{"name":"' + self.hubTasks.payload + '", "count": ' + str(
                self.hubTasks.count) + '}\r\n'
            self.hubTasks.count += 1
        bulk += "--abcdefg--\r\n"

        with self.client.post(
                "/channel/" + self.hubTasks.channel + "/bulk",
                data=bulk,
                headers={"Content-Type": "multipart/mixed; boundary=abcdefg"},
                catch_response=True,
                name="post_bulk") as postResponse:
            if postResponse.status_code != 201:
                postResponse.failure("Got wrong response on post: " +
                                     str(postResponse.status_code))

        links = postResponse.json()

        uris = links['_links']['uris']
        for uri in uris:
            self.hubTasks.append_href(uri)
        # todo add read functionality
        return uris

    @task(10)
    def next_10(self):
        self.hubTasks.next_10()

    @task(10)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length(50000)

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        return HubTasks.callback(channel)
示例#2
0
class VerifierTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.hubTasks = HubTasks(VerifierUser(), self.client)
        self.hubTasks.start()

    @task(1000)
    def write_read(self):
        self.hubTasks.write_read()

    @task(50)
    def change_parallel(self):
        self.hubTasks.change_parallel("verifier_test_2")

    @task(100)
    def sequential(self):
        self.hubTasks.sequential()

    @task(1)
    def hour_query(self):
        self.hubTasks.hour_query()

    @task(1)
    def hour_query_get_items(self):
        self.hubTasks.hour_query_get_items()

    @task(1)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(1)
    def minute_query_get_items(self):
        self.hubTasks.minute_query_get_items()

    @task(10)
    def next_previous(self):
        self.hubTasks.next_previous()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        return HubTasks.callback(channel)
示例#3
0
class HistoricalTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.user = HistoricalUser()
        self.hubTasks = HubTasks(self.user, self.client)
        self.hubTasks.start()

    @task(1000)
    def write_read(self):
        self.hubTasks.write_read()

    @task(1)
    def hour_query(self):
        self.hubTasks.hour_query()

    @task(1)
    def hour_query_get_items(self):
        self.hubTasks.hour_query_get_items()

    @task(1)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(1)
    def minute_query_get_items(self):
        self.hubTasks.minute_query_get_items()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def next_previous(self):
        self.hubTasks.next_previous()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        logger.debug(
            utils.get_client_address(request) + ' | ' + request.method +
            ' | /callback')
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        logger.debug(
            utils.get_client_address(request) + ' | ' + request.method +
            ' | /callback/' + channel + ' | ' + request.get_data().strip())
        return HubTasks.callback(channel)
示例#4
0
class HistoricalTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.user = HistoricalUser()
        self.hubTasks = HubTasks(self.user, self.client)
        self.hubTasks.start()

    @task(1000)
    def write_read(self):
        self.hubTasks.write_read()

    @task(1)
    def hour_query(self):
        self.hubTasks.hour_query()

    @task(1)
    def hour_query_get_items(self):
        self.hubTasks.hour_query_get_items()

    @task(1)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(1)
    def minute_query_get_items(self):
        self.hubTasks.minute_query_get_items()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def next_previous(self):
        self.hubTasks.next_previous()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        return HubTasks.callback(channel)
示例#5
0
class VerifierTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.hubTasks = HubTasks(SingleUser(), self.client)
        self.hubTasks.start()

    @task(1000)
    def write_read(self):
        self.hubTasks.write_read()

    @task(10)
    def hour_query(self):
        self.hubTasks.hour_query()

    @task(10)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def next_previous(self):
        self.hubTasks.next_previous()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length(20000)

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback')
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback/' + channel + ' | ' + request.get_data().strip())
        return HubTasks.callback(channel)

    @web.app.route('/store/<name>', methods=['GET'])
    def get_store(name):
        return Response(HubTasks.get_store(name), mimetype='application/json')
示例#6
0
class VerifierTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.hubTasks = HubTasks(BatchUser(), self.client)
        self.hubTasks.start()

    @task(10000)
    def write(self):
        bulk = ""
        for x in range(0, 50):
            bulk += "--abcdefg\r\n"
            bulk += "Content-Type: application/json\r\n\r\n"
            bulk += '{"name":"' + self.hubTasks.payload + '", "count": ' + str(self.hubTasks.count) + '}\r\n'
            self.hubTasks.count += 1
        bulk += "--abcdefg--\r\n"

        with self.client.post("/channel/" + self.hubTasks.channel + "/bulk", data=bulk,
                              headers={"Content-Type": "multipart/mixed; boundary=abcdefg"}, catch_response=True,
                              name="post_bulk") as postResponse:
            if postResponse.status_code != 201:
                postResponse.failure("Got wrong response on post: " + str(postResponse.status_code))

        links = get_response_as_json(postResponse)
        logger.debug('item POSTed: ' + links['_links']['self']['href'])

        uris = links['_links']['uris']
        for uri in uris:
            self.hubTasks.append_href(uri, 'websockets')
            self.hubTasks.append_href(uri, 'webhooks')
        # todo add read functionality
        return uris

    @task(10)
    def next_10(self):
        self.hubTasks.next_10()

    @task(10)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length(50000)

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback')
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback/' + channel + ' | ' + request.get_data().strip())
        return HubTasks.callback(channel)

    @web.app.route('/store/<name>', methods=['GET'])
    def get_store(name):
        return Response(HubTasks.get_store(name), mimetype='application/json')
示例#7
0
class VerifierTasks(TaskSet):
    hubTasks = None

    def on_start(self):
        self.hubTasks = HubTasks(VerifierUser(), self.client)
        self.hubTasks.start()

    @task(1000)
    def write_read(self):
        self.hubTasks.write_read()

    @task(5)
    def change_parallel(self):
        self.hubTasks.change_parallel("verifier_test_2")

    @task(100)
    def sequential(self):
        self.hubTasks.sequential()

    @task(1)
    def earliest(self):
        self.hubTasks.earliest()

    @task(100)
    def latest(self):
        self.hubTasks.latest()

    @task(10)
    def day_query(self):
        self.hubTasks.day_query()

    @task(1)
    def hour_query(self):
        self.hubTasks.hour_query()

    @task(1)
    def hour_query_get_items(self):
        self.hubTasks.hour_query_get_items()

    @task(1)
    def minute_query(self):
        self.hubTasks.minute_query()

    @task(1)
    def minute_query_get_items(self):
        self.hubTasks.minute_query_get_items()

    @task(10)
    def next_previous(self):
        self.hubTasks.next_previous()

    @task(10)
    def second_query(self):
        self.hubTasks.second_query()

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback')
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback/' + channel + ' | ' + request.get_data().strip())
        return HubTasks.callback(channel)

    @web.app.route('/store/<name>', methods=['GET'])
    def get_store(name):
        return Response(HubTasks.get_store(name), mimetype='application/json')
示例#8
0
class LargeTasks(TaskSet):
    hubTasks = None
    first = True

    def on_start(self):
        self.hubTasks = HubTasks(LargeUser(), self.client)
        self.hubTasks.start()

    def large_file_name(self, number, direction):
        return '/mnt/large' + str(number) + '.' + direction

    # todo have this create a replicated channel

    @task(100)
    def write(self):
        if self.first:
            self.create_large(self.hubTasks)
            self.first = False
        large_file_name = self.large_file_name(self.hubTasks.number, 'out')
        large_file = open(large_file_name, 'rb')
        expected_size = os.stat(large_file_name).st_size
        threads = "8"
        with self.hubTasks.client.post(
                self.hubTasks.get_channel_url() + "?threads=" + threads,
                data=large_file,
                headers={"content-type": "application/octet-stream"},
                catch_response=True,
                name="post_payload_" + threads) as postResponse:
            if postResponse.status_code != 201:
                postResponse.failure("Got wrong response on post: " +
                                     str(postResponse.status_code) +
                                     self.hubTasks.get_channel_url())
            else:
                uri = postResponse.json()['_links']['self']['href']
                with self.client.get(uri,
                                     stream=True,
                                     catch_response=True,
                                     name="get_payload") as getResponse:
                    if getResponse.status_code != 200:
                        getResponse.failure("Got wrong response on get: " +
                                            str(getResponse.status_code) +
                                            " " + uri)
                    inputFile = self.large_file_name(self.hubTasks.number,
                                                     'in')
                    with open(inputFile, 'wb') as fd:
                        for chunk in getResponse.iter_content(chunk_size=1024):
                            if chunk:
                                fd.write(chunk)
                    get_size = os.stat(inputFile).st_size
                    if get_size == expected_size:
                        print "Got expected size on get: " + str(
                            get_size) + " " + uri
                    else:
                        getResponse.failure("Got wrong size on get: " +
                                            str(get_size) + " " + uri)

    def create_large(self, tasks):
        large_file_name = self.large_file_name(self.hubTasks.number, 'out')
        if os.path.isfile(large_file_name):
            print "using existing file " + large_file_name + " bytes=" + str(
                os.stat(large_file_name).st_size)
            return
        if tasks.number == 1:
            target = open(large_file_name, 'w')
            print "writing file " + large_file_name
            target.truncate(0)
            chars = string.ascii_uppercase + string.digits
            size = 50 * 1024
            for x in range(0, 10 * 1024):
                target.write(''.join(
                    random.choice(chars) for i in range(size)))
                target.flush()

            print "closing " + large_file_name
            target.close()
        elif tasks.number == 2:
            os.system("cat /mnt/large1.out /mnt/large1.out > /mnt/large2.out")
        elif tasks.number == 3:
            os.system("cat /mnt/large2.out /mnt/large2.out > /mnt/large3.out")

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        return HubTasks.callback(channel)
示例#9
0
文件: large.py 项目: flightstats/hub
class LargeTasks(TaskSet):
    hubTasks = None
    first = True

    def on_start(self):
        self.hubTasks = HubTasks(LargeUser(), self.client)
        self.hubTasks.start()

    def large_file_name(self, number, direction):
        return '/mnt/large' + str(number) + '.' + direction

    # todo have this create a replicated channel

    @task(100)
    def write(self):
        if self.first:
            self.create_large(self.hubTasks)
            self.first = False
        large_file_name = self.large_file_name(self.hubTasks.number, 'out')
        large_file = open(large_file_name, 'rb')
        expected_size = os.stat(large_file_name).st_size
        threads = "8"
        with self.hubTasks.client.post(self.hubTasks.get_channel_url() + "?threads=" + threads,
                                       data=large_file,
                                       headers={"content-type": "application/octet-stream"},
                                       catch_response=True,
                                       name="post_payload_" + threads) as postResponse:
            if postResponse.status_code != 201:
                postResponse.failure("Got wrong response on post: " + str(postResponse.status_code)
                                     + self.hubTasks.get_channel_url())
            else:
                uri = postResponse.json()['_links']['self']['href']
                logger.debug('item POSTed: ' + uri)
                with self.client.get(uri, stream=True, catch_response=True, name="get_payload") as getResponse:
                    if getResponse.status_code != 200:
                        getResponse.failure("Got wrong response on get: " + str(getResponse.status_code) + " " + uri)
                    inputFile = self.large_file_name(self.hubTasks.number, 'in')
                    with open(inputFile, 'wb') as fd:
                        for chunk in getResponse.iter_content(chunk_size=1024):
                            if chunk:
                                fd.write(chunk)
                    get_size = os.stat(inputFile).st_size
                    if get_size == expected_size:
                        logger.info("Got expected size on get: " + str(get_size) + " " + uri)
                    else:
                        getResponse.failure("Got wrong size on get: " + str(get_size) + " " + uri)

    def create_large(self, tasks):
        large_file_name = self.large_file_name(self.hubTasks.number, 'out')
        if os.path.isfile(large_file_name):
            logger.info("using existing file " + large_file_name + " bytes=" + str(os.stat(large_file_name).st_size))
            return
        if tasks.number == 1:
            target = open(large_file_name, 'w')
            logger.info("writing file " + large_file_name)
            target.truncate(0)
            chars = string.ascii_uppercase + string.digits
            size = 50 * 1024
            for x in range(0, 10 * 1024):
                target.write(''.join(random.choice(chars) for i in range(size)))
                target.flush()

            logger.info("closing " + large_file_name)
            target.close()
        elif tasks.number == 2:
            os.system("cat /mnt/large1.out /mnt/large1.out > /mnt/large2.out")
        elif tasks.number == 3:
            os.system("cat /mnt/large2.out /mnt/large2.out > /mnt/large3.out")

    @task(10)
    def verify_callback_length(self):
        self.hubTasks.verify_callback_length()

    @web.app.route("/callback", methods=['GET'])
    def get_channels():
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback')
        return HubTasks.get_channels()

    @web.app.route("/callback/<channel>", methods=['GET', 'POST'])
    def callback(channel):
        logger.debug(utils.get_client_address(request) + ' | ' + request.method + ' | /callback/' + channel + ' | ' + request.get_data().strip())
        return HubTasks.callback(channel)

    @web.app.route('/store/<name>', methods=['GET'])
    def get_store(name):
        return Response(HubTasks.get_store(name), mimetype='application/json')