Пример #1
0
        public void TestNotifications(List <GcmNotification> notifications,
                                      List <GcmMessageResponseFilter> responseFilters,
                                      Action <object, INotification> sentCallback,
                                      Action <object, INotification, Exception> failedCallback,
                                      Action <object, string, string, INotification> subscriptionChangedCallback,
                                      Action <object, string, DateTime, INotification> subscriptionExpiredCallback)
        {
            testPort++;

            int pushFailCount    = 0;
            int pushSuccessCount = 0;

            int serverReceivedCount        = 0;
            int serverReceivedFailCount    = 0;
            int serverReceivedSuccessCount = 0;


            var server = new TestServers.GcmTestServer();

            server.MessageResponseFilters.AddRange(responseFilters);

            server.Start(testPort, response => {
                serverReceivedCount        += (int)response.NumberOfCanonicalIds;
                serverReceivedSuccessCount += (int)response.NumberOfSuccesses;
                serverReceivedFailCount    += (int)response.NumberOfFailures;
            });



            var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");

            settings.OverrideUrl("http://localhost:" + (testPort) + "/");

            var push = new GcmPushService(settings);

            push.OnNotificationSent += (sender, notification1) => {
                pushSuccessCount++;
                sentCallback(sender, notification1);
            };
            push.OnNotificationFailed += (sender, notification1, error) => {
                pushFailCount++;
                failedCallback(sender, notification1, error);
            };
            push.OnDeviceSubscriptionChanged += (sender, oldSubscriptionId, newSubscriptionId, notification) => subscriptionChangedCallback(sender, oldSubscriptionId, newSubscriptionId, notification);
            push.OnDeviceSubscriptionExpired += (sender, expiredSubscriptionId, expirationDateUtc, notification) => subscriptionExpiredCallback(sender, expiredSubscriptionId, expirationDateUtc, notification);


            foreach (var n in notifications)
            {
                push.QueueNotification(n);
            }

            push.Stop();
            push.Dispose();

            server.Dispose();
            //waitServerFinished.WaitOne();

            Console.WriteLine("TEST-> DISPOSE.");
        }
Пример #2
0
 void ConfigureAndriod(NotiConfig config)
 {
     this.HasAndriod = config.HasAndroid;
     if (this.HasAndriod)
     {
         var setting = new GcmPushChannelSettings(config.GcmSenderId, config.GcmAuthToken, config.GcmPackageName);
         pushBroker.RegisterGcmService(setting);
     }
 }
Пример #3
0
 private void EnsureAndroid()
 {
     if (!m_started_android)
     {
         GcmPushChannelSettings settings = new GcmPushChannelSettings(m_config.androidSenderId, m_config.androidSenderAPIKey, m_appId);
         Service.StartGooglePushService(settings, serviceSettings);
         m_started_android = true;
     }
 }
Пример #4
0
        public void TestNotifications(bool shouldBatch, int toQueue, int expectSuccessful, int expectFailed, int[] indexesToFail = null, bool waitForScaling = false)
        {
            testPort++;

            int msgIdOn = 1000;

            int pushFailCount    = 0;
            int pushSuccessCount = 0;

            int serverReceivedCount        = 0;
            int serverReceivedFailCount    = 0;
            int serverReceivedSuccessCount = 0;

            //var notification = new GcmNotification();

            var server = new TestServers.GcmTestServer();

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
            {
                IsMatch = (request, s) => {
                    return(s.Equals("FAIL", StringComparison.InvariantCultureIgnoreCase));
                },
                Status = new GcmMessageResult()
                {
                    ResponseStatus = GcmMessageTransportResponseStatus.InvalidRegistration,
                    MessageId      = "1:" + msgIdOn++
                }
            });

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
            {
                IsMatch = (request, s) => {
                    return(s.Equals("NOTREGISTERED", StringComparison.InvariantCultureIgnoreCase));
                },
                Status = new GcmMessageResult()
                {
                    ResponseStatus = GcmMessageTransportResponseStatus.NotRegistered,
                    MessageId      = "1:" + msgIdOn++
                }
            });
            //var waitServerFinished = new ManualResetEvent(false);

            server.Start(testPort, response =>
            {
                serverReceivedCount        += (int)response.NumberOfCanonicalIds;
                serverReceivedSuccessCount += (int)response.NumberOfSuccesses;
                serverReceivedFailCount    += (int)response.NumberOfFailures;
            });



            var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");

            settings.OverrideUrl("http://*****:*****@"{""key"":""value1""}";

            if (shouldBatch)
            {
                var regIds = new List <string>();

                for (int i = 0; i < toQueue; i++)
                {
                    regIds.Add((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS");
                }

                var n = new GcmNotification();
                n.RegistrationIds.AddRange(regIds);
                n.WithJson(json);

                push.QueueNotification(n);
            }
            else
            {
                for (int i = 0; i < toQueue; i++)
                {
                    push.QueueNotification(new GcmNotification()
                                           .ForDeviceRegistrationId((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS")
                                           .WithJson(json));
                }
            }



            Console.WriteLine("Avg Queue Wait Time: " + push.AverageQueueWaitTime + " ms");
            Console.WriteLine("Avg Send Time: " + push.AverageSendTime + " ms");

            if (waitForScaling)
            {
                while (push.QueueLength > 0)
                {
                    Thread.Sleep(500);
                }

                Console.WriteLine("Sleeping 3 minutes for autoscaling...");
                Thread.Sleep(TimeSpan.FromMinutes(3));

                Console.WriteLine("Channel Count: " + push.ChannelCount);
                Assert.IsTrue(push.ChannelCount <= 1);
            }

            push.Stop();
            push.Dispose();

            server.Dispose();
            //waitServerFinished.WaitOne();

            Console.WriteLine("TEST-> DISPOSE.");

            Assert.AreEqual(toQueue, serverReceivedCount, "Server - Received Count");
            Assert.AreEqual(expectFailed, serverReceivedFailCount, "Server - Failed Count");
            Assert.AreEqual(expectSuccessful, serverReceivedSuccessCount, "Server - Success Count");

            Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
            Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
        }
Пример #5
0
        public void TestNotifications(bool shouldBatch, int toQueue, int expectSuccessful, int expectFailed, int[] indexesToFail = null)
        {
            testPort++;

            int msgIdOn = 1000;

            int pushFailCount    = 0;
            int pushSuccessCount = 0;

            int serverReceivedCount        = 0;
            int serverReceivedFailCount    = 0;
            int serverReceivedSuccessCount = 0;

            //var notification = new GcmNotification();

            var server = new TestServers.GcmTestServer();

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
            {
                IsMatch = (request, s) => {
                    return(s.Equals("FAIL", StringComparison.InvariantCultureIgnoreCase));
                },
                Status = new GcmMessageResult()
                {
                    ResponseStatus = GcmMessageTransportResponseStatus.InvalidRegistration,
                    MessageId      = "1:" + msgIdOn++
                }
            });

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
            {
                IsMatch = (request, s) => {
                    return(s.Equals("NOTREGISTERED", StringComparison.InvariantCultureIgnoreCase));
                },
                Status = new GcmMessageResult()
                {
                    ResponseStatus = GcmMessageTransportResponseStatus.NotRegistered,
                    MessageId      = "1:" + msgIdOn++
                }
            });
            //var waitServerFinished = new ManualResetEvent(false);

            server.Start(testPort, response =>
            {
                serverReceivedCount        += (int)response.NumberOfCanonicalIds;
                serverReceivedSuccessCount += (int)response.NumberOfSuccesses;
                serverReceivedFailCount    += (int)response.NumberOfFailures;
            });



            var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");

            settings.OverrideUrl("http://*****:*****@"{""key"":""value1""}";

            if (shouldBatch)
            {
                var regIds = new List <string>();

                for (int i = 0; i < toQueue; i++)
                {
                    regIds.Add((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS");
                }

                var n = new GcmNotification();
                n.RegistrationIds.AddRange(regIds);
                n.WithJson(json);

                push.QueueNotification(n);
            }
            else
            {
                for (int i = 0; i < toQueue; i++)
                {
                    push.QueueNotification(new GcmNotification()
                                           .ForDeviceRegistrationId((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS")
                                           .WithJson(json));
                }
            }

            push.Stop();
            push.Dispose();

            server.Dispose();
            //waitServerFinished.WaitOne();

            Console.WriteLine("TEST-> DISPOSE.");

            Assert.AreEqual(toQueue, serverReceivedCount, "Server - Received Count");
            Assert.AreEqual(expectFailed, serverReceivedFailCount, "Server - Failed Count");
            Assert.AreEqual(expectSuccessful, serverReceivedSuccessCount, "Server - Success Count");

            Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
            Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
        }
Пример #6
0
 public static void RegisterGcmService(this PushBroker broker, GcmPushChannelSettings channelSettings, string applicationId, IPushServiceSettings serviceSettings = null)
 {
     broker.RegisterService <GcmNotification>(new GcmPushService(new GcmPushChannelFactory(), channelSettings, serviceSettings), applicationId);
 }
Пример #7
0
 public static void RegisterGcmService(this PushBroker broker, GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings = null)
 {
     RegisterGcmService(broker, channelSettings, null, serviceSettings);
 }