Exemple #1
0
    public async Task ShouldHave10000MaxValue(MessageIdFactory sut)
    {
        var results = Enumerable.Range(1, 15000)
                      .Select(x => Task.Run(async() =>
        {
            await Task.Delay(10);
            return(sut.CreateMessageId());
        }))
                      .ToList();

        await Task.WhenAll(results);

        var count = results.Select(x => x.Result).Distinct().Count();

        Assert.True(count >= 10000);
        Assert.True(count < 10100);

        Assert.Equal(1, results.Select(x => Convert.ToInt32(x.Result)).Min());
        Assert.True(results.Select(x => Convert.ToInt32(x.Result)).Max() < 10100);
        Assert.True(results.Select(x => Convert.ToInt32(x.Result)).Max() >= 10000);
        Assert.Equal(2, results.Select(x => x.Result).Count(x => x == "1"));
        Assert.Equal(2, results.Select(x => x.Result).Count(x => x == "4900"));
        Assert.Equal(1, results.Select(x => x.Result).Count(x => x == "5100"));
        Assert.Equal(1, results.Select(x => x.Result).Count(x => x == "10000"));
    }
Exemple #2
0
    public async Task ShouldResetCounterMultipleTimes(
        int times, int totalCount, MessageIdFactory sut)
    {
        var results = Enumerable.Range(1, totalCount)
                      .Select(x => Task.Run(async() =>
        {
            await Task.Delay(10);
            return(sut.CreateMessageId());
        }))
                      .ToList();

        await Task.WhenAll(results);

        var count = results.Select(x => x.Result).Distinct().Count();

        Assert.True(count >= 10000);
        Assert.True(count < 10100);

        Assert.Equal(1, results.Select(x => Convert.ToInt32(x.Result)).Min());
        Assert.True(results.Select(x => Convert.ToInt32(x.Result)).Max() < 10100);
        Assert.True(results.Select(x => Convert.ToInt32(x.Result)).Max() >= 10000);
        Assert.Equal(times + 1, results.Select(x => x.Result).Count(x => x == "1"));
        Assert.Equal(times + 1, results.Select(x => x.Result).Count(x => x == "4900"));
        Assert.Equal(times, results.Select(x => x.Result).Count(x => x == "5100"));
        Assert.Equal(times, results.Select(x => x.Result).Count(x => x == "10000"));
    }
Exemple #3
0
        /// <summary>
        ///   Executes the specified service method completion sink.
        /// </summary>
        /// <param name = "serviceMethodUiBridge">The service method completion sink.</param>
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            m_ServiceMethodUiBridge = serviceMethodUiBridge;
            AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(m_AsyncKey);

            try
            {
                Feature feature = BuildFeature(serviceMethodUiBridge);
                CreateFeatureRequest      request = CreateFeatureRequest.Create(MessageIdFactory.GenerateMessageId(), feature);
                IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy();
                featureStoreServiceProxy.BeginCreateFeature(
                    request,
                    ar =>
                {
                    string rtfResults;
                    try
                    {
                        CreateFeatureResponse response = featureStoreServiceProxy.EndCreateFeature(ar);
                        rtfResults = BuildResultsRichText(request, response, GetType().Name);
                    }
                    catch (Exception e)
                    {
                        rtfResults = BuildExceptionRichText(e);
                    }

                    asyncOperation.PostOperationCompleted(HandleEndAsync, rtfResults);
                },
                    null);
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Exemple #4
0
 public TcpMessageSender(AbstractClientConfig clientConfig, IMessageStatistics statistics, MessageIdFactory messageIdFactory)
 {
     _mClientConfig    = clientConfig;
     _mStatistics      = statistics;
     _mActive          = true;
     _mQueue           = new BlockingThreadSafeQueue <IMessageTree>();
     _mAtomicTrees     = new BlockingThreadSafeQueue <IMessageTree>(MAX_ATOMIC_MESSAGES);
     _mCodec           = new PlainTextMessageCodec();
     _messageIdFactory = messageIdFactory;
 }
 public TcpMessageSender(AbstractClientConfig clientConfig, IMessageStatistics statistics, MessageIdFactory messageIdFactory)
 {
     _mClientConfig = clientConfig;
     _mStatistics = statistics;
     _mActive = true;
     _mQueue = new BlockingThreadSafeQueue<IMessageTree>();
     _mAtomicTrees = new BlockingThreadSafeQueue<IMessageTree>(MAX_ATOMIC_MESSAGES);
     _mCodec = new PlainTextMessageCodec();
     _messageIdFactory = messageIdFactory;
 }
Exemple #6
0
        public static MessageWrapper GetMessage <T>(T mes, bool rudpEnabled, out uint messageId)
            where T : ITypedMessage
        {
            var serializedMessage = ZeroFormatterSerializer.Serialize(mes);
            var messageType       = mes.GetMessageType();

            messageId = MessageIdFactory.GetMessageId();
            var message = new MessageWrapper(messageType, serializedMessage, messageId, rudpEnabled);

            return(message);
        }
 public MatchFactory(MatchRemover matchRemover, UdpSendUtils udpSendUtils,
                     MatchmakerNotifier matchmakerNotifier, IpAddressesStorage ipAddressesStorage,
                     MessageIdFactory messageIdFactory, MessagesPackIdFactory messagesPackIdFactory)
 {
     this.matchRemover          = matchRemover;
     this.udpSendUtils          = udpSendUtils;
     this.messageIdFactory      = messageIdFactory;
     this.messagesPackIdFactory = messagesPackIdFactory;
     this.matchmakerNotifier    = matchmakerNotifier;
     this.ipAddressesStorage    = ipAddressesStorage;
 }
Exemple #8
0
 public MatchRemover(MatchStorage matchStorage, ByteArrayRudpStorage byteArrayRudpStorage,
                     UdpSendUtils udpSendUtils, MatchmakerNotifier matchmakerNotifier, IpAddressesStorage ipAddressesStorage,
                     MessageIdFactory messageIdFactory, MessagesPackIdFactory messagesPackIdFactory)
 {
     this.messagesPackIdFactory = messagesPackIdFactory;
     this.matchStorage          = matchStorage;
     this.byteArrayRudpStorage  = byteArrayRudpStorage;
     this.matchmakerNotifier    = matchmakerNotifier;
     this.ipAddressesStorage    = ipAddressesStorage;
     this.messageIdFactory      = messageIdFactory;
     matchesToRemove            = new ConcurrentQueue <int>();
     playersMatchFinishNotifier = new PlayersMatchFinishNotifier(udpSendUtils, ipAddressesStorage);
 }
Exemple #9
0
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            FeatureScope featureScope = BuildFeatureScope(serviceMethodUiBridge);

            try
            {
                RetrieveDefinedFeaturesRequest request =
                    RetrieveDefinedFeaturesRequest.Create(MessageIdFactory.GenerateMessageId(), featureScope);
                IFeatureStoreServiceProxy       featureStoreServiceProxy = new FeatureStoreServiceProxy();
                RetrieveDefinedFeaturesResponse response = featureStoreServiceProxy.RetrieveDefinedFeatures(request);
                serviceMethodUiBridge.DisplayResults(BuildResultsRichText(request, response, GetType().Name));
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Exemple #10
0
    public async Task ShouldMakeUniqueIdsConcurrently_InSequence(MessageIdFactory sut)
    {
        var results = Enumerable.Range(1, 1000)
                      .Select(x => Task.Run(async() =>
        {
            await Task.Delay(10);
            return(sut.CreateMessageId());
        }))
                      .ToList();

        await Task.WhenAll(results);

        var count = results.Select(x => x.Result).Distinct().Count();

        Assert.Equal(1000, count);
        Assert.Equal(1, results.Select(x => Convert.ToInt32(x.Result)).Min());
        Assert.Equal(1000, results.Select(x => Convert.ToInt32(x.Result)).Max());
    }
Exemple #11
0
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            FeatureKey featureKey = BuildFeatureKey(serviceMethodUiBridge);

            try
            {
                CheckFeatureStateRequest request = CheckFeatureStateRequest.Create(
                    MessageIdFactory.GenerateMessageId(), featureKey);
                IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy();
                CheckFeatureStateResponse response = featureStoreServiceProxy.CheckFeatureState(request);

                serviceMethodUiBridge.DisplayResults(BuildResultsRichText(request, response, GetType().Name));
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
        public virtual void Initialize(AbstractClientConfig clientConfig)
        {
            _mClientConfig = clientConfig;
            _mStatistics = new DefaultMessageStatistics();

            _mFactory = new MessageIdFactory();
            // initialize domain and ip address
            _mFactory.Initialize(_mClientConfig.Domain.Id);

            _mSender = new TcpMessageSender(_mClientConfig, _mStatistics, _mFactory);
            _mSender.Initialize();

            _mStatusUpdateTask = new StatusUpdateTask(_mStatistics, _mClientConfig);

            _mTaggedTransactions = new LRUCache<string, ITaggedTransaction>(CatConstants.TAGGED_TRANSACTION_CACHE_SIZE);

            // start status update task
            Thread statusUpdateTask = new Thread(_mStatusUpdateTask.Run);
            statusUpdateTask.IsBackground = true;
            statusUpdateTask.Start();
            Logger.Info("Thread(StatusUpdateTask) started.");
        }
Exemple #13
0
        public void Run()
        {
            if (matchmakerListenerCts != null)
            {
                throw new Exception("Сервер уже запущен");
            }

            //Старт уведомления матчмейкера о смертях игроков и окончании матчей
            MatchmakerNotifier notifier = new MatchmakerNotifier();

            matchmakerNotifierCts = notifier.StartThread();

            //Создание структур данных для матчей
            matchStorage = new MatchStorage();


            MessageIdFactory messageIdFactory = new MessageIdFactory();
            MessageFactory   messageFactory   = new MessageFactory(messageIdFactory);

            InputEntitiesCreator inputEntitiesCreator = new InputEntitiesCreator(matchStorage);
            ExitEntitiesCreator  exitEntitiesCreator  = new ExitEntitiesCreator(matchStorage);

            ByteArrayRudpStorage byteArrayRudpStorage = new ByteArrayRudpStorage();

            shittyUdpMediator = new ShittyUdpMediator();

            MessagesPackIdFactory   messagesPackIdFactory   = new MessagesPackIdFactory();
            IpAddressesStorage      ipAddressesStorage      = new IpAddressesStorage();
            SimpleMessagesPacker    simpleMessagesPacker    = new SimpleMessagesPacker(PackingHelper.Mtu, shittyUdpMediator, messagesPackIdFactory);
            OutgoingMessagesStorage outgoingMessagesStorage = new OutgoingMessagesStorage(simpleMessagesPacker, ipAddressesStorage);
            UdpSendUtils            udpSendUtils            = new UdpSendUtils(byteArrayRudpStorage, outgoingMessagesStorage, messageFactory);
            MessageProcessor        messageProcessor        = new MessageProcessor(inputEntitiesCreator, exitEntitiesCreator,
                                                                                   byteArrayRudpStorage,
                                                                                   // udpSendUtils,
                                                                                   ipAddressesStorage);

            shittyUdpMediator.SetProcessor(messageProcessor);

            matchRemover = new MatchRemover(matchStorage, byteArrayRudpStorage, udpSendUtils, notifier, ipAddressesStorage, messageIdFactory, messagesPackIdFactory);
            MatchFactory          matchFactory          = new MatchFactory(matchRemover, udpSendUtils, notifier, ipAddressesStorage, messageIdFactory, messagesPackIdFactory);
            MatchCreator          matchCreator          = new MatchCreator(matchFactory);
            MatchLifeCycleManager matchLifeCycleManager =
                new MatchLifeCycleManager(matchStorage, matchCreator, matchRemover);

            //Старт прослушки матчмейкера
            MatchModelMessageHandler matchModelMessageHandler = new MatchModelMessageHandler(matchCreator, matchStorage);
            MatchmakerListener       matchmakerListener       = new MatchmakerListener(matchModelMessageHandler, HttpPort);
            MonitorListener          monitorListener          = new MonitorListener(HttpPort);

            monitorListenerCts    = monitorListener.StartThread();
            matchmakerListenerCts = matchmakerListener.StartThread();


            //Старт прослушки игроков
            shittyUdpMediator
            .SetupConnection(UdpPort)
            .StartReceiveThread();

            RudpMessagesSender rudpMessagesSender = new RudpMessagesSender(byteArrayRudpStorage, matchStorage, udpSendUtils, ipAddressesStorage);
            GameEngineTicker   gameEngineTicker   = new GameEngineTicker(matchStorage, matchLifeCycleManager,
                                                                         inputEntitiesCreator, exitEntitiesCreator, rudpMessagesSender, outgoingMessagesStorage);

            //Старт тиков
            Chronometer chronometer = ChronometerFactory.Create(gameEngineTicker.Tick);

            chronometer.StartEndlessLoop();
        }