Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kuenishi committed Jul 20, 2012
2 parents e2a2397 + 78058d2 commit 9b24016
Show file tree
Hide file tree
Showing 61 changed files with 1,386 additions and 1,033 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ LGPL 2.1
Update history
--------------

0.3.1 2012/7/20
~~~~~~~~~~~~~~~

Improvements
- RPC enhances to many exceptions and provide new error handling interface (#49)
- JSON interface for set_config APIs (#44)
- jubavisor close zk connection correctly (#74)

Bugfix
- #73, #69, #66, #65

Release 0.3.0 2012/6/29
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 6 additions & 0 deletions src/classifier/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ def build(bld):
target = "classifier_test",
includes = '.',
use = 'jubatus_classifier jubastorage')

bld.install_files('${PREFIX}/include/jubatus/classifier', [
'classifier_base.hpp',
'classifier_factory.hpp',
'classifier_type.hpp',
])
19 changes: 13 additions & 6 deletions src/common/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ typedef error_info<struct error_at_file_, char const *> error_at_file;
typedef error_info<struct error_at_func_, char const *> error_at_func;
typedef error_info<struct error_at_line_, int> error_at_line;
typedef error_info<struct error_errno_, int> error_errno;
inline std::string to_string(const error_errno& info)
{
std::string msg(strerror(info.value()));
msg += " (" + pfi::lang::lexical_cast<std::string>(info.value()) + ")";
return msg;
}

typedef error_info<struct error_file_name_, std::string> error_file_name;
typedef error_info<struct error_api_func_, std::string> error_api_func;
typedef error_info<struct error_message_, std::string> error_message;
Expand Down Expand Up @@ -70,7 +77,7 @@ class jubatus_exception : public std::exception {
virtual exception_thrower_ptr thrower() const = 0;

template <class Exception>
friend Exception const & add_info(Exception const & e, pfi::lang::shared_ptr<error_info_base> info);
friend const Exception& add_info(const Exception& e, pfi::lang::shared_ptr<error_info_base> info);

std::string name() const throw()
{
Expand All @@ -96,20 +103,20 @@ class jubatus_exception : public std::exception {
};

template <class Exception>
inline Exception const & add_info(Exception const & e, pfi::lang::shared_ptr<error_info_base> info)
inline const Exception& add_info(const Exception& e, pfi::lang::shared_ptr<error_info_base> info)
{
e.info_list_.push_back(info);
return e;
}

template <class Exception, class Tag, class V>
inline Exception const & operator <<(Exception const & e, error_info<Tag, V> const & info)
inline const Exception& operator <<(const Exception& e, const error_info<Tag, V>& info)
{
return add_info(e, pfi::lang::shared_ptr<error_info_base>(new error_info<Tag, V>(info)));
}

template <class Exception>
inline Exception const & operator <<(Exception const & e, pfi::lang::shared_ptr<error_info_base> info)
inline const Exception& operator <<(const Exception& e, pfi::lang::shared_ptr<error_info_base> info)
{
return add_info(e, info);
}
Expand Down Expand Up @@ -174,7 +181,7 @@ class jubaexception : public jubatus_exception {
};

template <class Exception>
inline Exception const & operator <<(Exception const & e, exception_thrower_binder_type const &)
inline const Exception& operator <<(const Exception& e, const exception_thrower_binder_type&)
{
e.bind_thrower(exception_thrower_ptr(new exception_thrower_impl<Exception>(e)));
return e;
Expand Down Expand Up @@ -205,7 +212,7 @@ class runtime_error : public jubaexception<runtime_error> {

namespace detail {
template <class Exception>
exception_thrower_ptr current_std_exception(Exception const & e)
exception_thrower_ptr current_std_exception(const Exception& e)
{
return exception_thrower_ptr(new exception_thrower_impl<Exception>(e));
}
Expand Down
52 changes: 14 additions & 38 deletions src/common/exception_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#pragma once

#include <cstring>
#include <typeinfo>
#include <pficommon/lang/shared_ptr.h>
Expand All @@ -29,7 +31,11 @@ std::string demangle_symbol(const char *symbol);

class error_info_base {
public:
virtual bool splitter() const = 0;
virtual bool splitter() const
{
return false;
}

virtual std::string tag_typeid_name() const = 0;
virtual std::string as_string() const = 0;

Expand All @@ -40,6 +46,12 @@ class error_info_base {
template <class Tag, class V>
class error_info;

template <class Tag, class V>
inline std::string to_string(const error_info<Tag, V>& info)
{
return pfi::lang::lexical_cast<std::string, V>(info.value());
}

template<>
class error_info<struct error_splitter_, void> : public error_info_base {
public:
Expand All @@ -60,42 +72,13 @@ class error_info<struct error_splitter_, void> : public error_info_base {
}
};

template<>
class error_info<struct error_errno_, int> : public error_info_base {
public:
error_info(int err)
: value_(err)
{
}

bool splitter() const
{
return false;
}

std::string tag_typeid_name() const
{
return jubatus::exception::detail::demangle_symbol(typeid(struct error_errno_*).name());
}

std::string as_string() const
{
std::string msg(strerror(value_));
msg += " (" + pfi::lang::lexical_cast<std::string>(value_) + ")";
return msg;
}
private:
int value_;
};

template <class Tag, class V>
class error_info : public error_info_base {
public:
typedef V value_type;
error_info(value_type v);
~error_info() throw();

bool splitter() const;
std::string tag_typeid_name() const;
std::string as_string() const;

Expand All @@ -119,12 +102,6 @@ inline error_info<Tag, V>::~error_info() throw()
{
}

template <class Tag, class V>
inline bool error_info<Tag, V>::splitter() const
{
return false;
}

template <class Tag, class V>
inline std::string error_info<Tag, V>::tag_typeid_name() const
{
Expand All @@ -134,8 +111,7 @@ inline std::string error_info<Tag, V>::tag_typeid_name() const
template <class Tag, class V>
inline std::string error_info<Tag, V>::as_string() const
{
// TODO: implement generic and user defined converter to std::string
return pfi::lang::lexical_cast<std::string>(value_);
return to_string(*this);
}

} // exception
Expand Down
74 changes: 50 additions & 24 deletions src/common/exception_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ using jubatus::exception::error_info_list_t;
using jubatus::exception::exception_thrower_ptr;
using jubatus::exception::jubaexception;

namespace jubatus {
namespace exception {
typedef error_info<struct test_my_tag_, int> test_my_tag;
inline string to_string(const test_my_tag& info)
{
return pfi::lang::lexical_cast<string>(info.value() * 2);
}
} // exception
} // jubatus

TEST(error_info, defined_tag)
{
jubatus::exception::test_my_tag tag(1);

EXPECT_FALSE(tag.splitter());
EXPECT_EQ(1, tag.value());
}

TEST(error_info, error_info_base)
{
jubatus::exception::test_my_tag tag(1);
const jubatus::exception::error_info_base& base = tag;

EXPECT_FALSE(base.splitter());
EXPECT_EQ("2", base.as_string());
}

namespace test_exception {
class ore_exception : public jubaexception<ore_exception> {
public:
Expand All @@ -56,7 +83,7 @@ class derived_exception : public jubatus::exception::runtime_error {
// multi-derived exception cannot get as it thrower
// because thrower() returns exception_thrower_impl<runtime_error>
};
}
} // test_exception

TEST(exception, custom_exception)
{
Expand Down Expand Up @@ -145,10 +172,10 @@ TEST(exception, exception_info_macro)
} catch (const jubatus_exception& e) {
error_info_list_t info_list = e.error_info();
EXPECT_EQ(4, info_list.size());
EXPECT_EQ(false, info_list[0]->splitter());
EXPECT_EQ(false, info_list[1]->splitter());
EXPECT_EQ(false, info_list[2]->splitter());
EXPECT_EQ(true, info_list[3]->splitter());
EXPECT_FALSE(info_list[0]->splitter());
EXPECT_FALSE(info_list[1]->splitter());
EXPECT_FALSE(info_list[2]->splitter());
EXPECT_TRUE(info_list[3]->splitter());
}
}

Expand All @@ -161,12 +188,12 @@ TEST(exception, exception_info_macro_additional)
} catch (const jubatus_exception& e) {
error_info_list_t info_list = e.error_info();
EXPECT_EQ(5, info_list.size());
EXPECT_EQ(false, info_list[0]->splitter());
EXPECT_FALSE(info_list[0]->splitter());
EXPECT_EQ(string("message"), info_list[0]->as_string());
EXPECT_EQ(false, info_list[1]->splitter());
EXPECT_EQ(false, info_list[2]->splitter());
EXPECT_EQ(false, info_list[3]->splitter());
EXPECT_EQ(true, info_list[4]->splitter());
EXPECT_FALSE(info_list[1]->splitter());
EXPECT_FALSE(info_list[2]->splitter());
EXPECT_FALSE(info_list[3]->splitter());
EXPECT_TRUE(info_list[4]->splitter());
}
}

Expand All @@ -191,10 +218,10 @@ TEST(exception, exception_custom_error_info)
} catch (const jubatus_exception& e) {
error_info_list_t info_list = e.error_info();
EXPECT_EQ(4, info_list.size());
EXPECT_EQ(false, info_list[0]->splitter());
EXPECT_EQ(false, info_list[1]->splitter());
EXPECT_EQ(false, info_list[2]->splitter());
EXPECT_EQ(true, info_list[3]->splitter());
EXPECT_FALSE(info_list[0]->splitter());
EXPECT_FALSE(info_list[1]->splitter());
EXPECT_FALSE(info_list[2]->splitter());
EXPECT_TRUE(info_list[3]->splitter());
}
}

Expand All @@ -217,16 +244,16 @@ TEST(exception, exception_info_add_macro)
caught = true;
error_info_list_t info_list = e.error_info();
EXPECT_EQ(9, info_list.size());
EXPECT_EQ(false, info_list[0]->splitter());
EXPECT_EQ(false, info_list[1]->splitter());
EXPECT_EQ(false, info_list[2]->splitter());
EXPECT_EQ(true, info_list[3]->splitter());
EXPECT_EQ(false, info_list[4]->splitter());
EXPECT_FALSE(info_list[0]->splitter());
EXPECT_FALSE(info_list[1]->splitter());
EXPECT_FALSE(info_list[2]->splitter());
EXPECT_TRUE(info_list[3]->splitter());
EXPECT_FALSE(info_list[4]->splitter());
EXPECT_EQ(string("added"), info_list[4]->as_string());
EXPECT_EQ(false, info_list[5]->splitter());
EXPECT_EQ(false, info_list[6]->splitter());
EXPECT_EQ(false, info_list[7]->splitter());
EXPECT_EQ(true, info_list[8]->splitter());
EXPECT_FALSE(info_list[5]->splitter());
EXPECT_FALSE(info_list[6]->splitter());
EXPECT_FALSE(info_list[7]->splitter());
EXPECT_TRUE(info_list[8]->splitter());
}

EXPECT_TRUE(caught);
Expand Down Expand Up @@ -288,4 +315,3 @@ TEST(exception, exception_class_name)
}
#endif


Loading

0 comments on commit 9b24016

Please sign in to comment.