| 83 | DynamicWeightsTest() {} |
| 84 | |
| 85 | void checkWithGetRequest( |
| 86 | const PID<Master>& master, |
| 87 | const Credential& credential, |
| 88 | const Option<string>& _weights = None()) |
| 89 | { |
| 90 | Future<Response> response = process::http::request( |
| 91 | process::http::createRequest( |
| 92 | master, |
| 93 | "GET", |
| 94 | false, |
| 95 | "weights", |
| 96 | createBasicAuthHeaders(credential))); |
| 97 | |
| 98 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); |
| 99 | AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response); |
| 100 | |
| 101 | Try<JSON::Value> parse = JSON::parse(response->body); |
| 102 | ASSERT_SOME(parse); |
| 103 | |
| 104 | // Create Protobuf representation of weights. |
| 105 | Try<RepeatedPtrField<WeightInfo>> weightInfos = |
| 106 | ::protobuf::parse<RepeatedPtrField<WeightInfo>>(parse.get()); |
| 107 | |
| 108 | ASSERT_SOME(weightInfos); |
| 109 | |
| 110 | hashmap<string, double> weights = |
| 111 | convertToHashmap(weightInfos.get()); |
| 112 | |
| 113 | if (_weights.isNone()) { |
| 114 | EXPECT_TRUE(weights.empty()); |
| 115 | } else if (_weights == GET_WEIGHTS1) { |
| 116 | EXPECT_EQ(1u, weights.size()); |
| 117 | EXPECT_EQ(2.0, weights["role1"]); |
| 118 | } else if (_weights == GET_WEIGHTS2) { |
| 119 | EXPECT_EQ(1u, weights.size()); |
| 120 | EXPECT_EQ(4.0, weights["role2"]); |
| 121 | } else if (_weights == UPDATED_WEIGHTS1) { |
| 122 | EXPECT_EQ(2u, weights.size()); |
| 123 | EXPECT_EQ(2.0, weights["role1"]); |
| 124 | EXPECT_EQ(4.0, weights["role2"]); |
| 125 | } else if (_weights == UPDATED_WEIGHTS2) { |
| 126 | EXPECT_EQ(3u, weights.size()); |
| 127 | EXPECT_EQ(1.0, weights["role1"]); |
| 128 | EXPECT_EQ(4.0, weights["role2"]); |
| 129 | EXPECT_EQ(2.5, weights["role3"]); |
| 130 | } else { |
| 131 | EXPECT_EQ(_weights.get(), "Unexpected weights string."); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | protected: |
| 136 | const string ROLE1 = "role1"; |
nothing calls this directly
no test coverage detected