Example #1
0
    def test_assign_free_threads(self):
        cpu = get_cpu()
        workload = get_test_workload("a", 2, STATIC)
        workloads = {workload.get_id(): workload}

        cpu_allocator = GreedyCpuAllocator()
        self.__set_cpu_allocator(cpu_allocator)

        # Assign threads
        log.info("Assign threads")
        cpu_in_0 = copy.deepcopy(cpu)
        request = AllocateThreadsRequest(cpu_in_0, workload.get_id(),
                                         workloads, {},
                                         DEFAULT_TEST_REQUEST_METADATA)
        cpu_out_0 = cpu_allocator.assign_threads(request).get_cpu()

        cpu_in_1 = copy.deepcopy(cpu)
        body = AllocateThreadsRequest(cpu_in_1, workload.get_id(), workloads,
                                      {},
                                      DEFAULT_TEST_REQUEST_METADATA).to_dict()
        cpu_out_1 = self.client.put("/assign_threads",
                                    data=json.dumps(body),
                                    content_type='application/json')
        cpu_out_1 = deserialize_response(cpu_out_1.headers,
                                         cpu_out_1.json).get_cpu()

        log.info("cpu_out_0: {}".format(cpu_out_0))
        log.info("cpu_out_1: {}".format(cpu_out_1))
        self.assertEqual(cpu_out_0.to_dict(), cpu_out_1.to_dict())

        # Free threads
        log.info("Free threads")
        cpu_in_0 = copy.deepcopy(cpu_out_0)
        request = AllocateThreadsRequest(cpu_in_0, workload.get_id(),
                                         workloads, {},
                                         DEFAULT_TEST_REQUEST_METADATA)
        cpu_out_0 = cpu_allocator.free_threads(request).get_cpu()

        cpu_in_1 = copy.deepcopy(cpu_out_1)
        body = AllocateThreadsRequest(cpu_in_1, workload.get_id(), workloads,
                                      {},
                                      DEFAULT_TEST_REQUEST_METADATA).to_dict()
        cpu_out_1 = self.client.put("/free_threads",
                                    data=json.dumps(body),
                                    content_type='application/json')
        cpu_out_1 = deserialize_response(cpu_out_1.headers,
                                         cpu_out_1.json).get_cpu()

        log.info("cpu_out_0: {}".format(cpu_out_0))
        log.info("cpu_out_1: {}".format(cpu_out_1))
        self.assertEqual(cpu_out_0.to_dict(), cpu_out_1.to_dict())
Example #2
0
    def test_assign_free_threads(self):
        cpu = get_cpu()
        workload = get_test_workload("a", 2, STATIC)

        cpu_allocator = GreedyCpuAllocator()
        self.__set_cpu_allocator(cpu_allocator)

        # Assign threads
        log.info("Assign threads")
        cpu_in_0 = copy.deepcopy(cpu)
        request = get_no_usage_threads_request(cpu_in_0, [workload])
        cpu_out_0 = cpu_allocator.assign_threads(request).get_cpu()

        cpu_in_1 = copy.deepcopy(cpu)
        request = get_no_usage_threads_request(cpu_in_1, [workload])
        cpu_out_1 = self.client.put(
            "/assign_threads",
            data=json.dumps(request.to_dict()),
            content_type='application/json')
        cpu_out_1 = deserialize_response(cpu_out_1.headers, cpu_out_1.json).get_cpu()

        log.info("cpu_out_0: {}".format(cpu_out_0))
        log.info("cpu_out_1: {}".format(cpu_out_1))
        self.assertEqual(cpu_out_0.to_dict(), cpu_out_1.to_dict())

        # Free threads
        log.info("Free threads")
        cpu_in_0 = copy.deepcopy(cpu_out_0)
        request = get_no_usage_threads_request(cpu_in_0, [workload])
        cpu_out_0 = cpu_allocator.free_threads(request).get_cpu()

        cpu_in_1 = copy.deepcopy(cpu_out_1)
        request = get_no_usage_threads_request(cpu_in_1, [workload])
        cpu_out_1 = self.client.put(
            "/free_threads",
            data=json.dumps(request.to_dict()),
            content_type='application/json')
        cpu_out_1 = deserialize_response(cpu_out_1.headers, cpu_out_1.json).get_cpu()

        log.info("cpu_out_0: {}".format(cpu_out_0))
        log.info("cpu_out_1: {}".format(cpu_out_1))
        self.assertEqual(cpu_out_0.to_dict(), cpu_out_1.to_dict())