Skip to content

Commit

Permalink
Added support for onSuccess publisher events
Browse files Browse the repository at this point in the history
The unit test results for onSuccess publisher events are set to expect no calls as no bridge calls the onSuccess callback at the moment. Existing unit tests for onError publisher events were already disabled or modified for similar reasons. Unit test expectations for both these publisher events will have to be modified if/when the bridge used for executing the unit tests does issue these callbacks.
  • Loading branch information
cmjthomas authored and fquinner committed Mar 22, 2017
1 parent 15d0e1f commit 9017966
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 14 deletions.
7 changes: 7 additions & 0 deletions mama/c_cpp/src/c/mama/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ typedef void (MAMACALLTYPE *mama_publisherOnErrorCb) (
const char* info,
void* closure);

typedef void (MAMACALLTYPE *mama_publisherOnSuccessCb) (
mamaPublisher publisher,
mama_status status,
const char* info,
void* closure);

/**
* Callbacks for publisher events.
* If any cb is NULL then the callback will not be made.
Expand All @@ -106,6 +112,7 @@ typedef struct mamaPublisherCallbacks
mama_publisherOnCreateCb onCreate;
mama_publisherOnErrorCb onError;
mama_publisherOnDestroyCb onDestroy;
mama_publisherOnSuccessCb onSuccess;
} mamaPublisherCallbacks;


Expand Down
3 changes: 3 additions & 0 deletions mama/c_cpp/src/c/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ _createByIndex (mamaPublisher* result,
{
impl->mUserCallbacks.onCreate = publisherCallbacks->onCreate;
impl->mUserCallbacks.onError = publisherCallbacks->onError;
impl->mUserCallbacks.onSuccess = publisherCallbacks->onSuccess;
impl->mUserCallbacks.onDestroy = publisherCallbacks->onDestroy;
}
impl->mQueue = queue;
Expand Down Expand Up @@ -193,6 +194,7 @@ _createByIndex (mamaPublisher* result,
mamaPublisherCallbacks_allocate(&cb);
cb->onCreate = publisherCallbacks ? impl->mUserCallbacks.onCreate : NULL;
cb->onError = publisherCallbacks ? impl->mUserCallbacks.onError : NULL;
cb->onSuccess = publisherCallbacks ? impl->mUserCallbacks.onSuccess : NULL;
cb->onDestroy = mamaPublisher_onPublisherDestroyed; /* intercept onDestroy always to track state */

if (NULL != bridgeImpl->bridgeMamaPublisherSetUserCallbacks)
Expand Down Expand Up @@ -751,6 +753,7 @@ mamaPublisher_getUserCallbacks (mamaPublisher publisher,

cb->onCreate = impl->mUserCallbacks.onCreate;
cb->onError = impl->mUserCallbacks.onError;
cb->onSuccess = impl->mUserCallbacks.onSuccess;
cb->onDestroy = impl->mUserCallbacks.onDestroy;

return MAMA_STATUS_OK;
Expand Down
22 changes: 18 additions & 4 deletions mama/c_cpp/src/cpp/MamaPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ namespace Wombat
{
onPublisherCreate,
onPublisherError,
onPublisherDestroy
onPublisherDestroy,
onPublisherSuccess
};

mamaTry (mamaPublisher_createWithCallbacks (&mPublisher,
Expand Down Expand Up @@ -480,9 +481,9 @@ namespace Wombat
}

void MAMACALLTYPE MamaPublisherImpl::onPublisherError (mamaPublisher publisher,
mama_status status,
const char* info,
void* closure)
mama_status status,
const char* info,
void* closure)
{
MamaPublisherImpl* i = (MamaPublisherImpl*) closure;
if (NULL != i && NULL != i->mCallback)
Expand All @@ -492,5 +493,18 @@ namespace Wombat
}
}

void MAMACALLTYPE MamaPublisherImpl::onPublisherSuccess (mamaPublisher publisher,
mama_status status,
const char* info,
void* closure)
{
MamaPublisherImpl* i = (MamaPublisherImpl*)closure;
if (NULL != i && NULL != i->mCallback)
{
MamaStatus cppstatus(status);
i->mCallback->onSuccess(i->mParent, cppstatus, info, i->mClosure);
}
}

} // namespace Wombat

11 changes: 8 additions & 3 deletions mama/c_cpp/src/cpp/MamaPublisherImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ namespace Wombat
void* closure);

static void MAMACALLTYPE onPublisherError (mamaPublisher publisher,
mama_status status,
const char* info,
void* closure);
mama_status status,
const char* info,
void* closure);

static void MAMACALLTYPE onPublisherSuccess (mamaPublisher publisher,
mama_status status,
const char* info,
void* closure);

mamaPublisher mPublisher;
MamaPublisherCallback* mCallback;
Expand Down
6 changes: 6 additions & 0 deletions mama/c_cpp/src/cpp/mama/MamaPublisherCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ namespace Wombat
const MamaStatus& status,
const char* info,
void* closure) = 0;

virtual void onSuccess(
MamaPublisher* publisher,
const MamaStatus& status,
const char* info,
void* closure) = 0;
};

} // namespace Wombat
Expand Down
16 changes: 16 additions & 0 deletions mama/c_cpp/src/examples/c/mamapublisherc.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ static void MAMACALLTYPE publisherOnErrorCb (
}
}

static void MAMACALLTYPE publisherOnSuccessCb (
mamaPublisher publisher,
mama_status status,
const char* info,
void* closure)
{
if (gQuietLevel < 1)
{
const char* symbol = "";
mamaPublisher_getSymbol(publisher, &symbol);
mama_log(MAMA_LOG_LEVEL_FINEST, "publisherOnSuccessCb: %s status=%d/%s info=%s",
symbol, status, mamaStatus_stringForStatus(status), info);
}
}

static void createPublisher (void)
{
mama_status status;
Expand All @@ -233,6 +248,7 @@ static void createPublisher (void)
mamaPublisherCallbacks_allocate (&cb);
cb->onCreate = publisherOnCreateCb;
cb->onError = publisherOnErrorCb;
cb->onSuccess = publisherOnSuccessCb;
cb->onDestroy = publisherOnDestroyCb;
status = mamaPublisher_createWithCallbacks (&gPublisher,
gTransport,
Expand Down
16 changes: 16 additions & 0 deletions mama/c_cpp/src/examples/cpp/mamapublishercpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class MamaPublisherSample : public MamaBasicSubscriptionCallback
const char* info,
void* closure);

void onSuccess (
MamaPublisher* publisher,
const MamaStatus& status,
const char* info,
void* closure);

private:
int msgNumber;

Expand Down Expand Up @@ -339,6 +345,16 @@ void MamaPublisherSample::onError (
publisher->getSource(), publisher->getSymbol(), status.toString(), info);
}

void MamaPublisherSample::onSuccess(
MamaPublisher* publisher,
const MamaStatus& status,
const char* info,
void* closure)
{
mama_log(MAMA_LOG_LEVEL_FINEST, "onPublishSuccess: %s.%s %s %s",
publisher->getSource(), publisher->getSymbol(), status.toString(), info);
}

void parseCommandLine (int argc, const char **argv)
{
int i = 0;
Expand Down
26 changes: 26 additions & 0 deletions mama/c_cpp/src/gunittest/c/publishertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void MamaPublisherTestC::TearDown(void)
*/
int pubOnCreateCount = 0;
int pubOnErrorCount = 0;
int pubOnSuccessCount = 0;
int pubOnDestroyCount = 0;

/**
Expand All @@ -103,6 +104,15 @@ void pubOnError (mamaPublisher publisher,
pubOnErrorCount++;
}


void pubOnSuccess (mamaPublisher publisher,
mama_status status,
const char* info,
void* closure)
{
++pubOnSuccessCount;
}

/**
* Publisher event callbacks via transport topic callbacks
*/
Expand Down Expand Up @@ -136,6 +146,7 @@ TEST_F (MamaPublisherTestC, CreateDestroy)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

ASSERT_EQ (MAMA_STATUS_OK,
Expand Down Expand Up @@ -186,6 +197,7 @@ TEST_F (MamaPublisherTestC, GetTransportImpl)

ASSERT_EQ (0, pubOnCreateCount);
ASSERT_EQ (0, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount);
ASSERT_EQ (0, pubOnDestroyCount);
}

Expand All @@ -204,6 +216,7 @@ TEST_F (MamaPublisherTestC, Send)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

ASSERT_EQ (MAMA_STATUS_OK, mama_open());
Expand Down Expand Up @@ -238,6 +251,7 @@ TEST_F (MamaPublisherTestC, Send)

ASSERT_EQ (0, pubOnCreateCount);
ASSERT_EQ (0, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount);
ASSERT_EQ (0, pubOnDestroyCount);
}

Expand All @@ -260,10 +274,12 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacks)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

mamaPublisherCallbacks_allocate(&cb);
cb->onError = (mama_publisherOnErrorCb) pubOnError;
cb->onSuccess = (mama_publisherOnSuccessCb) pubOnSuccess;
cb->onCreate = (mama_publisherOnCreateCb) pubOnCreate;
cb->onDestroy = (mama_publisherOnDestroyCb) pubOnDestroy;

Expand Down Expand Up @@ -308,6 +324,7 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacks)

ASSERT_EQ (1, pubOnCreateCount);
ASSERT_EQ (0, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount); // this should be numPublishers but no bridge calls onSuccess yet
ASSERT_EQ (1, pubOnDestroyCount);

mamaPublisherCallbacks_deallocate(cb);
Expand All @@ -333,10 +350,12 @@ TEST_F (MamaPublisherTestC, DISABLED_EventSendWithCallbacksBadSource)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

mamaPublisherCallbacks_allocate(&cb);
cb->onError = (mama_publisherOnErrorCb) pubOnError;
cb->onSuccess = (mama_publisherOnSuccessCb) pubOnSuccess;
cb->onCreate = (mama_publisherOnCreateCb) pubOnCreate;
cb->onDestroy = (mama_publisherOnDestroyCb) pubOnDestroy;

Expand Down Expand Up @@ -379,6 +398,7 @@ TEST_F (MamaPublisherTestC, DISABLED_EventSendWithCallbacksBadSource)

ASSERT_EQ (1, pubOnCreateCount);
ASSERT_EQ (numErrors, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount);
ASSERT_EQ (1, pubOnDestroyCount);

mamaPublisherCallbacks_deallocate(cb);
Expand All @@ -405,12 +425,14 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacksNoErrorCallback)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

mamaPublisherCallbacks_allocate(&cb);
cb->onError = NULL;
cb->onCreate = (mama_publisherOnCreateCb) pubOnCreate; /* No error callback */
cb->onDestroy = (mama_publisherOnDestroyCb) pubOnDestroy;
cb->onSuccess = (mama_publisherOnSuccessCb) pubOnSuccess;

ASSERT_EQ (MAMA_STATUS_OK, mama_open());

Expand Down Expand Up @@ -453,6 +475,7 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacksNoErrorCallback)

ASSERT_EQ (1, pubOnCreateCount);
ASSERT_EQ (0, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount);
ASSERT_EQ (1, pubOnDestroyCount);

mamaPublisherCallbacks_deallocate(cb);
Expand All @@ -479,10 +502,12 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacksNoCallbacks)

pubOnCreateCount = 0;
pubOnErrorCount = 0;
pubOnSuccessCount = 0;
pubOnDestroyCount = 0;

mamaPublisherCallbacks_allocate(&cb);
cb->onError = NULL;
cb->onSuccess = NULL;
cb->onCreate = NULL;
cb->onDestroy = NULL;

Expand Down Expand Up @@ -527,6 +552,7 @@ TEST_F (MamaPublisherTestC, EventSendWithCallbacksNoCallbacks)

ASSERT_EQ (0, pubOnCreateCount);
ASSERT_EQ (0, pubOnErrorCount);
ASSERT_EQ (0, pubOnSuccessCount);
ASSERT_EQ (0, pubOnDestroyCount);

mamaPublisherCallbacks_deallocate(cb);
Expand Down
14 changes: 14 additions & 0 deletions mama/c_cpp/src/gunittest/cpp/MamaPublisherTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,21 @@ class TestCallback : public MamaPublisherCallback
private:
int onCreateCount;
int onErrorCount;
int onSuccessCount;
int onDestroyCount;

public:

int getOnCreateCount() { return onCreateCount; }
int getOnErrorCount() { return onErrorCount; }
int getOnSuccessCount() { return onSuccessCount; }
int getOnDestroyCount() { return onDestroyCount; }

TestCallback()
{
onCreateCount = 0;
onErrorCount = 0;
onSuccessCount = 0;
onDestroyCount = 0;
}

Expand All @@ -105,6 +108,15 @@ class TestCallback : public MamaPublisherCallback
onErrorCount++;
}

virtual void onSuccess (
MamaPublisher* publisher,
const MamaStatus& status,
const char* info,
void* closure)
{
++onSuccessCount;
}

virtual void onDestroy (
MamaPublisher* publisher,
void* closure)
Expand Down Expand Up @@ -205,6 +217,7 @@ TEST_F(MamaPublisherTest, PublishWithCallbacks)

ASSERT_EQ(1, testCallback->getOnCreateCount());
ASSERT_EQ(0, testCallback->getOnErrorCount());
ASSERT_EQ(0, testCallback->getOnSuccessCount()); // this should be 1 but no bridge calls onSuccess yet

delete testCallback;
}
Expand Down Expand Up @@ -262,6 +275,7 @@ TEST_F(MamaPublisherTest, DISABLED_PublishWithCallbacksBadSource)

ASSERT_EQ(1, testCallback->getOnCreateCount());
ASSERT_EQ(numPublishes, testCallback->getOnErrorCount());
ASSERT_EQ(0, testCallback->getOnSuccessCount());
}

/**
Expand Down
Loading

1 comment on commit 9017966

@fquinner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pull request can "be" the issue so all information required is here though its fairly self explanatory. The feature is an extension of publisher events to include an onSuccess callback. It is purely optional for the bridge to implement (qpid for example doesn't use it).

Please sign in to comment.