http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/m4/ax_doxygen.m4 ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/m4/ax_doxygen.m4 b/hedwig-client/src/main/cpp/m4/ax_doxygen.m4 deleted file mode 100644 index 6334fd4..0000000 --- a/hedwig-client/src/main/cpp/m4/ax_doxygen.m4 +++ /dev/null @@ -1,533 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_prog_doxygen.html -# =========================================================================== -# -# SYNOPSIS -# -# DX_INIT_DOXYGEN(PROJECT-NAME, DOXYFILE-PATH, [OUTPUT-DIR]) -# DX_DOXYGEN_FEATURE(ON|OFF) -# DX_DOT_FEATURE(ON|OFF) -# DX_HTML_FEATURE(ON|OFF) -# DX_CHM_FEATURE(ON|OFF) -# DX_CHI_FEATURE(ON|OFF) -# DX_MAN_FEATURE(ON|OFF) -# DX_RTF_FEATURE(ON|OFF) -# DX_XML_FEATURE(ON|OFF) -# DX_PDF_FEATURE(ON|OFF) -# DX_PS_FEATURE(ON|OFF) -# -# DESCRIPTION -# -# The DX_*_FEATURE macros control the default setting for the given -# Doxygen feature. Supported features are 'DOXYGEN' itself, 'DOT' for -# generating graphics, 'HTML' for plain HTML, 'CHM' for compressed HTML -# help (for MS users), 'CHI' for generating a seperate .chi file by the -# .chm file, and 'MAN', 'RTF', 'XML', 'PDF' and 'PS' for the appropriate -# output formats. The environment variable DOXYGEN_PAPER_SIZE may be -# specified to override the default 'a4wide' paper size. -# -# By default, HTML, PDF and PS documentation is generated as this seems to -# be the most popular and portable combination. MAN pages created by -# Doxygen are usually problematic, though by picking an appropriate subset -# and doing some massaging they might be better than nothing. CHM and RTF -# are specific for MS (note that you can't generate both HTML and CHM at -# the same time). The XML is rather useless unless you apply specialized -# post-processing to it. -# -# The macros mainly control the default state of the feature. The use can -# override the default by specifying --enable or --disable. The macros -# ensure that contradictory flags are not given (e.g., -# --enable-doxygen-html and --enable-doxygen-chm, -# --enable-doxygen-anything with --disable-doxygen, etc.) Finally, each -# feature will be automatically disabled (with a warning) if the required -# programs are missing. -# -# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN -# with the following parameters: a one-word name for the project for use -# as a filename base etc., an optional configuration file name (the -# default is 'Doxyfile', the same as Doxygen's default), and an optional -# output directory name (the default is 'doxygen-doc'). -# -# Automake Support -# -# The following is a template aminclude.am file for use with Automake. -# Make targets and variables values are controlled by the various -# DX_COND_* conditionals set by autoconf. -# -# The provided targets are: -# -# doxygen-doc: Generate all doxygen documentation. -# -# doxygen-run: Run doxygen, which will generate some of the -# documentation (HTML, CHM, CHI, MAN, RTF, XML) -# but will not do the post processing required -# for the rest of it (PS, PDF, and some MAN). -# -# doxygen-man: Rename some doxygen generated man pages. -# -# doxygen-ps: Generate doxygen PostScript documentation. -# -# doxygen-pdf: Generate doxygen PDF documentation. -# -# Note that by default these are not integrated into the automake targets. -# If doxygen is used to generate man pages, you can achieve this -# integration by setting man3_MANS to the list of man pages generated and -# then adding the dependency: -# -# $(man3_MANS): doxygen-doc -# -# This will cause make to run doxygen and generate all the documentation. -# -# The following variable is intended for use in Makefile.am: -# -# DX_CLEANFILES = everything to clean. -# -# Then add this variable to MOSTLYCLEANFILES. -# -# ----- begin aminclude.am ------------------------------------- -# -# ## --------------------------------- ## -# ## Format-independent Doxygen rules. ## -# ## --------------------------------- ## -# -# if DX_COND_doc -# -# ## ------------------------------- ## -# ## Rules specific for HTML output. ## -# ## ------------------------------- ## -# -# if DX_COND_html -# -# DX_CLEAN_HTML = @DX_DOCDIR@/html -# -# endif DX_COND_html -# -# ## ------------------------------ ## -# ## Rules specific for CHM output. ## -# ## ------------------------------ ## -# -# if DX_COND_chm -# -# DX_CLEAN_CHM = @DX_DOCDIR@/chm -# -# if DX_COND_chi -# -# DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi -# -# endif DX_COND_chi -# -# endif DX_COND_chm -# -# ## ------------------------------ ## -# ## Rules specific for MAN output. ## -# ## ------------------------------ ## -# -# if DX_COND_man -# -# DX_CLEAN_MAN = @DX_DOCDIR@/man -# -# endif DX_COND_man -# -# ## ------------------------------ ## -# ## Rules specific for RTF output. ## -# ## ------------------------------ ## -# -# if DX_COND_rtf -# -# DX_CLEAN_RTF = @DX_DOCDIR@/rtf -# -# endif DX_COND_rtf -# -# ## ------------------------------ ## -# ## Rules specific for XML output. ## -# ## ------------------------------ ## -# -# if DX_COND_xml -# -# DX_CLEAN_XML = @DX_DOCDIR@/xml -# -# endif DX_COND_xml -# -# ## ----------------------------- ## -# ## Rules specific for PS output. ## -# ## ----------------------------- ## -# -# if DX_COND_ps -# -# DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps -# -# DX_PS_GOAL = doxygen-ps -# -# doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps -# -# @DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag -# cd @DX_DOCDIR@/latex; \ -# rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ -# $(DX_LATEX) refman.tex; \ -# $(MAKEINDEX_PATH) refman.idx; \ -# $(DX_LATEX) refman.tex; \ -# countdown=5; \ -# while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ -# refman.log > /dev/null 2>&1 \ -# && test $$countdown -gt 0; do \ -# $(DX_LATEX) refman.tex; \ -# countdown=`expr $$countdown - 1`; \ -# done; \ -# $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi -# -# endif DX_COND_ps -# -# ## ------------------------------ ## -# ## Rules specific for PDF output. ## -# ## ------------------------------ ## -# -# if DX_COND_pdf -# -# DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf -# -# DX_PDF_GOAL = doxygen-pdf -# -# doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf -# -# @DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag -# cd @DX_DOCDIR@/latex; \ -# rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ -# $(DX_PDFLATEX) refman.tex; \ -# $(DX_MAKEINDEX) refman.idx; \ -# $(DX_PDFLATEX) refman.tex; \ -# countdown=5; \ -# while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ -# refman.log > /dev/null 2>&1 \ -# && test $$countdown -gt 0; do \ -# $(DX_PDFLATEX) refman.tex; \ -# countdown=`expr $$countdown - 1`; \ -# done; \ -# mv refman.pdf ../@PACKAGE@.pdf -# -# endif DX_COND_pdf -# -# ## ------------------------------------------------- ## -# ## Rules specific for LaTeX (shared for PS and PDF). ## -# ## ------------------------------------------------- ## -# -# if DX_COND_latex -# -# DX_CLEAN_LATEX = @DX_DOCDIR@/latex -# -# endif DX_COND_latex -# -# .PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) -# -# .INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) -# -# doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag -# -# doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) -# -# @DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS) -# rm -rf @DX_DOCDIR@ -# $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG) -# -# DX_CLEANFILES = \ -# @DX_DOCDIR@/@PACKAGE@.tag \ -# -r \ -# $(DX_CLEAN_HTML) \ -# $(DX_CLEAN_CHM) \ -# $(DX_CLEAN_CHI) \ -# $(DX_CLEAN_MAN) \ -# $(DX_CLEAN_RTF) \ -# $(DX_CLEAN_XML) \ -# $(DX_CLEAN_PS) \ -# $(DX_CLEAN_PDF) \ -# $(DX_CLEAN_LATEX) -# -# endif DX_COND_doc -# -# ----- end aminclude.am --------------------------------------- -# -# LICENSE -# -# Copyright (c) 2009 Oren Ben-Kiki <o...@ben-kiki.org> -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 10 - -## ----------## -## Defaults. ## -## ----------## - -DX_ENV="" -AC_DEFUN([DX_FEATURE_doc], ON) -AC_DEFUN([DX_FEATURE_dot], ON) -AC_DEFUN([DX_FEATURE_man], OFF) -AC_DEFUN([DX_FEATURE_html], ON) -AC_DEFUN([DX_FEATURE_chm], OFF) -AC_DEFUN([DX_FEATURE_chi], OFF) -AC_DEFUN([DX_FEATURE_rtf], OFF) -AC_DEFUN([DX_FEATURE_xml], OFF) -AC_DEFUN([DX_FEATURE_pdf], ON) -AC_DEFUN([DX_FEATURE_ps], ON) - -## --------------- ## -## Private macros. ## -## --------------- ## - -# DX_ENV_APPEND(VARIABLE, VALUE) -# ------------------------------ -# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen. -AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])]) - -# DX_DIRNAME_EXPR -# --------------- -# Expand into a shell expression prints the directory part of a path. -AC_DEFUN([DX_DIRNAME_EXPR], - [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']]) - -# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF) -# ------------------------------------- -# Expands according to the M4 (static) status of the feature. -AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])]) - -# DX_REQUIRE_PROG(VARIABLE, PROGRAM) -# ---------------------------------- -# Require the specified program to be found for the DX_CURRENT_FEATURE to work. -AC_DEFUN([DX_REQUIRE_PROG], [ -AC_PATH_TOOL([$1], [$2]) -if test "$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = 1; then - AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION]) - AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0) -fi -]) - -# DX_TEST_FEATURE(FEATURE) -# ------------------------ -# Expand to a shell expression testing whether the feature is active. -AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1]) - -# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE) -# ------------------------------------------------- -# Verify that a required features has the right state before trying to turn on -# the DX_CURRENT_FEATURE. -AC_DEFUN([DX_CHECK_DEPEND], [ -test "$DX_FLAG_$1" = "$2" \ -|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1, - requires, contradicts) doxygen-DX_CURRENT_FEATURE]) -]) - -# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE) -# ---------------------------------------------------------- -# Turn off the DX_CURRENT_FEATURE if the required feature is off. -AC_DEFUN([DX_CLEAR_DEPEND], [ -test "$DX_FLAG_$1" = "$2" || AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0) -]) - -# DX_FEATURE_ARG(FEATURE, DESCRIPTION, -# CHECK_DEPEND, CLEAR_DEPEND, -# REQUIRE, DO-IF-ON, DO-IF-OFF) -# -------------------------------------------- -# Parse the command-line option controlling a feature. CHECK_DEPEND is called -# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND), -# otherwise CLEAR_DEPEND is called to turn off the default state if a required -# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional -# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and -# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature. -AC_DEFUN([DX_ARG_ABLE], [ - AC_DEFUN([DX_CURRENT_FEATURE], [$1]) - AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2]) - AC_ARG_ENABLE(doxygen-$1, - [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1], - [--enable-doxygen-$1]), - DX_IF_FEATURE([$1], [don't $2], [$2]))], - [ -case "$enableval" in -#( -y|Y|yes|Yes|YES) - AC_SUBST([DX_FLAG_$1], 1) - $3 -;; #( -n|N|no|No|NO) - AC_SUBST([DX_FLAG_$1], 0) -;; #( -*) - AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1]) -;; -esac -], [ -AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)]) -$4 -]) -if DX_TEST_FEATURE([$1]); then - $5 - : -fi -if DX_TEST_FEATURE([$1]); then - AM_CONDITIONAL(DX_COND_$1, :) - $6 - : -else - AM_CONDITIONAL(DX_COND_$1, false) - $7 - : -fi -]) - -## -------------- ## -## Public macros. ## -## -------------- ## - -# DX_XXX_FEATURE(DEFAULT_STATE) -# ----------------------------- -AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])]) -AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])]) -AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])]) -AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])]) -AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])]) -AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])]) -AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) -AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) -AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])]) -AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])]) - -# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR]) -# --------------------------------------------------------- -# PROJECT also serves as the base name for the documentation files. -# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc". -AC_DEFUN([DX_INIT_DOXYGEN], [ - -# Files: -AC_SUBST([DX_PROJECT], [$1]) -AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])]) -AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])]) - -# Environment variables used inside doxygen.cfg: -DX_ENV_APPEND(SRCDIR, $srcdir) -DX_ENV_APPEND(PROJECT, $DX_PROJECT) -DX_ENV_APPEND(DOCDIR, $DX_DOCDIR) -DX_ENV_APPEND(VERSION, $PACKAGE_VERSION) - -# Doxygen itself: -DX_ARG_ABLE(doc, [generate any doxygen documentation], - [], - [], - [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) - DX_REQUIRE_PROG([DX_PERL], perl)], - [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) - -# Dot for graphics: -DX_ARG_ABLE(dot, [generate graphics for doxygen documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [DX_REQUIRE_PROG([DX_DOT], dot)], - [DX_ENV_APPEND(HAVE_DOT, YES) - DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], - [DX_ENV_APPEND(HAVE_DOT, NO)]) - -# Man pages generation: -DX_ARG_ABLE(man, [generate doxygen manual pages], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [], - [DX_ENV_APPEND(GENERATE_MAN, YES)], - [DX_ENV_APPEND(GENERATE_MAN, NO)]) - -# RTF file generation: -DX_ARG_ABLE(rtf, [generate doxygen RTF documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [], - [DX_ENV_APPEND(GENERATE_RTF, YES)], - [DX_ENV_APPEND(GENERATE_RTF, NO)]) - -# XML file generation: -DX_ARG_ABLE(xml, [generate doxygen XML documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [], - [DX_ENV_APPEND(GENERATE_XML, YES)], - [DX_ENV_APPEND(GENERATE_XML, NO)]) - -# (Compressed) HTML help generation: -DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [DX_REQUIRE_PROG([DX_HHC], hhc)], - [DX_ENV_APPEND(HHC_PATH, $DX_HHC) - DX_ENV_APPEND(GENERATE_HTML, YES) - DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], - [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) - -# Seperate CHI file generation. -DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file], - [DX_CHECK_DEPEND(chm, 1)], - [DX_CLEAR_DEPEND(chm, 1)], - [], - [DX_ENV_APPEND(GENERATE_CHI, YES)], - [DX_ENV_APPEND(GENERATE_CHI, NO)]) - -# Plain HTML pages generation: -DX_ARG_ABLE(html, [generate doxygen plain HTML documentation], - [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], - [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], - [], - [DX_ENV_APPEND(GENERATE_HTML, YES)], - [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) - -# PostScript file generation: -DX_ARG_ABLE(ps, [generate doxygen PostScript documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [DX_REQUIRE_PROG([DX_LATEX], latex) - DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) - DX_REQUIRE_PROG([DX_DVIPS], dvips) - DX_REQUIRE_PROG([DX_EGREP], egrep)]) - -# PDF file generation: -DX_ARG_ABLE(pdf, [generate doxygen PDF documentation], - [DX_CHECK_DEPEND(doc, 1)], - [DX_CLEAR_DEPEND(doc, 1)], - [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) - DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) - DX_REQUIRE_PROG([DX_EGREP], egrep)]) - -# LaTeX generation for PS and/or PDF: -if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then - AM_CONDITIONAL(DX_COND_latex, :) - DX_ENV_APPEND(GENERATE_LATEX, YES) -else - AM_CONDITIONAL(DX_COND_latex, false) - DX_ENV_APPEND(GENERATE_LATEX, NO) -fi - -# Paper size for PS and/or PDF: -AC_ARG_VAR(DOXYGEN_PAPER_SIZE, - [a4wide (default), a4, letter, legal or executive]) -case "$DOXYGEN_PAPER_SIZE" in -#( -"") - AC_SUBST(DOXYGEN_PAPER_SIZE, "") -;; #( -a4wide|a4|letter|legal|executive) - DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE) -;; #( -*) - AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE']) -;; -esac - -#For debugging: -#echo DX_FLAG_doc=$DX_FLAG_doc -#echo DX_FLAG_dot=$DX_FLAG_dot -#echo DX_FLAG_man=$DX_FLAG_man -#echo DX_FLAG_html=$DX_FLAG_html -#echo DX_FLAG_chm=$DX_FLAG_chm -#echo DX_FLAG_chi=$DX_FLAG_chi -#echo DX_FLAG_rtf=$DX_FLAG_rtf -#echo DX_FLAG_xml=$DX_FLAG_xml -#echo DX_FLAG_pdf=$DX_FLAG_pdf -#echo DX_FLAG_ps=$DX_FLAG_ps -#echo DX_ENV=$DX_ENV -])
http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/m4/gtest.m4 ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/m4/gtest.m4 b/hedwig-client/src/main/cpp/m4/gtest.m4 deleted file mode 100644 index 648f43c..0000000 --- a/hedwig-client/src/main/cpp/m4/gtest.m4 +++ /dev/null @@ -1,74 +0,0 @@ -dnl GTEST_LIB_CHECK([minimum version [, -dnl action if found [,action if not found]]]) -dnl -dnl Check for the presence of the Google Test library, optionally at a minimum -dnl version, and indicate a viable version with the HAVE_GTEST flag. It defines -dnl standard variables for substitution including GTEST_CPPFLAGS, -dnl GTEST_CXXFLAGS, GTEST_LDFLAGS, and GTEST_LIBS. It also defines -dnl GTEST_VERSION as the version of Google Test found. Finally, it provides -dnl optional custom action slots in the event GTEST is found or not. -AC_DEFUN([GTEST_LIB_CHECK], -[ -dnl Provide a flag to enable or disable Google Test usage. -AC_ARG_ENABLE([gtest], - [AS_HELP_STRING([--enable-gtest], - [Enable tests using the Google C++ Testing Framework. - (Default is disabled.)])], - [], - [enable_gtest=no]) -AC_ARG_VAR([GTEST_CONFIG], - [The exact path of Google Test's 'gtest-config' script.]) -AC_ARG_VAR([GTEST_CPPFLAGS], - [C-like preprocessor flags for Google Test.]) -AC_ARG_VAR([GTEST_CXXFLAGS], - [C++ compile flags for Google Test.]) -AC_ARG_VAR([GTEST_LDFLAGS], - [Linker path and option flags for Google Test.]) -AC_ARG_VAR([GTEST_LIBS], - [Library linking flags for Google Test.]) -AC_ARG_VAR([GTEST_VERSION], - [The version of Google Test available.]) -HAVE_GTEST="no" -AS_IF([test "x${enable_gtest}" != "xno"], - [AC_MSG_CHECKING([for 'gtest-config']) - AS_IF([test "x${enable_gtest}" != "xyes"], - [AS_IF([test -x "${enable_gtest}/scripts/gtest-config"], - [GTEST_CONFIG="${enable_gtest}/scripts/gtest-config"], - [GTEST_CONFIG="${enable_gtest}/bin/gtest-config"]) - AS_IF([test -x "${GTEST_CONFIG}"], [], - [AC_MSG_RESULT([no]) - AC_MSG_ERROR([dnl -Unable to locate either a built or installed Google Test. -The specific location '${enable_gtest}' was provided for a built or installed -Google Test, but no 'gtest-config' script could be found at this location.]) - ])], - [AC_PATH_PROG([GTEST_CONFIG], [gtest-config])]) - AS_IF([test -x "${GTEST_CONFIG}"], - [AC_MSG_RESULT([${GTEST_CONFIG}]) - m4_ifval([$1], - [_gtest_min_version="--min-version=$1" - AC_MSG_CHECKING([for Google Test at least version >= $1])], - [_gtest_min_version="--min-version=0" - AC_MSG_CHECKING([for Google Test])]) - AS_IF([${GTEST_CONFIG} ${_gtest_min_version}], - [AC_MSG_RESULT([yes]) - HAVE_GTEST='yes'], - [AC_MSG_RESULT([no])])], - [AC_MSG_RESULT([no])]) - AS_IF([test "x${HAVE_GTEST}" = "xyes"], - [GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags` - GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags` - GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags` - GTEST_LIBS=`${GTEST_CONFIG} --libs` - GTEST_VERSION=`${GTEST_CONFIG} --version` - AC_DEFINE([HAVE_GTEST],[1],[Defined when Google Test is available.])], - [AS_IF([test "x${enable_gtest}" = "xyes"], - [AC_MSG_ERROR([dnl -Google Test was enabled, but no viable version could be found.]) - ])])]) -AC_SUBST([HAVE_GTEST]) -AM_CONDITIONAL([HAVE_GTEST],[test "x$HAVE_GTEST" = "xyes"]) -AS_IF([test "x$HAVE_GTEST" = "xyes"], - [m4_ifval([$2], [$2])], - [m4_ifval([$3], [$3])]) -]) http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/scripts/log4cxx.conf ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/scripts/log4cxx.conf b/hedwig-client/src/main/cpp/scripts/log4cxx.conf deleted file mode 100644 index 1917d7e..0000000 --- a/hedwig-client/src/main/cpp/scripts/log4cxx.conf +++ /dev/null @@ -1,44 +0,0 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# - -log4j.appender.rootAppender=org.apache.log4j.ConsoleAppender -log4j.appender.rootAppender.layout=org.apache.log4j.BasicLayout - -log4j.appender.hedwig=org.apache.log4j.RollingFileAppender -#log4j.appender.hedwig=org.apache.log4j.ConsoleAppender -log4j.appender.hedwig.fileName=./testLog.log -log4j.appender.hedwig.layout=org.apache.log4j.PatternLayout -log4j.appender.hedwig.layout.ConversionPattern=[%d{%H:%M:%S.%l}] %t %p %c - %m%n - -log4j.appender.hedwigtest=org.apache.log4j.RollingFileAppender -#log4j.appender.hedwigtest=org.apache.log4j.ConsoleAppender -log4j.appender.hedwigtest.fileName=./testLog.log -log4j.appender.hedwigtest.layout=org.apache.log4j.PatternLayout -log4j.appender.hedwigtest.layout.ConversionPattern=[%d{%H:%M:%S.%l}] %t %p %c - %m%n - -# category -log4j.category.hedwig=DEBUG, hedwig -log4j.category.hedwigtest=DEBUG, hedwigtest - -log4j.rootCategory=OFF - -#log4j.category.hedwig.channel=ERROR - http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/scripts/network-delays.sh ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/scripts/network-delays.sh b/hedwig-client/src/main/cpp/scripts/network-delays.sh deleted file mode 100644 index 83fd132..0000000 --- a/hedwig-client/src/main/cpp/scripts/network-delays.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -setup_delays() { - - UNAME=`uname -s` - - echo "Setting delay to ${1}ms" - case "$UNAME" in - Darwin|FreeBSD) - sudo ipfw pipe 1 config delay ${1}ms - sudo ipfw add pipe 1 dst-port 4081 - sudo ipfw add pipe 1 src-port 4081 - sudo ipfw add pipe 1 dst-port 4082 - sudo ipfw add pipe 1 src-port 4082 - sudo ipfw add pipe 1 dst-port 4083 - sudo ipfw add pipe 1 src-port 4083 - ;; - Linux) - sudo tc qdisc add dev lo root handle 1: prio - sudo tc qdisc add dev lo parent 1:3 handle 30: netem delay ${1}ms - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip dport 4081 0xffff flowid 1:3 - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip dport 4081 0xffff flowid 1:3 - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4082 0xffff flowid 1:3 - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4082 0xffff flowid 1:3 - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4083 0xffff flowid 1:3 - sudo tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4083 0xffff flowid 1:3 - ;; - *) - echo "Unknown system type, $UNAME, only Linux, Darwin & FreeBSD supported" - ;; - esac -} - -clear_delays() { - UNAME=`uname -s` - - case "$UNAME" in - Darwin|FreeBSD) - echo "Flushing ipfw" - sudo ipfw -f -q flush - ;; - Linux) - echo "Clearing delay" - sudo tc qdisc del dev lo root - ;; - *) - echo "Unknown system type, $UNAME, only Linux, Darwin & FreeBSD supported" - ;; - esac -} - http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/scripts/server-control.sh ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/scripts/server-control.sh b/hedwig-client/src/main/cpp/scripts/server-control.sh deleted file mode 100644 index cd8563a..0000000 --- a/hedwig-client/src/main/cpp/scripts/server-control.sh +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -BASE=../../../../../ -BKSCRIPT=$BASE/bookkeeper-server/bin/bookkeeper -HWSCRIPT=$BASE/hedwig-server/bin/hedwig -ZKCLIENT=org.apache.zookeeper.ZooKeeperMain - -check_bk_down() { - NUM_UP=100 - for i in 0 1 2 3 4 5 6 7 8 9; do - NUM_UP=`$BKSCRIPT $ZKCLIENT ls /ledgers/available 2> /dev/null | awk 'BEGIN{SERVERS=0} /^\[/ { gsub(/[,\[\]]/, ""); SERVERS=NF} END{ print SERVERS }'` - if [ $NUM_UP == 0 ]; then - break; - fi - sleep 1 - done - - if [ $NUM_UP != 0 ]; then - echo "Warning: Couldn't stop all bookies" - exit 1; - fi -} - -check_bk_up() { - NUM_BOOKIES=$1 - NUM_UP=0 - for i in 0 1 2 3 4 5 6 7 8 9; do - NUM_UP=`$BKSCRIPT $ZKCLIENT ls /ledgers/available 2> /dev/null | awk 'BEGIN{SERVERS=0} /^\[/ { gsub(/[,\[\]]/, ""); SERVERS=NF} END{ print SERVERS }'` - if [ $NUM_UP == $NUM_BOOKIES ]; then - break; - fi - sleep 1 - done - - if [ $NUM_UP != $NUM_BOOKIES ]; then - echo "Couldn't start bookkeeper" - exit 1; - fi -} - -check_hw_down() { - REGION=$1 - NUM_UP=100 - for i in 0 1 2 3 4 5 6 7 8 9; do - NUM_UP=`$BKSCRIPT $ZKCLIENT ls /hedwig/$REGION/hosts 2> /dev/null | awk 'BEGIN{SERVERS=0} /^\[/ { gsub(/[,\[\]]/, ""); SERVERS=NF} END{ print SERVERS }'` - if [ $NUM_UP == 0 ]; then - break; - fi - sleep 1 - done - - if [ $NUM_UP != 0 ]; then - echo "Warning: Couldn't stop all hedwig servers" - exit 1; - fi -} - -check_hw_up() { - REGION=$1 - NUM_SERVERS=$2 - NUM_UP=0 - for i in 0 1 2 3 4 5 6 7 8 9; do - NUM_UP=`$BKSCRIPT $ZKCLIENT ls /hedwig/$REGION/hosts 2> /dev/null | awk 'BEGIN{SERVERS=0} /^\[/ { gsub(/[,\[\]]/, ""); SERVERS=NF} END{ print SERVERS }'` - if [ $NUM_UP == $NUM_SERVERS ]; then - break; - fi - sleep 1 - done - - if [ $NUM_UP != $NUM_SERVERS ]; then - echo "Couldn't start hedwig" - exit 1; - fi -} - -start_hw_server () { - REGION=$1 - COUNT=$2 - PORT=$((4080+$COUNT)) - SSL_PORT=$((9876+$COUNT)) - - export HEDWIG_LOG_CONF=/tmp/hw-log4j-$COUNT.properties - cat > $HEDWIG_LOG_CONF <<EOF -log4j.rootLogger=INFO, ROLLINGFILE -# -# Add ROLLINGFILE to rootLogger to get log file output -# Log DEBUG level and above messages to a log file -log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender -log4j.appender.ROLLINGFILE.Threshold=DEBUG -log4j.appender.ROLLINGFILE.File=/tmp/hedwig-server-$COUNT.log -log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout -log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n -# uncomment the next line to limit number of backup files -#log4j.appender.ROLLINGFILE.MaxBackupIndex=10 -log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout -log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n -log4j.logger.org.apache.zookeeper=OFF,ROLLINGFILE -log4j.logger.org.apache.hedwig.zookeeper=OFF,ROLLINGFILE -EOF - - export HEDWIG_SERVER_CONF=/tmp/hw-server-$COUNT.conf - cat > $HEDWIG_SERVER_CONF <<EOF -zk_host=localhost:2181 -# The number of milliseconds of each tick in ZooKeeper. -zk_timeout=2000 -# The port at which the clients will connect. -server_port=$PORT -# The SSL port at which the clients will connect (only if SSL is enabled). -ssl_server_port=$SSL_PORT -# Flag indicating if the server should also operate in SSL mode. -ssl_enabled=true -cert_path=$PWD/../../../../../hedwig-server/src/main/resources/server.p12 -password=eUySvp2phM2Wk -region=$REGION -EOF - $HWSCRIPT server 2>&1 > hwoutput.$COUNT.log & - echo $! > hwprocess.$COUNT.pid -} - -start_cluster() { - if [ -e bkprocess.pid ] || [ `ls hwprocess.*.pid 2> /dev/null | wc -l` != 0 ]; then - stop_cluster; - fi - - $BKSCRIPT localbookie 3 2>&1 > bkoutput.log & - echo $! > bkprocess.pid - check_bk_up 3 - - for i in 1 2 3; do - start_hw_server CppUnitTest $i - done - check_hw_up CppUnitTest 3 -} - -stop_cluster() { - for i in hwprocess.*.pid; do - if [ ! -e $i ]; then - continue; - fi - kill `cat $i`; - rm $i; - done - check_hw_down - - if [ ! -e bkprocess.pid ]; then - return; - fi - - kill `cat bkprocess.pid` - rm bkprocess.pid - - check_bk_down -} http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/scripts/tester.sh ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/scripts/tester.sh b/hedwig-client/src/main/cpp/scripts/tester.sh deleted file mode 100644 index 85e1f74..0000000 --- a/hedwig-client/src/main/cpp/scripts/tester.sh +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -cd `dirname $0`; - -export LOG4CXX_CONF=`pwd`/log4cxx.conf - -source network-delays.sh -source server-control.sh - -runtest() { - if [ "z$HEDWIG_NETWORK_DELAY" != "z" ]; then - setup_delays $HEDWIG_NETWORK_DELAY - fi - - stop_cluster; - start_cluster; - - if [ "z$2" != "z" ]; then - ../test/hedwigtest -s true -m true - else - if [ "z$1" == "zssl" ]; then - ../test/hedwigtest -s true - elif [ "z$1" == "zmultiplex" ]; then - ../test/hedwigtest -m true - else - ../test/hedwigtest - fi - fi - - RESULT=$? - stop_cluster; - - if [ "z$HEDWIG_NETWORK_DELAY" != "z" ]; then - clear_delays - else - cat <<EOF - -The environment variable HEDWIG_NETWORK_DELAY is not set, so the tests were run directly -with a localhost server. This isn't quite realistic as usually there will be some delay between -the client and the hedwig server. Set HEDWIG_NETWORK_DELAY to the number of milliseconds you want -to delay the packets between the server and client. - - $ export HEDWIG_NETWORK_DELAY=500 - -Requires root privileges. - -WARNING!!! This will modify your traffic shaping and firewall rules. If you do run with delays, -check your firewall rules afterwards. - -EOF - fi - - exit $RESULT -} - -runall() { - runtest; - runtest ssl; - runtest multiplex; - runtest ssl multiplex; -} - -singletest() { - if [ "z$HEDWIG_NETWORK_DELAY" != "z" ]; then - setup_delays $HEDWIG_NETWORK_DELAY - fi - - stop_cluster; - start_cluster; - - ../test/hedwigtest --gtest_filter=$1 - RESULT=$? - stop_cluster; - - if [ "z$HEDWIG_NETWORK_DELAY" != "z" ]; then - clear_delays - else - cat <<EOF - -The environment variable HEDWIG_NETWORK_DELAY is not set, so the tests were run directly -with a localhost server. This isn't quite realistic as usually there will be some delay between -the client and the hedwig server. Set HEDWIG_NETWORK_DELAY to the number of milliseconds you want -to delay the packets between the server and client. - - $ export HEDWIG_NETWORK_DELAY=500 - -Requires root privileges. - -WARNING!!! This will modify your traffic shaping and firewall rules. If you do run with delays, -check your firewall rules afterwards. - -EOF - fi - - exit $RESULT -} - -case "$1" in - start-cluster) - start_cluster - ;; - stop-cluster) - stop_cluster - ;; - simple-test) - runtest - ;; - ssl-simple-test) - runtest ssl - ;; - multiplex-test) - runtest multiplex - ;; - ssl-multiplex-test) - runtest ssl multiplex - ;; - setup-delays) - setup_delays $2 - ;; - clear-delays) - clear_delays - ;; - all) - runall - ;; - singletest) - singletest $2 - ;; - *) - cat <<EOF -Usage: tester.sh [command] - -tester.sh all - Run through the tests (both simple and ssl), setting up and cleaning up all prerequisites. - -tester.sh simple-test - Run through the tests (simple mode), setting up and cleaning up all prerequisites. - -tester.sh ssl-test - Run through the tests (ssl mode), setting up and cleaning up all prerequisites. - -tester.sh singletest <name> - Run a single test - -tester.sh start-cluster - Start a hedwig cluster - -tester.sh stop-cluster - Stops a hedwig cluster - -tester.sh setup-delays <delay> - Set the millisecond delay for accessing the hedwig servers for the tests. - -tester.sh clear-delays - Clear the delay for accessing the hedwig servers. -EOF - ;; -esac http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/Makefile.am ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/Makefile.am b/hedwig-client/src/main/cpp/test/Makefile.am deleted file mode 100644 index d55100c..0000000 --- a/hedwig-client/src/main/cpp/test/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -if HAVE_GTEST -bin_PROGRAMS = hedwigtest -hedwigtest_SOURCES = main.cpp utiltest.cpp publishtest.cpp subscribetest.cpp pubsubtest.cpp messageboundtest.cpp messagefiltertest.cpp throttledeliverytest.cpp multiplextest.cpp -hedwigtest_CPPFLAGS = -I$(top_srcdir)/inc $(DEPS_CFLAGS) $(GTEST_CPPFLAGS) $(BOOST_CPPFLAGS) -hedwigtest_CXXFLAGS = $(GTEST_CXXFLAGS) -hedwigtest_LDADD = $(DEPS_LIBS) $(GTEST_LIBS) -L$(top_builddir)/lib -lhedwig01 -hedwigtest_LDFLAGS = -no-undefined $(BOOST_ASIO_LIB) $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) $(GTEST_LDFLAGS) - -check: hedwigtest - bash ../scripts/tester.sh all - -simplesslcheck: hedwigtest - bash ../scripts/tester.sh ssl-simple-test - -simplecheck: hedwigtest - bash ../scripts/tester.sh simple-test - -multiplexsslcheck: hedwigtest - bash ../scripts/tester.sh ssl-multiplex-test - -multiplexcheck: hedwigtest - bash ../scripts/tester.sh multiplex-test - -else -check: - @echo "\n\nYou haven't configured with gtest. Run the ./configure command with --enable-gtest=<path_to_gtest>" - @echo "i.e. ./configure --enable-gtest=/home/user/src/gtest-1.6.0" - @echo "See the README for more info\n\n\b" -endif http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/main.cpp ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/main.cpp b/hedwig-client/src/main/cpp/test/main.cpp deleted file mode 100644 index 7c08c97..0000000 --- a/hedwig-client/src/main/cpp/test/main.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "../lib/channel.h" -#include "../lib/util.h" -#include <hedwig/protocol.h> -#include <hedwig/callback.h> -#include <iostream> - -#include <log4cxx/logger.h> -#include <log4cxx/basicconfigurator.h> -#include <log4cxx/propertyconfigurator.h> -#include <log4cxx/helpers/exception.h> - -#include "util.h" - -#include "gtest/gtest.h" - -bool TestServerConfiguration::isSSL = false; -std::string TestServerConfiguration::certFile = ""; -bool TestServerConfiguration::multiplexing = false; - -int main( int argc, char **argv) -{ - try { - if (getenv("LOG4CXX_CONF") == NULL) { - std::cerr << "Set LOG4CXX_CONF in your environment to get logging." << std::endl; - log4cxx::BasicConfigurator::configure(); - } else { - log4cxx::PropertyConfigurator::configure(getenv("LOG4CXX_CONF")); - } - } catch (std::exception &e) { - std::cerr << "exception caught while configuring log4cpp via : " << e.what() << std::endl; - } catch (...) { - std::cerr << "unknown exception while configuring log4cpp vi'." << std::endl; - } - - // Enable SSL for testing - int opt; - while((opt = getopt(argc,argv,"s:c:m:")) > 0) { - switch(opt) { - case 's': - if (std::string(optarg) == "true") { - std::cout << "run in ssl mode...." << std::endl; - TestServerConfiguration::isSSL = true; - } else { - TestServerConfiguration::isSSL = false; - } - break; - case 'm': - if (std::string(optarg) == "true") { - std::cout << "run in multiplexing mode ..." << std::endl; - TestServerConfiguration::multiplexing = true; - } else { - TestServerConfiguration::multiplexing = false; - } - break; - case 'c': - std::cout << "use cert file :" << optarg << std::endl; - TestServerConfiguration::certFile = std::string(optarg); - break; - }//switch - }//while - - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - google::protobuf::ShutdownProtobufLibrary(); - - return ret; -} http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/messageboundtest.cpp ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/messageboundtest.cpp b/hedwig-client/src/main/cpp/test/messageboundtest.cpp deleted file mode 100644 index 9315e72..0000000 --- a/hedwig-client/src/main/cpp/test/messageboundtest.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gtest/gtest.h" - -#include "../lib/clientimpl.h" -#include <hedwig/exceptions.h> -#include <hedwig/callback.h> -#include <stdexcept> -#include <pthread.h> - -#include <log4cxx/logger.h> - -#include "util.h" - -static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("hedwig."__FILE__)); - -class MessageBoundConfiguration : public TestServerConfiguration { -public: - MessageBoundConfiguration() : TestServerConfiguration() {} - - virtual int getInt(const std::string& key, int defaultVal) const { - if (key == Configuration::SUBSCRIPTION_MESSAGE_BOUND) { - return 5; - } - return TestServerConfiguration::getInt(key, defaultVal); - } -}; - -class MessageBoundOrderCheckingMessageHandlerCallback : public Hedwig::MessageHandlerCallback { -public: - MessageBoundOrderCheckingMessageHandlerCallback(const int nextExpectedMsg) - : nextExpectedMsg(nextExpectedMsg) { - } - - virtual void consume(const std::string& topic, const std::string& subscriberId, - const Hedwig::Message& msg, Hedwig::OperationCallbackPtr& callback) { - boost::lock_guard<boost::mutex> lock(mutex); - - int thisMsg = atoi(msg.body().c_str()); - LOG4CXX_DEBUG(logger, "received message " << thisMsg); - if (thisMsg == nextExpectedMsg) { - nextExpectedMsg++; - } - // checking msgId - callback->operationComplete(); - } - - int nextExpected() { - return nextExpectedMsg; - } - -protected: - boost::mutex mutex; - int nextExpectedMsg; -}; - -void sendXExpectLastY(Hedwig::Publisher& pub, Hedwig::Subscriber& sub, const std::string& topic, - const std::string& subid, int X, int Y) { - for (int i = 0; i < X;) { - std::stringstream oss; - oss << i; - try { - pub.publish(topic, oss.str()); - ++i; - } catch (std::exception &e) { - LOG4CXX_WARN(logger, "Exception when publishing message " << i << " : " - << e.what()); - } - } - - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::ATTACH); - - MessageBoundOrderCheckingMessageHandlerCallback* cb = - new MessageBoundOrderCheckingMessageHandlerCallback(X - Y); - - Hedwig::MessageHandlerCallbackPtr handler(cb); - sub.startDelivery(topic, subid, handler); - - for (int i = 0; i < 100; i++) { - if (cb->nextExpected() == X) { - break; - } else { - sleep(1); - } - } - ASSERT_TRUE(cb->nextExpected() == X); - - sub.stopDelivery(topic, subid); - sub.closeSubscription(topic, subid); -} - -TEST(MessageBoundTest, testMessageBound) { - Hedwig::Configuration* conf = new MessageBoundConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - std::string topic = "testMessageBound"; - std::string subid = "testSubId"; - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - sub.closeSubscription(topic, subid); - - sendXExpectLastY(pub, sub, topic, subid, 100, 5); -} - -TEST(MessageBoundTest, testMultipleSubscribers) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::SubscriptionOptions options5; - options5.set_messagebound(5); - options5.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - Hedwig::SubscriptionOptions options20; - options20.set_messagebound(20); - options20.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - Hedwig::SubscriptionOptions optionsUnlimited; - optionsUnlimited.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - - std::string topic = "testMultipleSubscribers"; - std::string subid5 = "testSubId5"; - std::string subid20 = "testSubId20"; - std::string subidUnlimited = "testSubIdUnlimited"; - - sub.subscribe(topic, subid5, options5); - sub.closeSubscription(topic, subid5); - - sendXExpectLastY(pub, sub, topic, subid5, 1000, 5); - - sub.subscribe(topic, subid20, options20); - sub.closeSubscription(topic, subid20); - sendXExpectLastY(pub, sub, topic, subid20, 1000, 20); - - sub.subscribe(topic, subidUnlimited, optionsUnlimited); - sub.closeSubscription(topic, subidUnlimited); - - sendXExpectLastY(pub, sub, topic, subidUnlimited, 1000, 1000); - sub.unsubscribe(topic, subidUnlimited); - - sendXExpectLastY(pub, sub, topic, subid20, 1000, 20); - sub.unsubscribe(topic, subid20); - - sendXExpectLastY(pub, sub, topic, subid5, 1000, 5); - sub.unsubscribe(topic, subid5); -} - -TEST(MessageBoundTest, testUpdateMessageBound) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::SubscriptionOptions options5; - options5.set_messagebound(5); - options5.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - Hedwig::SubscriptionOptions options20; - options20.set_messagebound(20); - options20.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - Hedwig::SubscriptionOptions options10; - options10.set_messagebound(10); - options10.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - - std::string topic = "testUpdateMessageBound"; - std::string subid = "updateSubId"; - - sub.subscribe(topic, subid, options5); - sub.closeSubscription(topic, subid); - sendXExpectLastY(pub, sub, topic, subid, 50, 5); - - // update bound to 20 - sub.subscribe(topic, subid, options20); - sub.closeSubscription(topic, subid); - sendXExpectLastY(pub, sub, topic, subid, 50, 20); - - // update bound to 10 - sub.subscribe(topic, subid, options10); - sub.closeSubscription(topic, subid); - sendXExpectLastY(pub, sub, topic, subid, 50, 10); - - // message bound is not provided, no update - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - sub.closeSubscription(topic, subid); - sendXExpectLastY(pub, sub, topic, subid, 50, 10); -} http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/messagefiltertest.cpp ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/messagefiltertest.cpp b/hedwig-client/src/main/cpp/test/messagefiltertest.cpp deleted file mode 100644 index 907d95d..0000000 --- a/hedwig-client/src/main/cpp/test/messagefiltertest.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gtest/gtest.h" - -#include "../lib/clientimpl.h" -#include <hedwig/exceptions.h> -#include <hedwig/callback.h> -#include <stdexcept> -#include <pthread.h> - -#include <log4cxx/logger.h> - -#include "util.h" - -static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("hedwig."__FILE__)); - -class MessageFilterConfiguration : public TestServerConfiguration { -public: - MessageFilterConfiguration() : TestServerConfiguration() {} - - virtual bool getBool(const std::string& key, bool defaultVal) const { - if (key == Configuration::SUBSCRIBER_AUTOCONSUME) { - return false; - } else { - return TestServerConfiguration::getBool(key, defaultVal); - } - } -}; - -class ModMessageFilter : public Hedwig::ClientMessageFilter { -public: - ModMessageFilter() : mod(0) { - } - - virtual void setSubscriptionPreferences(const std::string& topic, const std::string& subscriberId, - const Hedwig::SubscriptionPreferencesPtr& preferences) { - if (!preferences->has_options()) { - return; - } - - const Hedwig::Map& userOptions = preferences->options(); - int numOpts = userOptions.entries_size(); - for (int i=0; i<numOpts; i++) { - const Hedwig::Map_Entry& opt = userOptions.entries(i); - const std::string& key = opt.key(); - if ("MOD" != key) { - continue; - } - const std::string& value = opt.value(); - mod = atoi(value.c_str()); - break; - } - return; - } - virtual bool testMessage(const Hedwig::Message& message) { - int value = atoi(message.body().c_str()); - return 0 == value % mod; - } -private: - int mod; -}; - -class GapCheckingMessageHandlerCallback : public Hedwig::MessageHandlerCallback { -public: - GapCheckingMessageHandlerCallback(Hedwig::Subscriber& sub, - const int start, const int nextValue, - const int gap, bool doConsume) - : sub(sub), start(start), nextValue(nextValue), gap(gap), doConsume(doConsume) { - } - - virtual void consume(const std::string& topic, const std::string& subscriberId, - const Hedwig::Message& msg, Hedwig::OperationCallbackPtr& callback) { - boost::lock_guard<boost::mutex> lock(mutex); - - int value = atoi(msg.body().c_str()); - if(value > start) { - LOG4CXX_DEBUG(logger, "received message " << value); - if (value == nextValue) { - nextValue += gap; - } - } - callback->operationComplete(); - if (doConsume) { - sub.consume(topic, subscriberId, msg.msgid()); - } - } - - int nextExpected() { - return nextValue; - } - -protected: - boost::mutex mutex; - Hedwig::Subscriber& sub; - int start; - int nextValue; - int gap; - bool doConsume; -}; - -void publishNums(Hedwig::Publisher& pub, const std::string& topic, - int start, int num, int M) { - for (int i=1; i<=num; i++) { - int value = start + i; - int mod = value % M; - - std::stringstream valSS; - valSS << value; - - std::stringstream modSS; - modSS << mod; - - Hedwig::Message msg; - msg.set_body(valSS.str()); - Hedwig::MessageHeader* header = msg.mutable_header(); - Hedwig::Map* properties = header->mutable_properties(); - Hedwig::Map_Entry* entry = properties->add_entries(); - entry->set_key("mod"); - entry->set_value(modSS.str()); - - pub.publish(topic, msg); - } -} - -void receiveNumModM(Hedwig::Subscriber& sub, - const std::string& topic, const std::string& subid, - int start, int num, int M, bool consume) { - Hedwig::SubscriptionOptions options; - options.set_createorattach(Hedwig::SubscribeRequest::ATTACH); - Hedwig::Map* userOptions = options.mutable_options(); - Hedwig::Map_Entry* opt = userOptions->add_entries(); - opt->set_key("MOD"); - - std::stringstream modSS; - modSS << M; - opt->set_value(modSS.str()); - - sub.subscribe(topic, subid, options); - - int base = start + M - start % M; - int end = base + num * M; - - GapCheckingMessageHandlerCallback * cb = - new GapCheckingMessageHandlerCallback(sub, start, base, M, consume); - Hedwig::MessageHandlerCallbackPtr handler(cb); - Hedwig::ClientMessageFilterPtr filter(new ModMessageFilter()); - - sub.startDeliveryWithFilter(topic, subid, handler, filter); - - for (int i = 0; i < 100; i++) { - if (cb->nextExpected() == end) { - break; - } else { - sleep(1); - } - } - ASSERT_TRUE(cb->nextExpected() == end); - - sub.stopDelivery(topic, subid); - sub.closeSubscription(topic, subid); -} - -TEST(MessageFilterTest, testNullMessageFilter) { - Hedwig::Configuration* conf = new MessageFilterConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - - std::string topic = "testNullMessageFilter"; - std::string subid = "myTestSubid"; - - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - - GapCheckingMessageHandlerCallback * cb = - new GapCheckingMessageHandlerCallback(sub, 0, 0, 0, true); - Hedwig::MessageHandlerCallbackPtr handler(cb); - Hedwig::ClientMessageFilterPtr filter(new ModMessageFilter()); - - ASSERT_THROW(sub.startDeliveryWithFilter(topic, subid, handler, - Hedwig::ClientMessageFilterPtr()), - Hedwig::NullMessageFilterException); - ASSERT_THROW(sub.startDeliveryWithFilter(topic, subid, - Hedwig::MessageHandlerCallbackPtr(), filter), - Hedwig::NullMessageHandlerException); -} - -TEST(MessageFilterTest, testMessageFilter) { - Hedwig::Configuration* conf = new MessageFilterConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - std::string topic = "testMessageFilter"; - std::string subid = "myTestSubid"; - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - sub.closeSubscription(topic, subid); - - publishNums(pub, topic, 0, 100, 2); - receiveNumModM(sub, topic, subid, 0, 50, 2, true); -} - -TEST(MessageFilterTest, testUpdateMessageFilter) { - Hedwig::Configuration* conf = new MessageFilterConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - std::string topic = "testUpdateMessageFilter"; - std::string subid = "myTestSubid"; - - sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - sub.closeSubscription(topic, subid); - - publishNums(pub, topic, 0, 100, 2); - receiveNumModM(sub, topic, subid, 0, 50, 2, false); - receiveNumModM(sub, topic, subid, 0, 25, 4, false); - receiveNumModM(sub, topic, subid, 0, 33, 3, false); -} http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/multiplextest.cpp ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/multiplextest.cpp b/hedwig-client/src/main/cpp/test/multiplextest.cpp deleted file mode 100644 index 534d9ef..0000000 --- a/hedwig-client/src/main/cpp/test/multiplextest.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gtest/gtest.h" - -#include "../lib/clientimpl.h" -#include <hedwig/exceptions.h> -#include <hedwig/callback.h> -#include <stdexcept> -#include <pthread.h> - -#include <log4cxx/logger.h> - -#include "util.h" - -static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("hedwig."__FILE__)); - -class MultiplexConfiguration : public TestServerConfiguration { -public: - MultiplexConfiguration() : TestServerConfiguration() {} - - virtual bool getBool(const std::string& key, bool defaultVal) const { - if (key == Configuration::SUBSCRIBER_AUTOCONSUME) { - return false; - } else if (key == Configuration::SUBSCRIPTION_CHANNEL_SHARING_ENABLED) { - return true; - } else { - return TestServerConfiguration::getBool(key, defaultVal); - } - } -}; - -class MultiplexMessageHandlerCallback : public Hedwig::MessageHandlerCallback { -public: - MultiplexMessageHandlerCallback(Hedwig::Subscriber& sub, - const int start, const int numMsgsAtFirstRun, - const bool receiveSecondRun, - const int numMsgsAtSecondRun) - : sub(sub), next(start), start(start), numMsgsAtFirstRun(numMsgsAtFirstRun), - numMsgsAtSecondRun(numMsgsAtSecondRun), receiveSecondRun(receiveSecondRun) { - } - - virtual void consume(const std::string& topic, const std::string& subscriberId, - const Hedwig::Message& msg, Hedwig::OperationCallbackPtr& callback) { - const int value = atoi(msg.body().c_str()); - LOG4CXX_DEBUG(logger, "received message " << value); - boost::lock_guard<boost::mutex> lock(mutex); - if (value == next) { - ++next; - } else { - LOG4CXX_ERROR(logger, "Did not receive expected value " << next << ", got " << value); - next = 0; - firstLatch.setSuccess(false); - firstLatch.notify(); - secondLatch.setSuccess(false); - secondLatch.notify(); - } - if (numMsgsAtFirstRun + start == next) { - firstLatch.setSuccess(true); - firstLatch.notify(); - } - if (receiveSecondRun) { - if (numMsgsAtFirstRun + numMsgsAtSecondRun + start == next) { - secondLatch.setSuccess(true); - secondLatch.notify(); - } - } else { - if (numMsgsAtFirstRun + start + 1 == next) { - secondLatch.setSuccess(true); - secondLatch.notify(); - } - } - callback->operationComplete(); - sub.consume(topic, subscriberId, msg.msgid()); - } - - void checkFirstRun() { - firstLatch.timed_wait(10000); - ASSERT_TRUE(firstLatch.wasSuccess()); - ASSERT_EQ(numMsgsAtFirstRun + start, next); - } - - void checkSecondRun() { - if (receiveSecondRun) { - secondLatch.timed_wait(10000); - ASSERT_TRUE(secondLatch.wasSuccess()); - ASSERT_EQ(numMsgsAtFirstRun + numMsgsAtSecondRun + start, next); - } else { - secondLatch.timed_wait(3000); - ASSERT_TRUE(!secondLatch.wasSuccess()); - ASSERT_EQ(numMsgsAtFirstRun + start, next); - } - } - -protected: - Hedwig::Subscriber& sub; - boost::mutex mutex; - int next; - const int start; - const int numMsgsAtFirstRun; - const int numMsgsAtSecondRun; - SimpleWaitCondition firstLatch; - SimpleWaitCondition secondLatch; - const bool receiveSecondRun; -}; - -class MultiplexThrottleDeliveryMessageHandlerCallback : public Hedwig::MessageHandlerCallback { -public: - MultiplexThrottleDeliveryMessageHandlerCallback(Hedwig::Subscriber& sub, - const int start, const int numMsgs, - const bool enableThrottle, - const int numMsgsThrottle) - : sub(sub), next(start), start(start), numMsgs(numMsgs), - numMsgsThrottle(numMsgsThrottle), enableThrottle(enableThrottle) { - } - - virtual void consume(const std::string& topic, const std::string& subscriberId, - const Hedwig::Message& msg, Hedwig::OperationCallbackPtr& callback) { - const int value = atoi(msg.body().c_str()); - LOG4CXX_DEBUG(logger, "received message " << value); - boost::lock_guard<boost::mutex> lock(mutex); - if (value == next) { - ++next; - } else { - LOG4CXX_ERROR(logger, "Did not receive expected value " << next << ", got " << value); - next = 0; - throttleLatch.setSuccess(false); - throttleLatch.notify(); - nonThrottleLatch.setSuccess(false); - nonThrottleLatch.notify(); - } - if (next == numMsgsThrottle + start + 1) { - throttleLatch.setSuccess(true); - throttleLatch.notify(); - } else if (next == numMsgs + 1) { - nonThrottleLatch.setSuccess(true); - nonThrottleLatch.notify(); - } - callback->operationComplete(); - if (enableThrottle) { - if (next > numMsgsThrottle + start) { - sub.consume(topic, subscriberId, msg.msgid()); - } - } else { - sub.consume(topic, subscriberId, msg.msgid()); - } - } - - void checkThrottle() { - if (enableThrottle) { - throttleLatch.timed_wait(3000); - ASSERT_TRUE(!throttleLatch.wasSuccess()); - ASSERT_EQ(numMsgsThrottle + start, next); - } else { - throttleLatch.timed_wait(10000); - ASSERT_TRUE(throttleLatch.wasSuccess()); - nonThrottleLatch.timed_wait(10000); - ASSERT_TRUE(nonThrottleLatch.wasSuccess()); - ASSERT_EQ(numMsgs + start, next); - } - } - - void checkAfterThrottle() { - if (enableThrottle) { - nonThrottleLatch.timed_wait(10000); - ASSERT_TRUE(nonThrottleLatch.wasSuccess()); - ASSERT_EQ(numMsgs + start, next); - } - } - -protected: - Hedwig::Subscriber& sub; - boost::mutex mutex; - int next; - const int start; - const int numMsgs; - const int numMsgsThrottle; - const bool enableThrottle; - SimpleWaitCondition throttleLatch; - SimpleWaitCondition nonThrottleLatch; -}; - -TEST(MultiplexTest, testStopDelivery) { - Hedwig::Configuration* conf = new MultiplexConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - const int numMsgs = 20; - std::string topic1 = "testStopDelivery-1"; - std::string subid1 = "mysubid-1"; - std::string topic2 = "testStopDelivery-2"; - std::string subid2 = "mysubid-2"; - - MultiplexMessageHandlerCallback * cb11 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, true, numMsgs); - MultiplexMessageHandlerCallback * cb12 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, false, 0); - MultiplexMessageHandlerCallback * cb21 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, false, 0); - MultiplexMessageHandlerCallback * cb22 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, true, numMsgs); - - Hedwig::MessageHandlerCallbackPtr handler11(cb11); - Hedwig::MessageHandlerCallbackPtr handler12(cb12); - Hedwig::MessageHandlerCallbackPtr handler21(cb21); - Hedwig::MessageHandlerCallbackPtr handler22(cb22); - - sub.subscribe(topic1, subid1, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic1, subid2, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic2, subid1, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic2, subid2, Hedwig::SubscribeRequest::CREATE); - - // start deliveries - sub.startDelivery(topic1, subid1, handler11); - sub.startDelivery(topic1, subid2, handler12); - sub.startDelivery(topic2, subid1, handler21); - sub.startDelivery(topic2, subid2, handler22); - - // first publish - for (int i = 1; i <= numMsgs; i++) { - std::stringstream oss; - oss << i; - pub.publish(topic1, oss.str()); - pub.publish(topic2, oss.str()); - } - - // check first run - cb11->checkFirstRun(); - cb12->checkFirstRun(); - cb21->checkFirstRun(); - cb22->checkFirstRun(); - - // stop delivery for <topic1, subscriber2> and <topic2, subscriber1> - sub.stopDelivery(topic1, subid2); - sub.stopDelivery(topic2, subid1); - - // second publish - for (int i = numMsgs+1; i <= 2*numMsgs; i++) { - std::stringstream oss; - oss << i; - pub.publish(topic1, oss.str()); - pub.publish(topic2, oss.str()); - } - - cb11->checkSecondRun(); - cb12->checkSecondRun(); - cb21->checkSecondRun(); - cb22->checkSecondRun(); -} - -TEST(MultiplexTest, testCloseSubscription) { - Hedwig::Configuration* conf = new MultiplexConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - const int numMsgs = 20; - std::string topic1 = "testCloseSubscription-1"; - std::string subid1 = "mysubid-1"; - std::string topic2 = "testCloseSubscription-2"; - std::string subid2 = "mysubid-2"; - - MultiplexMessageHandlerCallback * cb11 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, true, numMsgs); - MultiplexMessageHandlerCallback * cb12 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, false, 0); - MultiplexMessageHandlerCallback * cb21 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, false, 0); - MultiplexMessageHandlerCallback * cb22 = - new MultiplexMessageHandlerCallback(sub, 1, numMsgs, true, numMsgs); - - Hedwig::MessageHandlerCallbackPtr handler11(cb11); - Hedwig::MessageHandlerCallbackPtr handler12(cb12); - Hedwig::MessageHandlerCallbackPtr handler21(cb21); - Hedwig::MessageHandlerCallbackPtr handler22(cb22); - - sub.subscribe(topic1, subid1, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic1, subid2, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic2, subid1, Hedwig::SubscribeRequest::CREATE); - sub.subscribe(topic2, subid2, Hedwig::SubscribeRequest::CREATE); - - // start deliveries - sub.startDelivery(topic1, subid1, handler11); - sub.startDelivery(topic1, subid2, handler12); - sub.startDelivery(topic2, subid1, handler21); - sub.startDelivery(topic2, subid2, handler22); - - // first publish - for (int i = 1; i <= numMsgs; i++) { - std::stringstream oss; - oss << i; - pub.publish(topic1, oss.str()); - pub.publish(topic2, oss.str()); - } - - // check first run - cb11->checkFirstRun(); - cb12->checkFirstRun(); - cb21->checkFirstRun(); - cb22->checkFirstRun(); - - // close subscription for <topic1, subscriber2> and <topic2, subscriber1> - sub.closeSubscription(topic1, subid2); - sub.closeSubscription(topic2, subid1); - - // second publish - for (int i = numMsgs+1; i <= 2*numMsgs; i++) { - std::stringstream oss; - oss << i; - pub.publish(topic1, oss.str()); - pub.publish(topic2, oss.str()); - } - - cb11->checkSecondRun(); - cb12->checkSecondRun(); - cb21->checkSecondRun(); - cb22->checkSecondRun(); -} - -TEST(MultiplexTest, testThrottle) { - Hedwig::Configuration* conf = new MultiplexConfiguration(); - std::auto_ptr<Hedwig::Configuration> confptr(conf); - - Hedwig::Client* client = new Hedwig::Client(*conf); - std::auto_ptr<Hedwig::Client> clientptr(client); - - Hedwig::Subscriber& sub = client->getSubscriber(); - Hedwig::Publisher& pub = client->getPublisher(); - - const int numMsgs = 10; - std::string topic1 = "testThrottle-1"; - std::string subid1 = "mysubid-1"; - std::string topic2 = "testThrottle-2"; - std::string subid2 = "mysubid-2"; - - MultiplexThrottleDeliveryMessageHandlerCallback * cb11 = - new MultiplexThrottleDeliveryMessageHandlerCallback(sub, 1, 3*numMsgs, false, numMsgs); - MultiplexThrottleDeliveryMessageHandlerCallback * cb12 = - new MultiplexThrottleDeliveryMessageHandlerCallback(sub, 1, 3*numMsgs, true, numMsgs); - MultiplexThrottleDeliveryMessageHandlerCallback * cb21 = - new MultiplexThrottleDeliveryMessageHandlerCallback(sub, 1, 3*numMsgs, true, numMsgs); - MultiplexThrottleDeliveryMessageHandlerCallback * cb22 = - new MultiplexThrottleDeliveryMessageHandlerCallback(sub, 1, 3*numMsgs, false, numMsgs); - - Hedwig::MessageHandlerCallbackPtr handler11(cb11); - Hedwig::MessageHandlerCallbackPtr handler12(cb12); - Hedwig::MessageHandlerCallbackPtr handler21(cb21); - Hedwig::MessageHandlerCallbackPtr handler22(cb22); - - Hedwig::SubscriptionOptions options; - options.set_createorattach(Hedwig::SubscribeRequest::CREATE_OR_ATTACH); - options.set_messagewindowsize(numMsgs); - - sub.subscribe(topic1, subid1, options); - sub.subscribe(topic1, subid2, options); - sub.subscribe(topic2, subid1, options); - sub.subscribe(topic2, subid2, options); - - // start deliveries - sub.startDelivery(topic1, subid1, handler11); - sub.startDelivery(topic1, subid2, handler12); - sub.startDelivery(topic2, subid1, handler21); - sub.startDelivery(topic2, subid2, handler22); - - // first publish - for (int i = 1; i <= 3*numMsgs; i++) { - std::stringstream oss; - oss << i; - pub.publish(topic1, oss.str()); - pub.publish(topic2, oss.str()); - } - - // check first run - cb11->checkThrottle(); - cb12->checkThrottle(); - cb21->checkThrottle(); - cb22->checkThrottle(); - - // consume messages to not throttle them - for (int i=1; i<=numMsgs; i++) { - Hedwig::MessageSeqId msgid; - msgid.set_localcomponent(i); - sub.consume(topic1, subid2, msgid); - sub.consume(topic2, subid1, msgid); - } - - cb11->checkAfterThrottle(); - cb12->checkAfterThrottle(); - cb21->checkAfterThrottle(); - cb22->checkAfterThrottle(); -} http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a8d62b1/hedwig-client/src/main/cpp/test/publishtest.cpp ---------------------------------------------------------------------- diff --git a/hedwig-client/src/main/cpp/test/publishtest.cpp b/hedwig-client/src/main/cpp/test/publishtest.cpp deleted file mode 100644 index 46b146a..0000000 --- a/hedwig-client/src/main/cpp/test/publishtest.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gtest/gtest.h" - -#include "../lib/clientimpl.h" -#include <hedwig/exceptions.h> -#include <hedwig/callback.h> -#include <stdexcept> -#include <pthread.h> - -#include <log4cxx/logger.h> - -#include "util.h" - -static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("hedwig."__FILE__)); - -TEST(PublishTest, testPublishByMessage) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::Message syncMsg; - syncMsg.set_body("sync publish by Message"); - pub.publish("testTopic", syncMsg); - - SimpleWaitCondition* cond = new SimpleWaitCondition(); - Hedwig::OperationCallbackPtr testcb(new TestCallback(cond)); - Hedwig::Message asyncMsg; - asyncMsg.set_body("async publish by Message"); - pub.asyncPublish("testTopic", asyncMsg, testcb); - cond->wait(); - ASSERT_TRUE(cond->wasSuccess()); - delete cond; - - delete client; - delete conf; -} - -TEST(PublishTest, testSyncPublish) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - pub.publish("testTopic", "testMessage 1"); - - delete client; - delete conf; -} - -TEST(PublishTest, testSyncPublishWithResponse) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - int numMsgs = 20; - for(int i=1; i<=numMsgs; i++) { - Hedwig::PublishResponsePtr pubResponse = pub.publish("testSyncPublishWithResponse", "testMessage " + i); - ASSERT_EQ(i, (int)pubResponse->publishedmsgid().localcomponent()); - } - - delete client; - delete conf; -} - -TEST(PublishTest, testAsyncPublish) { - SimpleWaitCondition* cond = new SimpleWaitCondition(); - - Hedwig::Configuration* conf = new TestServerConfiguration(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::OperationCallbackPtr testcb(new TestCallback(cond)); - pub.asyncPublish("testTopic", "async test message", testcb); - - cond->wait(); - - ASSERT_TRUE(cond->wasSuccess()); - - delete cond; - delete client; - delete conf; -} - -TEST(PublishTest, testAsyncPublishWithResponse) { - Hedwig::Configuration* conf = new TestServerConfiguration(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - int numMsgs = 20; - for (int i=1; i<=numMsgs; i++) { - SimpleWaitCondition* cond = new SimpleWaitCondition(); - TestPublishResponseCallback* callback = - new TestPublishResponseCallback(cond); - Hedwig::PublishResponseCallbackPtr testcb(callback); - Hedwig::Message asyncMsg; - asyncMsg.set_body("testAsyncPublishWithResponse-" + i); - pub.asyncPublishWithResponse("testAsyncPublishWithResponse", asyncMsg, testcb); - - cond->wait(); - - ASSERT_TRUE(cond->wasSuccess()); - ASSERT_EQ(i, (int)callback->getResponse()->publishedmsgid().localcomponent()); - - delete cond; - } - delete client; - delete conf; -} - -TEST(PublishTest, testMultipleAsyncPublish) { - SimpleWaitCondition* cond1 = new SimpleWaitCondition(); - SimpleWaitCondition* cond2 = new SimpleWaitCondition(); - SimpleWaitCondition* cond3 = new SimpleWaitCondition(); - - Hedwig::Configuration* conf = new TestServerConfiguration(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::OperationCallbackPtr testcb1(new TestCallback(cond1)); - Hedwig::OperationCallbackPtr testcb2(new TestCallback(cond2)); - Hedwig::OperationCallbackPtr testcb3(new TestCallback(cond3)); - - pub.asyncPublish("testTopic", "async test message #1", testcb1); - pub.asyncPublish("testTopic", "async test message #2", testcb2); - pub.asyncPublish("testTopic", "async test message #3", testcb3); - - cond3->wait(); - ASSERT_TRUE(cond3->wasSuccess()); - cond2->wait(); - ASSERT_TRUE(cond2->wasSuccess()); - cond1->wait(); - ASSERT_TRUE(cond1->wasSuccess()); - - delete cond3; delete cond2; delete cond1; - delete client; - delete conf; -} - -class UnresolvedDefaultHostCallback : public Hedwig::OperationCallback { -public: - UnresolvedDefaultHostCallback(SimpleWaitCondition* cond) : cond(cond) {} - - virtual void operationComplete() { - cond->setSuccess(false); - cond->notify(); - } - - virtual void operationFailed(const std::exception& exception) { - LOG4CXX_ERROR(logger, "Failed with exception : " << exception.what()); - cond->setSuccess(exception.what() == Hedwig::HostResolutionException().what()); - cond->notify(); - } - -private: - SimpleWaitCondition *cond; -}; - -TEST(PublishTest, testPublishWithUnresolvedDefaultHost) { - std::string invalidHost(""); - Hedwig::Configuration* conf = new TestServerConfiguration(invalidHost); - - SimpleWaitCondition* cond = new SimpleWaitCondition(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - Hedwig::OperationCallbackPtr testcb(new UnresolvedDefaultHostCallback(cond)); - - pub.asyncPublish("testTopic", "testPublishWithUnresolvedDefaultHost", testcb); - - cond->wait(); - ASSERT_TRUE(cond->wasSuccess()); - - delete cond; - delete client; - delete conf; -} - /* void simplePublish() { - LOG4CXX_DEBUG(logger, ">>> simplePublish"); - SimpleWaitCondition* cond = new SimpleWaitCondition(); - - Hedwig::Configuration* conf = new Configuration1(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - - Hedwig::OperationCallbackPtr testcb(new TestCallback(cond)); - pub.asyncPublish("foobar", "barfoo", testcb); - - LOG4CXX_DEBUG(logger, "wait for response"); - cond->wait(); - delete cond; - LOG4CXX_DEBUG(logger, "got response"); - - - delete client; - delete conf; - LOG4CXX_DEBUG(logger, "<<< simplePublish"); - } - - class MyMessageHandler : public Hedwig::MessageHandlerCallback { - public: - MyMessageHandler(SimpleWaitCondition* cond) : cond(cond) {} - - void consume(const std::string& topic, const std::string& subscriberId, const Hedwig::Message& msg, Hedwig::OperationCallbackPtr& callback) { - LOG4CXX_DEBUG(logger, "Topic: " << topic << " subscriberId: " << subscriberId); - LOG4CXX_DEBUG(logger, " Message: " << msg.body()); - - callback->operationComplete(); - cond->setTrue(); - cond->signal(); - } - private: - SimpleWaitCondition* cond; - };*/ - /* - void simplePublishAndSubscribe() { - SimpleWaitCondition* cond1 = new SimpleWaitCondition(); - SimpleWaitCondition* cond2 = new SimpleWaitCondition(); - SimpleWaitCondition* cond3 = new SimpleWaitCondition(); - - Hedwig::Configuration* conf = new Configuration1(); - Hedwig::Client* client = new Hedwig::Client(*conf); - Hedwig::Publisher& pub = client->getPublisher(); - Hedwig::Subscriber& sub = client->getSubscriber(); - - std::string topic("foobar"); - std::string sid("mysubscriber"); - Hedwig::OperationCallbackPtr testcb1(new TestCallback(cond1)); - sub.asyncSubscribe(topic, sid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH, testcb1); - Hedwig::MessageHandlerCallbackPtr messagecb(new MyMessageHandler(cond2)); - sub.startDelivery(topic, sid, messagecb); - cond1->wait(); - - Hedwig::OperationCallbackPtr testcb2(new TestCallback(cond3)); - pub.asyncPublish("foobar", "barfoo", testcb2); - cond3->wait(); - cond2->wait(); - - delete cond1; - delete cond3; - delete cond2; - - delete client; - delete conf; - } - - void publishAndSubscribeWithRedirect() { - SimpleWaitCondition* cond1 = new SimpleWaitCondition(); - SimpleWaitCondition* cond2 = new SimpleWaitCondition(); - SimpleWaitCondition* cond3 = new SimpleWaitCondition(); - SimpleWaitCondition* cond4 = new SimpleWaitCondition(); - - Hedwig::Configuration* publishconf = new Configuration1(); - Hedwig::Configuration* subscribeconf = new Configuration2(); - - Hedwig::Client* publishclient = new Hedwig::Client(*publishconf); - Hedwig::Publisher& pub = publishclient->getPublisher(); - - Hedwig::Client* subscribeclient = new Hedwig::Client(*subscribeconf); - Hedwig::Subscriber& sub = subscribeclient->getSubscriber(); - - LOG4CXX_DEBUG(logger, "publishing"); - Hedwig::OperationCallbackPtr testcb2(new TestCallback(cond3)); - pub.asyncPublish("foobar", "barfoo", testcb2); - cond3->wait(); - - LOG4CXX_DEBUG(logger, "Subscribing"); - std::string topic("foobar"); - std::string sid("mysubscriber"); - Hedwig::OperationCallbackPtr testcb1(new TestCallback(cond1)); - sub.asyncSubscribe(topic, sid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH, testcb1); - LOG4CXX_DEBUG(logger, "Starting delivery"); - Hedwig::MessageHandlerCallbackPtr messagecb(new MyMessageHandler(cond2)); - sub.startDelivery(topic, sid, messagecb); - - LOG4CXX_DEBUG(logger, "Subscribe wait"); - cond1->wait(); - - Hedwig::OperationCallbackPtr testcb3(new TestCallback(cond4)); - pub.asyncPublish("foobar", "barfoo", testcb3); - cond4->wait(); - - - LOG4CXX_DEBUG(logger, "Delivery wait"); - - cond2->wait(); - - sub.stopDelivery(topic, sid); - - delete cond1; - delete cond3; - delete cond2; - delete cond4; - - delete subscribeclient; - delete publishclient; - delete publishconf; - delete subscribeconf; - }*/