blobslap_client.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Test the blobslap_client program
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above
  15. * copyright notice, this list of conditions and the following disclaimer
  16. * in the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * * The names of its contributors may not be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. /*
  37. Test that we are cycling the servers we are creating during testing.
  38. */
  39. #include <libtest/test.hpp>
  40. using namespace libtest;
  41. #ifndef __INTEL_COMPILER
  42. #pragma GCC diagnostic ignored "-Wstrict-aliasing"
  43. #endif
  44. #include "tests/ports.h"
  45. static std::string executable;
  46. static test_return_t help_test(void *)
  47. {
  48. char buffer[1024];
  49. snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
  50. const char *args[]= { buffer, "-?", 0 };
  51. test_compare(EXIT_SUCCESS, exec_cmdline(executable, args));
  52. return TEST_SUCCESS;
  53. }
  54. static test_return_t unknown_test(void *)
  55. {
  56. char buffer[1024];
  57. snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
  58. const char *args[]= { buffer, "--unknown", 0 };
  59. // The argument doesn't exist, so we should see an error
  60. test_compare(EXIT_FAILURE, exec_cmdline(executable, args));
  61. return TEST_SUCCESS;
  62. }
  63. static test_return_t basic_benchmark_test(void *)
  64. {
  65. char buffer[1024];
  66. snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
  67. const char *args[]= { buffer, "-c 100", "-n 10", "-e", 0 };
  68. // The argument doesn't exist, so we should see an error
  69. test_compare(EXIT_SUCCESS, exec_cmdline(executable, args));
  70. return TEST_SUCCESS;
  71. }
  72. test_st benchmark_tests[] ={
  73. {"--help", 0, help_test},
  74. {"--unknown", 0, unknown_test},
  75. {"-c 100 -n 10", 0, basic_benchmark_test},
  76. {0, 0, 0}
  77. };
  78. collection_st collection[] ={
  79. {"blobslap_client", 0, 0, benchmark_tests},
  80. {0, 0, 0, 0}
  81. };
  82. static void *world_create(server_startup_st& servers, test_return_t& error)
  83. {
  84. const char *argv[1]= { "blobslap_client" };
  85. if (not server_startup(servers, "gearmand", BLOBSLAP_CLIENT_TEST_PORT, 1, argv))
  86. {
  87. error= TEST_FAILURE;
  88. }
  89. if (not server_startup(servers, "blobslap_worker", BLOBSLAP_CLIENT_TEST_PORT, 1, argv))
  90. {
  91. error= TEST_FAILURE;
  92. }
  93. return &servers;
  94. }
  95. void get_world(Framework *world)
  96. {
  97. executable= "./benchmark/blobslap_client";
  98. world->collections= collection;
  99. world->_create= world_create;
  100. }