예제 #1
0
        public void TestNotifications(int toQueue, int expectSuccessful, int expectFailed, int[] idsToFail = null, bool waitForScaling = false, bool autoScale = false)
        {
            var testServer = new ApnsNodeTestServer("http://localhost:8888/");

            testServer.Reset();
            testServer.Setup(idsToFail ?? new int[] {});

            var started = DateTime.UtcNow;

            int pushFailCount    = 0;
            int pushSuccessCount = 0;

            AppleNotification.ResetIdentifier();

            var settings = new ApplePushChannelSettings(false, appleCert, "pushsharp", true);

            settings.OverrideServer("localhost", 2195);
            settings.SkipSsl = true;
            settings.MillisecondsToWaitBeforeMessageDeclaredSuccess = 5000;

            var serviceSettings = new PushServiceSettings();

            if (!autoScale)
            {
                serviceSettings.AutoScaleChannels = false;
                serviceSettings.Channels          = 1;
            }

            var push = new ApplePushService(settings, serviceSettings);

            push.OnNotificationFailed += (sender, notification1, error) => {
                Console.WriteLine("NOTIFICATION FAILED: " + ((AppleNotification)notification1).Identifier);
                pushFailCount++;
            };
            push.OnNotificationSent += (sender, notification1) => {
                pushSuccessCount++;
            };
            push.OnNotificationRequeue += (sender, e) => {
                Console.WriteLine("REQUEUE: " + ((AppleNotification)e.Notification).Identifier);
            };

            for (int i = 0; i < toQueue; i++)
            {
                var n = new AppleNotification("aff441e214b2b2283df799f0b8b16c17a59b7ac077e2867ea54ebf6086e55866").WithAlert("Test");

                push.QueueNotification(n);
            }

            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();

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

            var span = DateTime.UtcNow - started;

            var info = testServer.GetInfo();

            Console.WriteLine("Test Time: " + span.TotalMilliseconds + " ms");
            Console.WriteLine("Client Failed: {0} Succeeded: {1} Sent: {2}", pushFailCount, pushSuccessCount, toQueue);
            Console.WriteLine("Server Failed: {0} Succeeded: {1} Received: {2} Discarded: {3}", info.FailedIds.Length, info.SuccessIds.Length, info.Received, info.Discarded);

            //Assert.AreEqual(toQueue, info.Received, "Server - Received Count");
            Assert.AreEqual(expectFailed, info.FailedIds.Length, "Server - Failed Count");
            Assert.AreEqual(expectSuccessful, info.SuccessIds.Length, "Server - Success Count");

            Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
            Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
        }
예제 #2
0
		public void TestNotifications(int toQueue, int expectSuccessful, int expectFailed, int[] idsToFail = null, bool waitForScaling = false, bool autoScale = false)
		{
			var testServer = new ApnsNodeTestServer ("http://localhost:8888/");
			testServer.Reset ();
			testServer.Setup (idsToFail ?? new int[] {});

			var started = DateTime.UtcNow;

			int pushFailCount = 0;
			int pushSuccessCount = 0;

			AppleNotification.ResetIdentifier ();

			var settings = new ApplePushChannelSettings(false, appleCert, "pushsharp", true);
			settings.OverrideServer("localhost", 2195);
			settings.SkipSsl = true;
			settings.MillisecondsToWaitBeforeMessageDeclaredSuccess = 5000;

			var serviceSettings = new PushServiceSettings();

			if (!autoScale)
			{
				serviceSettings.AutoScaleChannels = false;
				serviceSettings.Channels = 1;
			}

			var push = new ApplePushService(settings, serviceSettings);
			push.OnNotificationFailed += (sender, notification1, error) => {
				Console.WriteLine("NOTIFICATION FAILED: " + ((AppleNotification)notification1).Identifier);
				pushFailCount++;
			};
			push.OnNotificationSent += (sender, notification1) => {
				pushSuccessCount++;
			};
			push.OnNotificationRequeue += (sender, e) => {
				Console.WriteLine("REQUEUE: " + ((AppleNotification)e.Notification).Identifier);
			};

			for (int i = 0; i < toQueue; i++)
			{
				var n = new AppleNotification("aff441e214b2b2283df799f0b8b16c17a59b7ac077e2867ea54ebf6086e55866").WithAlert("Test");

				push.QueueNotification(n);
			}

			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();

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

			var span = DateTime.UtcNow - started;

			var info = testServer.GetInfo ();

			Console.WriteLine ("Test Time: " + span.TotalMilliseconds + " ms");
			Console.WriteLine ("Client Failed: {0} Succeeded: {1} Sent: {2}", pushFailCount, pushSuccessCount, toQueue);
			Console.WriteLine ("Server Failed: {0} Succeeded: {1} Received: {2} Discarded: {3}", info.FailedIds.Length, info.SuccessIds.Length, info.Received, info.Discarded);

			//Assert.AreEqual(toQueue, info.Received, "Server - Received Count");
			Assert.AreEqual(expectFailed, info.FailedIds.Length, "Server - Failed Count");
			Assert.AreEqual(expectSuccessful, info.SuccessIds.Length, "Server - Success Count");

			Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
			Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
		}