multiple_server_queues_test.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <grpc/grpc.h>
  19. #include <grpc/grpc_security.h>
  20. #include "test/core/util/test_config.h"
  21. int main(int argc, char** argv) {
  22. grpc_completion_queue* cq1;
  23. grpc_completion_queue* cq2;
  24. grpc_completion_queue* cq3;
  25. grpc_completion_queue_attributes attr;
  26. grpc_server* server;
  27. grpc::testing::TestEnvironment env(argc, argv);
  28. grpc_init();
  29. attr.version = 1;
  30. attr.cq_completion_type = GRPC_CQ_NEXT;
  31. attr.cq_polling_type = GRPC_CQ_DEFAULT_POLLING;
  32. cq1 = grpc_completion_queue_create(
  33. grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
  34. attr.cq_polling_type = GRPC_CQ_NON_LISTENING;
  35. cq2 = grpc_completion_queue_create(
  36. grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
  37. attr.cq_polling_type = GRPC_CQ_NON_POLLING;
  38. cq3 = grpc_completion_queue_create(
  39. grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
  40. server = grpc_server_create(nullptr, nullptr);
  41. grpc_server_register_completion_queue(server, cq1, nullptr);
  42. grpc_server_credentials* server_creds =
  43. grpc_insecure_server_credentials_create();
  44. grpc_server_add_http2_port(server, "[::]:0", server_creds);
  45. grpc_server_credentials_release(server_creds);
  46. grpc_server_register_completion_queue(server, cq2, nullptr);
  47. grpc_server_register_completion_queue(server, cq3, nullptr);
  48. grpc_server_start(server);
  49. grpc_server_shutdown_and_notify(server, cq2, nullptr);
  50. grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME),
  51. nullptr); /* cue queue freeze */
  52. grpc_completion_queue_shutdown(cq1);
  53. grpc_completion_queue_shutdown(cq2);
  54. grpc_completion_queue_shutdown(cq3);
  55. grpc_completion_queue_next(cq1, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
  56. grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
  57. grpc_completion_queue_next(cq3, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
  58. grpc_server_destroy(server);
  59. grpc_completion_queue_destroy(cq1);
  60. grpc_completion_queue_destroy(cq2);
  61. grpc_completion_queue_destroy(cq3);
  62. grpc_shutdown();
  63. return 0;
  64. }