test_message_op.cpp 1.6 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include "test_tool.h"
#include "test_message_op.h"
#include "framework/manager.h"
#include "framework/service.h"
#include "framework/dag.h"

namespace baidu {
namespace paddle_serving {
namespace unittest {

using baidu::paddle_serving::predictor::Manager;
using baidu::paddle_serving::predictor::InferService;
using baidu::paddle_serving::predictor::ParallelInferService;
using baidu::paddle_serving::predictor::FLAGS_use_parallel_infer_service;
using baidu::paddle_serving::predictor::InferServiceManager;
using baidu::paddle_serving::predictor::Bus;
using baidu::paddle_serving::predictor::Dag;
using baidu::paddle_serving::predictor::Channel;
using pds::ut::OpMessageData;

TEST_F(TestMSGOP, test_init) {
    Bus* bus = new Bus();
    ASSERT_NE(bus, NULL);
    Dag* dag = NULL;

    MsgOP op;
    std::string op_name = "TestMSGOp";
    std::string op_type = "TestMSGOp";
    EXPECT_EQ(0, op.init(bus, dag, (uint32_t)9999, op_name, op_type, NULL));
    EXPECT_FALSE(op.has_calc());
    EXPECT_EQ(9999, op.id());
    EXPECT_STREQ("TestMSGOp", op.name());
    EXPECT_STREQ("", op.debug_string().c_str());
    EXPECT_NE(op._timer, NULL);
    EXPECT_EQ(bus, op._bus);

    OpMessageData* ab = op.mutable_data<OpMessageData>();
    EXPECT_EQ(33, ab->a());
    EXPECT_FLOAT_EQ(4.4, ab->b());

    Channel* chn = op.mutable_channel();
    EXPECT_EQ(chn->id(), 9999);
    EXPECT_STREQ(chn->op().c_str(), "TestMSGOp");

    EXPECT_EQ(ab, chn->param());

    EXPECT_EQ(0, bus->size());
    Channel* chn2 = bus->channel_by_name("TestOp");
    EXPECT_EQ(NULL, chn2);

    // Message OP can obtain data via message()
    EXPECT_EQ(ab, chn->message());
}

}
}
}