Permalink
Browse files

multi-channel subscribe/unsubscribe

  • Loading branch information...
1 parent eebb20c commit d7f1473bca555dbf174d75eee7d2850c2301c1c4 @budgetpreneur budgetpreneur committed Feb 1, 2013
@@ -28,20 +28,22 @@ public bool EnableStubTest
{
Dictionary<string, string> data = new Dictionary<string, string>();
#if ((!__MonoCS__) && (!SILVERLIGHT) && (!WINDOWS_PHONE))
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/0", "[[],\"13559007117760880\"]");
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 1}],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/0", "[[],\"13559006802662768\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/13559006802662768", "[[\"demo test for stubs\"],\"13559014566792816\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/13559014566792816", "[[],\"13559014566792816\"]");
- data.Add("/v2/presence/sub_key/demo/channel/my%2Fchannel/leave", "{\"action\": \"leave\"}");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13596603179264912", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13596603179264912", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 1}],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13559006802662768", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559006802662768", "[[{\"action\": \"leave\", \"timestamp\": 1359660369, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 0}],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
+ data.Add("/v2/presence/sub_key/demo/channel/my%252Fchannel/leave", "{\"action\": \"leave\"}");
#else
- data.Add("/subscribe/demo/my/channel-pnpres/0/0", "[[],\"13559007117760880\"]");
- data.Add("/subscribe/demo/my/channel-pnpres/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 1}],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my/channel-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my/channel/0/0", "[[],\"13559006802662768\"]");
- data.Add("/subscribe/demo/my/channel/0/13559006802662768", "[[\"demo test for stubs\"],\"13559014566792816\"]");
- data.Add("/subscribe/demo/my/channel/0/13559014566792816", "[[],\"13559014566792816\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/13596603179264912", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13596603179264912", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 1}],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13559006802662768", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/13559006802662768", "[[{\"action\": \"leave\", \"timestamp\": 1359660369, \"uuid\": \"eb4c1645-1319-4425-865f-008563009d67\", \"occupancy\": 0}],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
data.Add("/v2/presence/sub_key/demo/channel/my%252Fchannel/leave", "{\"action\": \"leave\"}");
#endif
return data;
@@ -51,20 +53,24 @@ public bool EnableStubTest
{
Dictionary<string, string> data = new Dictionary<string, string>();
#if ((!__MonoCS__) && (!SILVERLIGHT) && (!WINDOWS_PHONE))
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/0", "[[],\"13559007117760880\"]");
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 1}],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/0", "[[],\"13559006802662768\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/13559006802662768", "[[\"demo test for stubs\"],\"13559014566792816\"]");
- data.Add("/subscribe/demo/my%2Fchannel/0/13559014566792816", "[[],\"13559014566792816\"]");
- data.Add("/v2/presence/sub_key/demo/channel/my%2Fchannel/leave", "{\"action\": \"leave\"}");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13596603179264912", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13596603179264912", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 1}],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13559006802662768", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13559006802662768", "[[{\"action\": \"leave\", \"timestamp\": 1359660369, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 0}],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my%2Fchannel,my%2Fchannel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my%2Fchannel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
+ data.Add("/v2/presence/sub_key/demo/channel/my%252Fchannel/leave", "{\"action\": \"leave\"}");
#else
- data.Add("/subscribe/demo/my/channel-pnpres/0/0", "[[],\"13559007117760880\"]");
- data.Add("/subscribe/demo/my/channel-pnpres/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 1}],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my/channel-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
- data.Add("/subscribe/demo/my/channel/0/0", "[[],\"13559006802662768\"]");
- data.Add("/subscribe/demo/my/channel/0/13559006802662768", "[[\"demo test for stubs\"],\"13559014566792816\"]");
- data.Add("/subscribe/demo/my/channel/0/13559014566792816", "[[],\"13559014566792816\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/13596603179264912", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/0", "[[],\"13596603179264912\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13596603179264912", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 1}],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13559006802662768", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/13559006802662768", "[[{\"action\": \"leave\", \"timestamp\": 1359660369, \"uuid\": \"mylocalmachine.mydomain.com\", \"occupancy\": 0}],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my/channel,my%2Fchannel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
+ data.Add("/subscribe/demo/my/channel-pnpres/0/13596603694444112", "[[],\"13596603694444112\"]");
data.Add("/v2/presence/sub_key/demo/channel/my%252Fchannel/leave", "{\"action\": \"leave\"}");
#endif
return data;
@@ -195,7 +201,7 @@ public bool EnableStubTest
{
Dictionary<string, string> data = new Dictionary<string, string>();
#if ((!__MonoCS__) && (!SILVERLIGHT) && (!WINDOWS_PHONE))
- data.Add("/v2/history/sub-key/demo/channel/my%252Fchannel", "[[\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 0\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 1\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 2\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 3\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 4\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 4\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 6\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 7\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 8\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 9\"],13559326456056557,13559327017296315]");
+ data.Add("/v2/history/sub-key/demo/channel/my%252Fchannel", "[[\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 0\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 1\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 2\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 3\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 4\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 5\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 6\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 7\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 8\",\"DetailedHistoryStartTimeWithReverseTrue 13559326410000000 9\"],13559326456056557,13559327017296315]");
data.Add("/publish/demo/demo/0/my%2Fchannel/0/%22DetailedHistoryStartTimeWithReverseTrue%200%22", "[1,\"Sent\",\"13559014566792817\"]");
data.Add("/publish/demo/demo/0/my%2Fchannel/0/%22DetailedHistoryStartTimeWithReverseTrue%201%22", "[1,\"Sent\",\"13559014566792817\"]");
data.Add("/publish/demo/demo/0/my%2Fchannel/0/%22DetailedHistoryStartTimeWithReverseTrue%202%22", "[1,\"Sent\",\"13559014566792817\"]");
@@ -39,27 +39,29 @@ public void ThenPresenceShouldReturnReceivedMessage()
receivedPresenceMessage = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
-
+
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
- pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage);
-
+ pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback);
+ Thread.Sleep(1000);
+
//since presence expects from stimulus from sub/unsub...
- pubnub.Subscribe<string>(channel, DummyMethodForSubscribe);
+ pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback);
+ Thread.Sleep(1000);
subscribeManualEvent.WaitOne(2000);
- pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe);
+ pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe, UnsubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback);
+ Thread.Sleep(1000);
unsubscribeManualEvent.WaitOne(2000);
presenceManualEvent.WaitOne(310 * 1000);
- pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub);
- presenceUnsubscribeEvent.WaitOne();
+ pubnub.EndPendingRequests();
Assert.IsTrue(receivedPresenceMessage, "Presence message not received");
}
@@ -78,20 +80,22 @@ public void ThenPresenceShouldReturnCustomUUID()
string channel = "my/channel";
- pubnub.Presence<string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage);
-
+ pubnub.Presence<string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage, PresenceUUIDDummyMethodForConnectCallback);
+ Thread.Sleep(1000);
+
//since presence expects from stimulus from sub/unsub...
pubnub.SessionUUID = customUUID;
- pubnub.Subscribe<string>(channel, DummyMethodForSubscribeUUID);
+ pubnub.Subscribe<string>(channel, DummyMethodForSubscribeUUID, SubscribeUUIDDummyMethodForConnectCallback);
+ Thread.Sleep(1000);
subscribeUUIDManualEvent.WaitOne(2000);
- pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribeUUID);
+ pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribeUUID, UnsubscribeUUIDDummyMethodForConnectCallback, UnsubscribeUUIDDummyMethodForDisconnectCallback);
+ Thread.Sleep(1000);
unsubscribeUUIDManualEvent.WaitOne(2000);
presenceUUIDManualEvent.WaitOne(310 * 1000);
- pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSubUUID);
- presenceUnsubscribeUUIDEvent.WaitOne();
+ pubnub.EndPendingRequests();
Assert.IsTrue(receivedCustomUUID, "Custom UUID not received");
}
@@ -179,36 +183,102 @@ void ThenHereNowShouldReturnMessage(string receivedMessage)
void DummyMethodForSubscribe(string receivedMessage)
{
- subscribeManualEvent.Set();
+ try
+ {
+ if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim()))
+ {
+ object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage);
+ JContainer dictionary = serializedMessage[0] as JContainer;
+ if (dictionary != null)
+ {
+ var uuid = dictionary["uuid"].ToString();
+ if (uuid != null)
+ {
+ receivedPresenceMessage = true;
+ }
+ }
+ }
+ }
+ catch { }
+ finally
+ {
+ presenceManualEvent.Set();
+ }
//Dummary callback method for subscribe and unsubscribe to test presence
}
void DummyMethodForSubscribeUUID(string receivedMessage)
{
- subscribeUUIDManualEvent.Set();
+ try
+ {
+ if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim()))
+ {
+ object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage);
+ JContainer dictionary = serializedMessage[0] as JContainer;
+ if (dictionary != null)
+ {
+ var uuid = dictionary["uuid"].ToString();
+ if (uuid != null)
+ {
+ receivedCustomUUID = true;
+ }
+ }
+ }
+ }
+ catch { }
+ finally
+ {
+ presenceUUIDManualEvent.Set();
+ }
//Dummary callback method for subscribe and unsubscribe to test presence
}
void DummyMethodForUnSubscribe(string receivedMessage)
{
- unsubscribeManualEvent.Set();
//Dummary callback method for unsubscribe to test presence
}
void DummyMethodForUnSubscribeUUID(string receivedMessage)
{
- unsubscribeUUIDManualEvent.Set();
//Dummary callback method for unsubscribe to test presence
}
- void DummyMethodForPreUnSub(string receivedMessage)
+ void PresenceDummyMethodForConnectCallback(string receivedMessage)
{
- presenceUnsubscribeEvent.Set();
}
- void DummyMethodForPreUnSubUUID(string receivedMessage)
+ void PresenceUUIDDummyMethodForConnectCallback(string receivedMessage)
{
- presenceUnsubscribeUUIDEvent.Set();
}
+
+ void SubscribeDummyMethodForConnectCallback(string receivedMessage)
+ {
+ subscribeManualEvent.Set();
+ }
+
+ void SubscribeUUIDDummyMethodForConnectCallback(string receivedMessage)
+ {
+ subscribeUUIDManualEvent.Set();
+ }
+
+
+ void UnsubscribeDummyMethodForConnectCallback(string receivedMessage)
+ {
+ }
+
+ void UnsubscribeUUIDDummyMethodForConnectCallback(string receivedMessage)
+ {
+ }
+
+ void UnsubscribeDummyMethodForDisconnectCallback(string receivedMessage)
+ {
+ unsubscribeManualEvent.Set();
+ }
+
+ void UnsubscribeUUIDDummyMethodForDisconnectCallback(string receivedMessage)
+ {
+ unsubscribeUUIDManualEvent.Set();
+ }
+
}
}
@@ -137,6 +137,7 @@ public void DetailedHistoryStartWithReverseTrue()
Thread.Sleep(2000);
pubnub.DetailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, true);
+ Thread.Sleep(2000);
mreMessageStartReverseTrue.WaitOne(310 * 1000);
Assert.IsTrue(messageStartReverseTrue, "Detailed History with Start and Reverse True Failed");
}
Oops, something went wrong.

0 comments on commit d7f1473

Please sign in to comment.