Ejemplo n.º 1
0
        public void CommitOutgoingMessageRealTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            MessagingWorkers.Start(new TestBatchParameters(), environmentFactory.MessagingEnvironment.MessagingServiceClient);

            var pltDeviceOperations = environmentFactory.ManagementEnvironment.ObjDeviceOperations;

            var messagingService = new MessagingService(new MessagingOperations(), pltDeviceOperations);

            messagingService.RecordOutgoingMessage(_deviceId, _deviceId, "32412341243");

            var msg = messagingService.Peek(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, msg.State);
            Assert.AreEqual(_deviceId, msg.Message.DeviceId);
            Assert.AreEqual("32412341243", msg.Message.Payload);
            Assert.AreEqual(_deviceId, msg.Message.SenderDeviceId);

            var state = messagingService.Commit(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, state);

            var state2 = messagingService.Commit(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, state2);

            MessagingWorkers.Stop();
        }
Ejemplo n.º 2
0
        private void StopBackgroundProcesses()
        {
            MessagingWorkers.Stop();

            _persistentConnectionReceiveAndForgetWorker.Stop();
            _persistentConnectionPeekWorker.Stop();
            _connectionRegistry.Stop();
        }
Ejemplo n.º 3
0
        public void RecordOutgoingMessageRealTest()
        {
            var environmentFactory  = EnvironmentFactoryFactory.Create();
            var pltDeviceOperations = environmentFactory.ManagementEnvironment.ObjDeviceOperations;

            MessagingWorkers.Start(new TestBatchParameters(), environmentFactory.MessagingEnvironment.MessagingServiceClient);

            var messagingService = new MessagingService(new MessagingOperations(), pltDeviceOperations);

            var success = messagingService.RecordOutgoingMessage(_deviceId, _deviceId, "32412341243");

            Assert.AreEqual(OutgoingState.Ok, success);

            MessagingWorkers.Stop();
        }
        public void RecordOutgoingAndPeekMessageRealTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            MessagingWorkers.Start(new TestBatchParameters(), environmentFactory.MessagingEnvironment.MessagingServiceClient);

            var pltDeviceOperations = environmentFactory.ManagementEnvironment.ObjDeviceOperations;
            var messagingOperations = new MessagingOperations();

            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            var batchParameters = Substitute.For <IBatchParameters>();

            batchParameters.PersistentConnectionMessagePeekCollectionTime.Returns(
                TimeSpan.FromMilliseconds(100));
            batchParameters.PersistentConnectionMessagePeekCollectionBatch.Returns(100);

            var pusherRegistry = new PusherRegistry(dateTimeProvider);

            var persistentConnectionWorker = new PersistentConnectionPeekWorker(pusherRegistry, messagingOperations, batchParameters);

            persistentConnectionWorker.Start();

            var messagingService = new MessagingService(messagingOperations, pltDeviceOperations);

            var success = messagingService.RecordOutgoingMessage(_deviceId, _deviceId, "32412341243");

            Assert.AreEqual(OutgoingState.Ok, success);


            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var connection = Substitute.For <IPersistentConnection>();

            connectionRegistry.RegisterInitiatedConnection(connection);
            connection.LastHeartbeat.Returns(DateTime.UtcNow);

            var device = _deviceService.Get(_deviceId);

            connectionRegistry.PromoteToLoggedInConnection(connection, _deviceId, device.NumericId);
            connectionRegistry.PromoteToSubscribedConnection(_deviceId, SubscriptionType.PeekAndCommit);
            connection.NextPeekTime = DateTime.UtcNow.AddSeconds(-0.1);
            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            bool ok = false;

            for (int i = 0; i < 20; i++)
            {
                try
                {
                    connection.ReceivedWithAnyArgs().SendMessage(null);
                    ok = true;
                }
                catch (ReceivedCallsException)
                {
                    Thread.Sleep(100);
                }
            }

            Assert.IsTrue(ok);

            persistentConnectionWorker.Stop();
            MessagingWorkers.Stop();
        }