コード例 #1
0
        public void FromStringThrowsOnNoToken()
        {
            TestEntry entryWithNoTag = TestEntry.Create();
            string    requestString  = JsonConvert.SerializeObject(entryWithNoTag);

            Assert.Throws <ArgumentException>(() => QueueEntry.FromRequestString(new QueueContext("x"), requestString, Int32.MaxValue));
        }
コード例 #2
0
        public void FromStringThrowsOnTooBigFrame()
        {
            TestEntryFull entry         = TestEntryFull.Create();
            string        requestString = JsonConvert.SerializeObject(entry);

            byte[] bytes = Encoding.UTF8.GetBytes(requestString);

            Assert.Throws <TooBigRequestException>(() => QueueEntry.FromRequestString(new QueueContext("x"), requestString, bytes.Length - 1));
        }
コード例 #3
0
        public void CreateJsonFromRequestString()
        {
            TestEntryFull originalEntry = TestEntryFull.Create();

            string requestString = JsonConvert.SerializeObject(originalEntry);

            QueueEntry requestEntry = QueueEntry.FromRequestString(new QueueContext("x"), requestString, Int32.MaxValue);

            Assert.AreEqual(originalEntry.Tag, requestEntry.Tag);
            Assert.IsTrue(originalEntry.Equals(JsonConvert.DeserializeObject <TestEntryFull>(requestEntry.Data)));
        }
コード例 #4
0
        public void EntriesJoinedInJsonArray(int entriesCount)
        {
            Guid[]   entriesIdentifiers = Enumerable.Repeat(0, entriesCount).Select(p => Guid.NewGuid()).ToArray();
            string[] entries            = entriesIdentifiers.Select(p => $"{{\"Tag\":\"tag\", \"D\":\"{p}\"}}").ToArray();

            DequeueResult result = new DequeueResult(entries.Select(p => QueueEntry.FromRequestString(new QueueContext("WHATEVER"), p, 1000)).ToArray());

            Assert.IsTrue(result.IsOk);

            string resultString = result.DataToString();

            Assert.AreEqual('[', resultString.First());
            Assert.AreEqual(']', resultString.Last());

            Assert.IsTrue(entriesIdentifiers.SequenceEqual(JArray.Parse(resultString).Select(p => Guid.Parse(p["D"].ToString()))));
        }
コード例 #5
0
        public LogicResult Enqueue(string queueName, string requestBody)
        {
            return(LockLocallyWithContext(queueName, context =>
            {
                if (String.IsNullOrWhiteSpace(requestBody))
                {
                    return new SuccessResult();
                }

                JToken token = JToken.Parse(requestBody);

                QueueEntry[] entries =
                    token.Type == JTokenType.Array
                        ? token.Children().Select(p => QueueEntry.FromRequestString(context, p.ToString(), _configurationReader.Configuration.Files.DataFileMaximumSizeB)).ToArray()
                        : new[] { QueueEntry.FromRequestString(context, token.ToString(), _configurationReader.Configuration.Files.DataFileMaximumSizeB) };

                return _nodeQueueManager.Enqueue(context, entries);
            }));
        }