Validate the state machine of BackendResourceState by testing that the following conditions hold: All BackendStates are initially marked as IN_USE. Releasing all Backends transitions all Backends to the RELEASED state.
| 69 | /// * All BackendStates are initially marked as IN_USE. |
| 70 | /// * Releasing all Backends transitions all Backends to the RELEASED state. |
| 71 | TEST_F(CoordinatorBackendStateTest, StateMachine) { |
| 72 | // Initialize a BackendResourceState with three BackendStates. |
| 73 | int num_backends = 3; |
| 74 | std::vector<Coordinator::BackendState*> backend_states; |
| 75 | Coordinator::BackendState* coordinator_backend = nullptr; |
| 76 | MakeBackendStates(num_backends, &coordinator_backend, &backend_states); |
| 77 | Coordinator::BackendResourceState* backend_resource_state = |
| 78 | pool_.Add(new Coordinator::BackendResourceState(backend_states)); |
| 79 | |
| 80 | // Assert that all BackendStates are initially in the IN_USE state. |
| 81 | ASSERT_EQ(backend_resource_state->backend_resource_states_.size(), num_backends); |
| 82 | for (auto backend_state : backend_resource_state->backend_resource_states_) { |
| 83 | ASSERT_EQ( |
| 84 | backend_state.second, Coordinator::BackendResourceState::ResourceState::IN_USE); |
| 85 | } |
| 86 | |
| 87 | // Assert that releasing an empty vector of BackendStates does not transition any |
| 88 | // BackendState to the RELEASED state. |
| 89 | std::vector<Coordinator::BackendState*> empty_backend_states; |
| 90 | backend_resource_state->BackendsReleased(empty_backend_states); |
| 91 | ASSERT_TRUE(empty_backend_states.empty()); |
| 92 | ASSERT_EQ(backend_resource_state->backend_resource_states_.size(), num_backends); |
| 93 | for (auto backend_state : backend_resource_state->backend_resource_states_) { |
| 94 | ASSERT_EQ( |
| 95 | backend_state.second, Coordinator::BackendResourceState::ResourceState::IN_USE); |
| 96 | } |
| 97 | |
| 98 | // Assert that releasing all BackendStates transitions all BackendStates from |
| 99 | // IN_USE to RELEASED. |
| 100 | backend_resource_state->BackendsReleased(backend_states); |
| 101 | std::vector<Coordinator::BackendState*> unreleased_backend_states = |
| 102 | backend_resource_state->CloseAndGetUnreleasedBackends(); |
| 103 | ASSERT_EQ(unreleased_backend_states.size(), 0); |
| 104 | } |
| 105 | |
| 106 | /// Validate the 'Coordinator Only' heuristic. |
| 107 | TEST_F(CoordinatorBackendStateTest, CoordinatorOnly) { |
nothing calls this directly
no test coverage detected