Ejemplo n.º 1
0
 public ReadInput(CoreServicesFixture coreServices, TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _taskObserver = taskObserver;
     _brokerClient = CreateLocalBrokerClient(coreServices, nameof(RSessionTest) + nameof(ReadInput));
     _session      = new RSession(0, testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
     _callback     = new RSessionCallbackStub();
 }
Ejemplo n.º 2
0
        private static async Task StopHostAsync(IBrokerClient brokerClient, RHost host, Task hostRunTask, bool waitForShutdown)
        {
            // Try graceful shutdown with q() first.
            if (waitForShutdown)
            {
                try {
                    host.QuitAsync().SilenceException <Exception>().DoNotWait();
                    await Task.WhenAny(hostRunTask, Task.Delay(10000)).Unwrap();
                } catch (Exception) { }

                if (hostRunTask.IsCompleted)
                {
                    return;
                }
            }

            // If it didn't work, tell the broker to forcibly terminate the host process.
            try {
                brokerClient.TerminateSessionAsync(host.Name).Wait(10000);
            } catch (Exception) { }

            if (hostRunTask.IsCompleted)
            {
                return;
            }

            if (host != null)
            {
                // If nothing worked, then just disconnect.
                await host.DisconnectAsync();
            }

            await hostRunTask;
        }
Ejemplo n.º 3
0
 public RSessionTest(IServiceContainer services, TestMethodFixture testMethod)
 {
     _services     = services;
     _testMethod   = testMethod;
     _brokerClient = CreateLocalBrokerClient(services, nameof(RSessionTest));
     _fileSystem   = _services.FileSystem();
 }
Ejemplo n.º 4
0
 public CancelAll(IServiceContainer services, TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _taskObserver = taskObserver;
     _callback     = new RSessionCallbackStub();
     _brokerClient = CreateLocalBrokerClient(services, nameof(RSessionTest) + nameof(CancelAll));
     _session      = new RSession(0, testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => {});
 }
Ejemplo n.º 5
0
 public Blobs(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _taskObserver = taskObserver;
     _testMethod   = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(Blobs));
     _session      = new RSession(0, _brokerClient, () => { });
 }
Ejemplo n.º 6
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (_Disposed)
            {
                throw new ObjectDisposedException(nameof(BrokerHostedService));
            }

            _senderBlock        = CreateClientBlock();
            _senderTransactions = CreateClientTransaction();

            _subscriptions.Add(_EventAggregator.Subscribe <Events.NewBlockEvent>(async o =>
            {
                var chain = ChainProvider.GetChain(o.CryptoCode);
                if (chain == null)
                {
                    return;
                }
                var block = chain.GetBlock(o.BlockId);
                if (block != null)
                {
                    var nbe = new Models.NewBlockEvent()
                    {
                        CryptoCode        = o.CryptoCode,
                        Hash              = block.Hash,
                        Height            = block.Height,
                        PreviousBlockHash = block?.Previous
                    };
                    await _senderBlock.Send(nbe);
                }
            }));


            _subscriptions.Add(_EventAggregator.Subscribe <Events.NewTransactionMatchEvent>(async o =>
            {
                var network = Waiters.GetWaiter(o.CryptoCode);
                if (network == null)
                {
                    return;
                }
                var chain = ChainProvider.GetChain(o.CryptoCode);
                if (chain == null)
                {
                    return;
                }
                var txe = new Models.NewTransactionEvent()
                {
                    TrackedSource      = o.Match.TrackedSource,
                    DerivationStrategy = o.Match.DerivationStrategy,
                    CryptoCode         = o.CryptoCode,
                    BlockId            = o.BlockId,
                    TransactionData    = Utils.ToTransactionResult(true, chain, new[] { o.SavedTransaction }),
                    Inputs             = o.Match.Inputs,
                    Outputs            = o.Match.Outputs
                };
                await _senderTransactions.Send(txe);
            }));

            Logs.Configuration.LogInformation("Starting Azure Service Bus Message Broker");
            return(Task.CompletedTask);
        }
Ejemplo n.º 7
0
 public CancelAll(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver) {
     _taskObserver = taskObserver;
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(CancelAll));
     _callback = new RSessionCallbackStub();
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => {});
 }
Ejemplo n.º 8
0
 public InteractionEvaluation(IServiceContainer services, TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _taskObserver = taskObserver;
     _testMethod   = testMethod;
     _brokerClient = CreateLocalBrokerClient(services, nameof(RSessionTest) + nameof(InteractionEvaluation));
     _session      = new RSession(0, _testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }
Ejemplo n.º 9
0
 public Blobs(IServiceContainer services, TestMethodFixture testMethod)
 {
     _testMethod   = testMethod;
     _brokerClient = CreateLocalBrokerClient(services, nameof(RSessionTest) + nameof(Blobs));
     _fileSystem   = services.FileSystem();
     _session      = new RSession(0, testMethod.FileSystemSafeName, _fileSystem, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }
Ejemplo n.º 10
0
 public ReadInput(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _taskObserver = taskObserver;
     _testMethod   = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(ReadInput));
     _session      = new RSession(0, _brokerClient, () => { });
     _callback     = new RSessionCallbackStub();
 }
Ejemplo n.º 11
0
 public Blobs(CoreServicesFixture coreServices, TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver)
 {
     _coreServices = coreServices;
     _taskObserver = taskObserver;
     _testMethod   = testMethod;
     _brokerClient = CreateLocalBrokerClient(_coreServices, nameof(RSessionTest) + nameof(Blobs));
     _session      = new RSession(0, testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }
Ejemplo n.º 12
0
        private static async Task TestBrokerConnectionWithRHost(IBrokerClient brokerClient, CancellationToken cancellationToken, ReentrancyToken reentrancyToken)
        {
            var callbacks = new NullRCallbacks();
            var rhost     = await brokerClient.ConnectAsync(nameof(TestBrokerConnectionAsync), callbacks, cancellationToken : cancellationToken, reentrancyToken : reentrancyToken);

            try {
                var rhostRunTask = rhost.Run(cancellationToken);
                callbacks.SetReadConsoleInput("q()\n");
                await rhostRunTask;
            } finally {
                rhost.Dispose();
            }
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="serviceFactory"></param>
 /// <param name="subscriberServiceHelper"></param>
 /// <param name="autoUnsubscribe">Indicates whether the created service subscription should be removed after the service is deleted.</param>
 /// <param name="loggingCallback">Optional logging callback.</param>
 public StatelessSubscriberServiceBootstrapper(StatelessServiceContext context,
                                               Func <StatelessServiceContext, TService> serviceFactory,
                                               IBrokerClient subscriberServiceHelper = null,
                                               bool autoUnsubscribe            = false,
                                               Action <string> loggingCallback = null)
 {
     _context        = context ?? throw new ArgumentNullException(nameof(context));
     _serviceFactory = serviceFactory ?? throw new ArgumentNullException(nameof(serviceFactory));
     _brokerClient   = subscriberServiceHelper ?? new BrokerClient();
     _fabricClient   = new FabricClient(FabricClientRole.User);
     _fabricClient.ServiceManager.ServiceNotificationFilterMatched += ServiceNotificationFilterMatched;
     _loggingCallback = loggingCallback;
     AutoUnsubscribe  = autoUnsubscribe;
 }
Ejemplo n.º 14
0
        private static async Task TestBrokerConnectionWithRHost(IBrokerClient brokerClient, CancellationToken cancellationToken)
        {
            var callbacks      = new NullRCallbacks();
            var connectionInfo = new HostConnectionInfo(nameof(TestBrokerConnectionAsync), callbacks, useRHostCommandLineArguments: true);
            var rhost          = await brokerClient.ConnectAsync(connectionInfo, cancellationToken);

            try {
                var rhostRunTask = rhost.Run(cancellationToken);
                callbacks.SetReadConsoleInput("q()\n");
                await rhostRunTask;
            } finally {
                rhost.Dispose();
            }
        }
Ejemplo n.º 15
0
        private async Task SwitchBrokerAsync(IBrokerClient oldBroker, CancellationToken cancellationToken, ReentrancyToken reentrancyToken)
        {
            var sessions = _sessions.Values.ToList();

            if (sessions.Any())
            {
                await SwitchSessionsAsync(sessions, cancellationToken, reentrancyToken);
            }
            else
            {
                // Ping isn't enough here - need a "full" test with RHost
                await TestBrokerConnectionWithRHost(_brokerProxy, cancellationToken, reentrancyToken);
            }
        }
Ejemplo n.º 16
0
 public void SendMessageToBrokers(int receiver, Message message, IBrokerClient callerBroker)
 {
     foreach (IBrokerClient broker in brokers)
     {
         try
         {
             if (!broker.Equals(callerBroker))
             {
                 broker.SendMessageToUser(receiver, message);
             }
         }
         catch (Exception)
         {
             // Não é necessário tratar a excecao, porque quem chama
             // o metodo nao tem de ter conhecimento se houve falhas ao conectar com outro broker.
         }
     }
 }
Ejemplo n.º 17
0
 public void UnregisterGroup(string groupName, IBrokerClient callerBroker)
 {
     foreach (IBrokerClient broker in brokers)
     {
         try
         {
             if (!broker.Equals(callerBroker))
             {
                 broker.UnregisterGroup(groupName);
             }
         }
         catch (Exception)
         {
             // Não é necessário tratar a excecao, porque quem chama
             // o metodo nao tem de ter conhecimento se houve falhas ao conectar com outro broker.
         }
     }
 }
Ejemplo n.º 18
0
        public RSession(int id, IBrokerClient brokerClient, Action onDispose)
        {
            Id            = id;
            BrokerClient  = brokerClient;
            _onDispose    = onDispose;
            _disposeToken = DisposeToken.Create <RSession>();
            _disableMutatingOnReadConsole = new CountdownDisposable(() => {
                if (!_delayedMutatedOnReadConsole)
                {
                    return;
                }

                _delayedMutatedOnReadConsole = false;
                Task.Run(() => Mutated?.Invoke(this, EventArgs.Empty));
            });

            _initializationLock   = new BinaryAsyncLock();
            _initializationTcs    = new TaskCompletionSourceEx <object>();
            _afterHostStartedTask = TaskUtilities.CreateCanceled(new RHostDisconnectedException());
        }
Ejemplo n.º 19
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (_Disposed)
            {
                throw new ObjectDisposedException(nameof(BrokerHostedService));
            }

            _senderBlock        = CreateClientBlock();
            _senderTransactions = CreateClientTransaction();

            _subscriptions.Add(_EventAggregator.Subscribe <Models.NewBlockEvent>(async o =>
            {
                await _senderBlock.Send(o);
            }));


            _subscriptions.Add(_EventAggregator.Subscribe <Models.NewTransactionEvent>(async o =>
            {
                await _senderTransactions.Send(o);
            }));
            return(Task.CompletedTask);
        }
Ejemplo n.º 20
0
        public RSession(int id, string name, IBrokerClient brokerClient, IExclusiveReaderLock initializationLock, Action onDispose)
        {
            Id            = id;
            Name          = name;
            BrokerClient  = brokerClient;
            _onDispose    = onDispose;
            _disposeToken = DisposeToken.Create <RSession>();
            _disableMutatingOnReadConsole = new CountdownDisposable(() => {
                if (!_delayedMutatedOnReadConsole)
                {
                    return;
                }

                _delayedMutatedOnReadConsole = false;
                Task.Run(() => Mutated?.Invoke(this, EventArgs.Empty));
            });

            _initializationLock = initializationLock;
            _stopHostLock       = new BinaryAsyncLock(true);
            _hostStartedTcs     = new TaskCompletionSourceEx <object>();
            _startupInfo        = new RHostStartupInfo();
        }
Ejemplo n.º 21
0
        private static async Task StopHostAsync(IBrokerClient brokerClient, string hostName, RHost host, Task hostRunTask)
        {
            // Try graceful shutdown with q() first.
            if (host != null)
            {
                try {
                    await Task.WhenAny(hostRunTask, host.QuitAsync(), Task.Delay(500)).Unwrap();
                } catch (Exception) { }

                if (hostRunTask.IsCompleted)
                {
                    return;
                }
            }

            // If it didn't work, tell the broker to forcibly terminate the host process.
            if (hostName != null)
            {
                try {
                    await brokerClient.TerminateSessionAsync(hostName);
                } catch (Exception) { }

                if (hostRunTask.IsCompleted)
                {
                    return;
                }
            }

            if (host != null)
            {
                // If nothing worked, then just disconnect.
                await host.DisconnectAsync();
            }

            await hostRunTask;
        }
 internal static Task UnsubscribeAsync(this IBrokerClient brokerClient, ActorBase actor, Type messageType)
 {
     return(brokerClient.UnsubscribeAsync(CreateReferenceWrapper(actor), messageType));
 }
Ejemplo n.º 23
0
 public RSessionTest(TestMethodFixture testMethod) {
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest));
 }
Ejemplo n.º 24
0
 protected SubscriberStatelessServiceBase(StatelessServiceContext serviceContext, IBrokerClient brokerClient = null)
     : base(serviceContext)
 {
     _brokerClient = brokerClient ?? new BrokerClient();
 }
Ejemplo n.º 25
0
 public ReadInput(IServiceContainer services, TestMethodFixture testMethod)
 {
     _brokerClient = CreateLocalBrokerClient(services, nameof(RSessionTest) + nameof(ReadInput));
     _session      = new RSession(0, testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
     _callback     = new RSessionCallbackStub();
 }
Ejemplo n.º 26
0
 private static async Task TestBrokerConnectionWithRHost(IBrokerClient brokerClient, CancellationToken cancellationToken) {
     var callbacks = new NullRCallbacks();
     var connectionInfo = new BrokerConnectionInfo(nameof(TestBrokerConnectionAsync), callbacks);
     var rhost = await brokerClient.ConnectAsync(connectionInfo, cancellationToken);
     try {
         var rhostRunTask = rhost.Run(cancellationToken);
         callbacks.SetReadConsoleInput("q()\n");
         await rhostRunTask;
     } finally {
         rhost.Dispose();
     }
 }
Ejemplo n.º 27
0
 public void SetApiBroker(IBrokerClient clientBroker)
 {
     this.clientBroker = clientBroker;
 }
Ejemplo n.º 28
0
 public ProcessorImpl(ISemtech semtech, ILora lora, IBrokerClient brokerclient)
 {
     _semtech      = semtech;
     _lora         = lora;
     _brokerclient = brokerclient;
 }
 public InteractionEvaluation(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver) {
     _taskObserver = taskObserver;
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(InteractionEvaluation));
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }
Ejemplo n.º 30
0
 public IBrokerClient Set(IBrokerClient broker)
 {
     return(Interlocked.Exchange(ref _broker, broker));
 }
Ejemplo n.º 31
0
 public BrokerClientProxy()
 {
     _broker = new NullBrokerClient();
 }
 /// <inheritdoc />
 public MockSubscriberStatelessServiceBase(StatelessServiceContext serviceContext, IBrokerClient brokerClient = null) : base(serviceContext, brokerClient)
 {
 }
 public SampleActorSubscriber(ActorService actorService, ActorId actorId)
     : base(actorService, actorId)
 {
     _brokerClient = new BrokerClient(FabricConfiguration.GetBrokerServiceLocator());
 }
Ejemplo n.º 34
0
 public void SetApiCobranza(IBrokerClient clientBroker)
 {
     this.clientBroker = clientBroker;
 }
Ejemplo n.º 35
0
 public Output(TestMethodFixture testMethod) {
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(Output));
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }