blobslap_client.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. static std::string executable;
  45. static test_return_t help_test(void *)
  46. {
  47. char buffer[1024];
  48. snprintf(buffer, sizeof(buffer), "%d", int(default_port()));
  49. const char *args[]= { buffer, "-?", "-p", buffer, 0 };
  50. ASSERT_EQ(EXIT_SUCCESS, exec_cmdline(executable, args, true));
  51. return TEST_SUCCESS;
  52. }
  53. static test_return_t unknown_test(void *)
  54. {
  55. char buffer[1024];
  56. snprintf(buffer, sizeof(buffer), "%d", int(default_port()));
  57. const char *args[]= { buffer, "--unknown", "-p", buffer, 0 };
  58. // The argument doesn't exist, so we should see an error
  59. ASSERT_EQ(EXIT_FAILURE, exec_cmdline(executable, args, true));
  60. return TEST_SUCCESS;
  61. }
  62. static test_return_t basic_benchmark_test(void *)
  63. {
  64. char buffer[1024];
  65. snprintf(buffer, sizeof(buffer), "%d", int(default_port()));
  66. const char *args[]= { buffer, "-c", "100", "-n", "10", "-e", "-p", buffer, 0 };
  67. // The argument doesn't exist, so we should see an error
  68. ASSERT_EQ(EXIT_SUCCESS, exec_cmdline(executable, args, true));
  69. return TEST_SUCCESS;
  70. }
  71. test_st benchmark_tests[] ={
  72. {"--help", 0, help_test},
  73. {"--unknown", 0, unknown_test},
  74. {"-c 100 -n 10", 0, basic_benchmark_test},
  75. {0, 0, 0}
  76. };
  77. collection_st collection[] ={
  78. {"blobslap_client", 0, 0, benchmark_tests},
  79. {0, 0, 0, 0}
  80. };
  81. static void *world_create(server_startup_st& servers, test_return_t& error)
  82. {
  83. if (server_startup(servers, "gearmand", libtest::default_port(), NULL) == false)
  84. {
  85. error= TEST_SKIPPED;
  86. }
  87. if (server_startup(servers, "blobslap_worker", libtest::default_port(), NULL) == false)
  88. {
  89. error= TEST_SKIPPED;
  90. }
  91. return &servers;
  92. }
  93. void get_world(libtest::Framework *world)
  94. {
  95. executable= "./benchmark/blobslap_client";
  96. world->collections(collection);
  97. world->create(world_create);
  98. }