Example #1
0
        public void unframe_record_when_provided_exactly_enough_data_in_one_call()
        {
            int unframedCnt = 0;
            var framer      = new LengthPrefixSuffixFramer(r =>
            {
                unframedCnt += 1;
                Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
            });

            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x03, 0x00, 0x00, 0x00,
                                                                    0x07, 0x17, 0x27,
                                                                    0x03, 0x00, 0x00, 0x00 }));

            Assert.AreEqual(1, unframedCnt);
        }
Example #2
0
        public void unframe_record_when_provided_with_small_chunks_of_data_at_a_time()
        {
            int unframedCnt = 0;
            var framer      = new LengthPrefixSuffixFramer(r => {
                unframedCnt += 1;
                Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
            });

            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x03, 0x00 }));
            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x00, 0x00 }));
            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x07, 0x17, 0x27 }));
            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x03, 0x00 }));

            Assert.AreEqual(0, unframedCnt);
            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x00, 0x00 }));
            Assert.AreEqual(1, unframedCnt);
        }
        public ClusterStorageWriterService(IPublisher bus,
                                           ISubscriber subscribeToBus,
                                           TimeSpan minFlushDelay,
                                           TFChunkDb db,
                                           TFChunkWriter writer,
                                           IIndexWriter indexWriter,
                                           IEpochManager epochManager,
                                           Func <long> getLastCommitPosition)
            : base(bus, subscribeToBus, minFlushDelay, db, writer, indexWriter, epochManager)
        {
            Ensure.NotNull(getLastCommitPosition, "getLastCommitPosition");

            _getLastCommitPosition = getLastCommitPosition;
            _framer = new LengthPrefixSuffixFramer(OnLogRecordUnframed, TFConsts.MaxLogRecordSize);

            SubscribeToMessage <ReplicationMessage.ReplicaSubscribed>();
            SubscribeToMessage <ReplicationMessage.CreateChunk>();
            SubscribeToMessage <ReplicationMessage.RawChunkBulk>();
            SubscribeToMessage <ReplicationMessage.DataChunkBulk>();
        }
Example #4
0
        public void discard_data_when_reset_and_continue_unframing_from_blank_slate()
        {
            int unframedCnt = 0;
            var framer      = new LengthPrefixSuffixFramer(r => {
                if (unframedCnt == 0)
                {
                    Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
                }
                else if (unframedCnt == 1)
                {
                    Assert.AreEqual(new byte[] { 0x05, 0x15 }, ReadAll(r));
                }
                else
                {
                    Assert.Fail();
                }

                unframedCnt += 1;
            });

            framer.UnFrameData(new ArraySegment <byte>(new byte[] {
                0x03, 0x00, 0x00, 0x00,
                0x07, 0x17, 0x27,
                0x03, 0x00, 0x00, 0x00,
                0xAA, 0xBB, 0xCC, 0x00,
                0x01, 0x02, 0x03, 0x04,
                0x05, 0x06, 0x07, 0x08
            }));

            Assert.AreEqual(1, unframedCnt);

            framer.Reset();

            framer.UnFrameData(new ArraySegment <byte>(new byte[] {
                0x02, 0x00, 0x00, 0x00,
                0x05, 0x15,
                0x02, 0x00, 0x00, 0x00
            }));

            Assert.AreEqual(2, unframedCnt);
        }
Example #5
0
        public void unframe_two_consecutive_records()
        {
            int unframedCnt = 0;
            var framer      = new LengthPrefixSuffixFramer(r => {
                if (unframedCnt == 0)
                {
                    Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
                }
                else if (unframedCnt == 1)
                {
                    Assert.AreEqual(new byte[] { 0x05, 0x15 }, ReadAll(r));
                }
                else
                {
                    Assert.Fail();
                }

                unframedCnt += 1;
            });

            framer.UnFrameData(new ArraySegment <byte>(new byte[] {
                0x03, 0x00, 0x00, 0x00,
                0x07, 0x17, 0x27
            }));

            Assert.AreEqual(0, unframedCnt);

            framer.UnFrameData(new ArraySegment <byte>(new byte[] {
                0x03, 0x00, 0x00, 0x00,
                0x02, 0x00, 0x00, 0x00,
                0x05, 0x15
            }));

            Assert.AreEqual(1, unframedCnt);

            framer.UnFrameData(new ArraySegment <byte>(new byte[] { 0x02, 0x00, 0x00, 0x00 }));

            Assert.AreEqual(2, unframedCnt);
        }
Example #6
0
        public void correctly_frame_byte_array()
        {
            var framer     = new LengthPrefixSuffixFramer(r => { });
            var data       = new byte[] { 0x7, 0x17, 0x27 };
            var framedData = MergeBytes(framer.FrameData(new ArraySegment <byte>(data)));

            Assert.AreEqual(11, framedData.Length);

            Assert.AreEqual(0x03, framedData[0]);
            Assert.AreEqual(0x00, framedData[1]);
            Assert.AreEqual(0x00, framedData[2]);
            Assert.AreEqual(0x00, framedData[3]);

            Assert.AreEqual(0x07, framedData[4]);
            Assert.AreEqual(0x17, framedData[5]);
            Assert.AreEqual(0x27, framedData[6]);

            Assert.AreEqual(0x03, framedData[7]);
            Assert.AreEqual(0x00, framedData[8]);
            Assert.AreEqual(0x00, framedData[9]);
            Assert.AreEqual(0x00, framedData[10]);
        }