skocic/server-farm

服务器农场中服务器和虚拟机分配的模拟

v1.0 2017-04-09 10:44 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:14:42 UTC


README

服务器农场中服务器和虚拟机分配的模拟

Build Status Code Style Status CodeCov CodeClimate Issue Count Issue Count

安装

使用 Composer 安装。运行以下命令

composer install

使用方法

使用方法可以从测试中看到。

本质上,我们通过指定 maximum 服务器规格(cpu、ram和hdd大小)来创建一个 ServerFarm 对象。我们创建一个虚拟机数组并通过 storeVmachines 存储它们(大于 maximum 的将被跳过),然后我们

  • 使用 getServers() 读取分配的机器数组
  • 使用 count() 获取数量
  • 使用 toString() 查看详细的分配列表
$vmArray = [
    new VmachineModel(1, 1, 2),
    new VmachineModel(2, 2, 1),
    new VmachineModel(3, 4, 3),
    new VmachineModel(2, 1, 2),
];
$sf = new ServerFarmModel(ServerModel::create(5, 6, 7));
$sf->storeVmachines($vmArray);
$actual = $sf->toString();
$expected = "Server list\n"
    . "1. VM(1 MHz, 1 GB, 2 GB) VM(2 MHz, 2 GB, 1 GB) remains VM(1 MHz, 3 GB, 4 GB)\n"
    . "2. VM(3 MHz, 4 GB, 3 GB) remains VM(1 MHz, 2 GB, 4 GB)\n"
    . "3. VM(2 MHz, 1 GB, 2 GB) remains VM(2 MHz, 5 GB, 5 GB)\n";
$this->assertSame($expected, $actual);
$n = $sf->count();
$this->assertSame(3, $n);

测试

  1. 运行测试前,需要安装 Composer。全局安装 composer,然后运行 composer install 以安装所需的文件。
  2. 从根目录运行此命令可以执行测试
$ ./vendor/bin/phpunit

贡献

请参阅 CONTRIBUTING 了解详细信息。

许可

有关更多信息,请参阅 许可文件