예제 #1
0
        public void RetrieveMessage_RequestMessage_ShouldReturnOriginalMessage()
        {
            var sut = new TitanicFileIO(Path.GetTempPath());

            var message = new NetMQMessage();

            message.Push("Hello World");
            message.Push("echo");

            var id = Guid.NewGuid();

            sut.SaveMessage(TitanicOperation.Request, id, message);

            var result = sut.GetMessage(TitanicOperation.Request, id);

            result.FrameCount.Should().Be(2, "because there are two frames");

            for (var i = 0; i < result.FrameCount; i++)
            {
                (result[i] == message[i]).Should().BeTrue("because they are identical.");
            }

            var expectedDir  = sut.TitanicDirectory;
            var expectedFile = Path.Combine(expectedDir, id + _request_ending);

            File.Delete(expectedFile);
        }
예제 #2
0
        public void SaveMessage_ReplyMessage_SholdCreateNewFileWithGuidAsName()
        {
            var sut = new TitanicFileIO(Path.GetTempPath());

            var message = new NetMQMessage();

            message.Push("Hello World");
            message.Push("echo");

            var messageSize = message[0].BufferSize + message[1].BufferSize + 4;    // 2 lines with \r\n

            var id = Guid.NewGuid();

            sut.SaveMessage(TitanicOperation.Reply, id, message);

            var expectedDir  = sut.TitanicDirectory;
            var expectedFile = Path.Combine(expectedDir, id + _reply_ending);

            File.Exists(expectedFile).Should().BeTrue("because the file exists");

            var info = new FileInfo(expectedFile);

            info.Length.Should().Be(messageSize);

            File.Delete(expectedFile);
        }
예제 #3
0
        public void CloseRequest_MaxEntryClosedAndAdditionalRequestsAndReplies_ShouldReorganizeQueue()
        {
            const int max_entries         = 20;
            const int additional_requests = 5;
            var       path = Path.Combine(Path.GetTempPath(), ".titanic", "Close_4");

            var sut = new TitanicFileIO(path, max_entries);

            var titanicQueue = sut.TitanicQueue;

            for (var i = 0; i < max_entries + additional_requests; i++)
            {
                var id = Guid.NewGuid();
                sut.SaveNewRequestEntry(id);  // -> fill titanic.queue

                var message = new NetMQMessage();
                message.Push($"Message #{i}");
                message.Push("echo");

                sut.SaveMessage(TitanicOperation.Request, id, message);
            }

            foreach (var entry in sut.GetRequestEntries(null).Skip(3).Take(5))
            {
                sut.SaveProcessedRequestEntry(entry);

                var message = sut.GetMessage(TitanicOperation.Request, entry.RequestId);

                sut.SaveMessage(TitanicOperation.Reply, entry.RequestId, message);
            }

            var requests = sut.GetRequestEntries(null).ToArray();

            requests.Length.Should().Be(max_entries + additional_requests);
            requests.Count(re => re.State == RequestEntry.Is_Processed).Should().Be(5);

            for (var i = 0; i < max_entries; i++)
            {
                sut.CloseRequest(requests[i].RequestId);      // mark closed not worrying about state
            }
            sut.GetNotClosedRequestEntries()
            .Count()
            .Should()
            .Be(additional_requests, "because 5 requests should have been left over!");

            Directory.Delete(sut.TitanicDirectory, true);
        }
예제 #4
0
        public void Exists_ExistingReply_ShouldReturnTrue()
        {
            var sut = new TitanicFileIO(Path.GetTempPath());

            const TitanicOperation op = TitanicOperation.Reply;

            var message = new NetMQMessage();

            message.Push("Hello World");
            message.Push("echo");

            var id = Guid.NewGuid();

            sut.SaveMessage(op, id, message);

            sut.ExistsMessage(op, id).Should().BeTrue("because it has been created.");

            var expectedDir  = sut.TitanicDirectory;
            var expectedFile = Path.Combine(expectedDir, id + _reply_ending);

            File.Delete(expectedFile);
        }