コード例 #1
0
        private static BrokerHost <Topic> InitializeHost()
        {
            var ipAddress = ConfigurationManager.AppSettings["ipAddress"];
            var port      = ConfigurationManager.AppSettings["port"];
            var endpoint  = ConfigurationManager.AppSettings["endpoint"];
            var state     = (State)Enum.Parse(typeof(State), ConfigurationManager.AppSettings["state"]);

            var brokerHost = new BrokerHost <Topic>();
            var broker     = new Broker <Topic>(state);

            broker.InitializeReplicationClientProxy();

            broker.AddTopic(Topic.FirstT);
            broker.AddTopic(Topic.SecondT);
            broker.AddTopic(Topic.ThirdT);

            if (state == State.StandBy)
            {
                broker.RequestIntegiryUpdate();
            }

            brokerHost.Initialize(ipAddress, port, endpoint, broker);

            return(brokerHost);
        }
コード例 #2
0
        public void AddTopicWhenTopicIsAlreadyAdded()
        {
            var broker = new Broker <Topic>(State.StandBy);

            var result = broker.AddTopic(Topic.FirstT);

            Assert.IsTrue(result);

            result = broker.AddTopic(Topic.FirstT);

            Assert.IsTrue(result);
        }
コード例 #3
0
        public void RequestStreamWithBadCount()
        {
            var broker = new Broker <Topic>(State.StandBy);

            broker.AddTopic(Topic.FirstT);

            int count = 10;

            var stream = new List <Message <Topic> >(count);

            var testDataString = "TEST";

            for (int i = 0; i < count; i++)
            {
                var message = new Message <Topic>()
                {
                    Topic = Topic.FirstT, Data = testDataString.ToByteArray()
                };

                var response = broker.PublishSync(message);

                Assert.AreEqual(response, NotifyStatus.Secceeded);
            }

            var topicCount = broker.TopicCount(Topic.FirstT);

            Assert.AreEqual(count, topicCount);

            var retVal = broker.MultipleRequest(new MultipleRequest <Topic>()
            {
                Topic = Topic.FirstT, Offset = 0, Count = 17
            });

            Assert.AreEqual(retVal.Count, count);
        }
コード例 #4
0
        public void DeleteTopic()
        {
            var broker = new Broker <Topic>(State.StandBy);

            var result = broker.AddTopic(Topic.FirstT);

            Assert.IsTrue(result);

            result = broker.DeleteTopic(Topic.FirstT);

            Assert.IsTrue(result);
        }
コード例 #5
0
        public void TopicCountTest()
        {
            var broker = new Broker <Topic>(State.StandBy);

            broker.AddTopic(Topic.FirstT);

            var testDataString = "TEST";
            var response       = broker.PublishSync(new Message <Topic>()
            {
                Topic = Topic.FirstT, Data = testDataString.ToByteArray()
            });

            Assert.AreEqual(response, NotifyStatus.Secceeded);
            Assert.AreEqual(1, broker.TopicCount(Topic.FirstT));
            Assert.AreEqual(-1, broker.TopicCount(Topic.SecondT));
        }
コード例 #6
0
        public void RequestMessageWithInvalidOffset()
        {
            var broker = new Broker <Topic>(State.StandBy);

            broker.AddTopic(Topic.FirstT);

            var testDataString = "TEST";
            var response       = broker.PublishSync(new Message <Topic>()
            {
                Topic = Topic.FirstT, Data = testDataString.ToByteArray()
            });

            Assert.AreEqual(response, NotifyStatus.Secceeded);

            var message = broker.SingleRequest(new SingleRequest <Topic>()
            {
                Topic = Topic.FirstT, Offset = 4
            });

            Assert.IsNull(message);
        }
コード例 #7
0
        public void RequestMessageWithValidParametars()
        {
            var broker = new Broker <Topic>(State.StandBy);

            broker.AddTopic(Topic.FirstT);

            var testDataString = "TEST";
            var response       = broker.PublishSync(new Message <Topic>()
            {
                Topic = Topic.FirstT, Data = testDataString.ToByteArray()
            });

            Assert.AreEqual(response, NotifyStatus.Secceeded);

            var message = broker.SingleRequest(new SingleRequest <Topic>()
            {
                Topic = Topic.FirstT, Offset = 0
            });

            Assert.AreEqual(message.Data.ToObject <string>(), testDataString);
            Assert.AreEqual(message.Topic, Topic.FirstT);
        }