Пример #1
1
        public void testWrite()
        {
            MemoryStream stream = new MemoryStream();
            CollectionMetadataWriter writer =
                new CollectionMetadataWriter(stream);

            DocumentInfo doc1 = new DocumentInfo("http://www.google.com/index.html", "Google", 150, "#Section1", null);
            DocumentInfo doc2 = new DocumentInfo("http://www.google.com/index.html", "Google", 250, "#Section2", null);
            writer.AddDocumentInfo(0, doc1);
            writer.AddDocumentInfo(1, doc2);
            writer.WriteOut();

            BinaryReader reader = new BinaryReader(stream);
            long collectionTokenCount = reader.ReadInt64();
            Assert.AreEqual(400, collectionTokenCount);

            FileIndex<long, DocumentInfo> documentIndex = new FileIndex<long, DocumentInfo>(
                new LongEncoder(), new DocumentInfoEncoder(), stream);
            Assert.AreEqual(2, documentIndex.EntryCount);

            DocumentInfo docInfo;
            Assert.IsTrue(documentIndex.TryGet(0, out docInfo));
            Assert.AreEqual(doc1, docInfo);

            Assert.IsTrue(documentIndex.TryGet(1, out docInfo));
            Assert.AreEqual(doc2, docInfo);
        }
        public void testEncodeDecode()
        {
            MemoryStream stream = new MemoryStream();
            DocumentInfoEncoder encoder = new DocumentInfoEncoder();

            DocumentInfo writtenDoc = new DocumentInfo("http://www.google.com/index.html", "Google", 150, "#Section1", null);
            encoder.write(new BinaryWriter(stream), writtenDoc);

            stream.Seek(0, SeekOrigin.Begin);

            DocumentInfo readDoc = encoder.read(new BinaryReader(stream));
            Assert.AreEqual(writtenDoc, readDoc);
        }
 internal void AddDocumentInfo(long documentId, DocumentInfo documentInfo)
 {
     documentsInfo.Add(documentId, documentInfo);
     collectionTokenCount += documentInfo.Length;
 }