MS-348 Add ResourceFactory Test

Former-commit-id: 2b8519881eb88c532b0a02f7f515f345545cd55c
This commit is contained in:
wxyu 2019-08-13 20:18:21 +08:00
parent cb67c47874
commit a0c52e3730
5 changed files with 40 additions and 2 deletions

View File

@ -7,6 +7,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-344 - Add TaskTable Test
- MS-345 - Add Node Test
- MS-346 - Add some implementation of scheduler to solve compile error
- MS-348 - Add ResourceFactory Test
## Bug

View File

@ -14,11 +14,11 @@ namespace engine {
std::shared_ptr<Resource>
ResourceFactory::Create(const std::string &name, const std::string &alias) {
if (name == "disk") {
return std::make_shared<CpuResource>(alias);
return std::make_shared<DiskResource>(alias);
} else if (name == "cpu") {
return std::make_shared<CpuResource>(alias);
} else if (name == "gpu") {
return std::make_shared<CpuResource>(alias);
return std::make_shared<GpuResource>(alias);
} else {
return nullptr;
}

View File

@ -14,6 +14,17 @@ namespace milvus {
namespace engine {
class DiskResource : public Resource {
public:
explicit
DiskResource(std::string name)
: Resource(std::move(name), ResourceType::DISK) {}
protected:
void
LoadFile(TaskPtr task) override {}
void
Process(TaskPtr task) override {}
};
}

View File

@ -14,6 +14,17 @@ namespace milvus {
namespace engine {
class GpuResource : public Resource {
public:
explicit
GpuResource(std::string name)
: Resource(std::move(name), ResourceType::GPU) {}
protected:
void
LoadFile(TaskPtr task) override {}
void
Process(TaskPtr task) override {}
};
}

View File

@ -0,0 +1,15 @@
#include "scheduler/ResourceFactory.h"
#include <gtest/gtest.h>
using namespace zilliz::milvus::engine;
TEST(resource_factory_test, create) {
auto disk = ResourceFactory::Create("disk");
auto cpu = ResourceFactory::Create("cpu");
auto gpu = ResourceFactory::Create("gpu");
ASSERT_TRUE(std::dynamic_pointer_cast<DiskResource>(disk));
ASSERT_TRUE(std::dynamic_pointer_cast<CpuResource>(cpu));
ASSERT_TRUE(std::dynamic_pointer_cast<GpuResource>(gpu));
}