示例#1
0
        public virtual void TestHugeFile()
        {
            var f = new DenseRAMFile();
            // output part
            var @out = new RAMOutputStream(f);
            var b1   = new byte[RAMOutputStream.BUFFER_SIZE];
            var b2   = new byte[RAMOutputStream.BUFFER_SIZE / 3];

            for (int i = 0; i < b1.Length; i++)
            {
                b1[i] = (byte)(sbyte)(i & 0x0007F);
            }
            for (int i = 0; i < b2.Length; i++)
            {
                b2[i] = (byte)(sbyte)(i & 0x0003F);
            }
            long n = 0;

            Assert.AreEqual(n, @out.Length, "output length must match");
            while (n <= MAX_VALUE - b1.Length)
            {
                @out.WriteBytes(b1, 0, b1.Length);
                @out.Flush();
                n += b1.Length;
                Assert.AreEqual(n, @out.Length, "output length must match");
            }
            //System.out.println("after writing b1's, length = "+out.Length()+" (MAX_VALUE="+MAX_VALUE+")");
            int  m = b2.Length;
            long L = 12;

            for (int j = 0; j < L; j++)
            {
                for (int i = 0; i < b2.Length; i++)
                {
                    b2[i]++;
                }
                @out.WriteBytes(b2, 0, m);
                @out.Flush();
                n += m;
                Assert.AreEqual(n, @out.Length, "output length must match");
            }
            @out.Dispose();
            // input part
            var @in = new RAMInputStream("testcase", f);

            Assert.AreEqual(n, @in.Length, "input length must match");
            //System.out.println("input length = "+in.Length()+" % 1024 = "+in.Length()%1024);
            for (int j = 0; j < L; j++)
            {
                long loc = n - (L - j) * m;
                @in.Seek(loc / 3);
                @in.Seek(loc);
                for (int i = 0; i < m; i++)
                {
                    var bt       = (sbyte)@in.ReadByte();
                    var expected = (sbyte)(1 + j + (i & 0x0003F));
                    Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
                }
            }
        }
示例#2
0
        public virtual void  TestHugeFile()
        {
            DenseRAMFile f = new DenseRAMFile();
            // output part
            RAMOutputStream out_Renamed = new RAMOutputStream(f);

            byte[] b1 = new byte[RAMOutputStream.BUFFER_SIZE_ForNUnit];
            byte[] b2 = new byte[RAMOutputStream.BUFFER_SIZE_ForNUnit / 3];
            for (int i = 0; i < b1.Length; i++)
            {
                b1[i] = (byte)(i & 0x0007F);
            }
            for (int i = 0; i < b2.Length; i++)
            {
                b2[i] = (byte)(i & 0x0003F);
            }
            long n = 0;

            Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
            while (n <= MAX_VALUE - b1.Length)
            {
                out_Renamed.WriteBytes(b1, 0, b1.Length);
                out_Renamed.Flush();
                n += b1.Length;
                Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
            }
            //System.out.println("after writing b1's, length = "+out.length()+" (MAX_VALUE="+MAX_VALUE+")");
            int  m = b2.Length;
            long L = 12;

            for (int j = 0; j < L; j++)
            {
                for (int i = 0; i < b2.Length; i++)
                {
                    b2[i]++;
                }
                out_Renamed.WriteBytes(b2, 0, m);
                out_Renamed.Flush();
                n += m;
                Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
            }
            out_Renamed.Close();
            // input part
            RAMInputStream in_Renamed = new RAMInputStream(f);

            Assert.AreEqual(n, in_Renamed.Length(), "input length must match");
            //System.out.println("input length = "+in.length()+" % 1024 = "+in.length()%1024);
            for (int j = 0; j < L; j++)
            {
                long loc = n - (L - j) * m;
                in_Renamed.Seek(loc / 3);
                in_Renamed.Seek(loc);
                for (int i = 0; i < m; i++)
                {
                    byte bt       = in_Renamed.ReadByte();
                    byte expected = (byte)(1 + j + (i & 0x0003F));
                    Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
                }
            }
        }
		public virtual void  TestHugeFile()
		{
			DenseRAMFile f = new DenseRAMFile();
			// output part
			RAMOutputStream out_Renamed = new RAMOutputStream(f);
			byte[] b1 = new byte[RAMOutputStream.BUFFER_SIZE_ForNUnitTest];
			byte[] b2 = new byte[RAMOutputStream.BUFFER_SIZE_ForNUnitTest / 3];
			for (int i = 0; i < b1.Length; i++)
			{
				b1[i] = (byte) (i & 0x0007F);
			}
			for (int i = 0; i < b2.Length; i++)
			{
				b2[i] = (byte) (i & 0x0003F);
			}
			long n = 0;
			Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
			while (n <= MAX_VALUE - b1.Length)
			{
				out_Renamed.WriteBytes(b1, 0, b1.Length);
				out_Renamed.Flush();
				n += b1.Length;
				Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
			}
			//System.out.println("after writing b1's, length = "+out.length()+" (MAX_VALUE="+MAX_VALUE+")");
			int m = b2.Length;
			long L = 12;
			for (int j = 0; j < L; j++)
			{
				for (int i = 0; i < b2.Length; i++)
				{
					b2[i]++;
				}
				out_Renamed.WriteBytes(b2, 0, m);
				out_Renamed.Flush();
				n += m;
				Assert.AreEqual(n, out_Renamed.Length(), "output length must match");
			}
			out_Renamed.Close();
			// input part
			RAMInputStream in_Renamed = RAMInputStream.RAMInputStream_ForNUnitTest(f);
			Assert.AreEqual(n, in_Renamed.Length(), "input length must match");
			//System.out.println("input length = "+in.length()+" % 1024 = "+in.length()%1024);
			for (int j = 0; j < L; j++)
			{
				long loc = n - (L - j) * m;
				in_Renamed.Seek(loc / 3);
				in_Renamed.Seek(loc);
				for (int i = 0; i < m; i++)
				{
					byte bt = in_Renamed.ReadByte();
					byte expected = (byte) (1 + j + (i & 0x0003F));
					Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
				}
			}
		}
示例#4
0
 public virtual void TestHugeFile()
 {
     var f = new DenseRAMFile();
     // output part
     var @out = new RAMOutputStream(f);
     var b1 = new byte[RAMOutputStream.BUFFER_SIZE];
     var b2 = new byte[RAMOutputStream.BUFFER_SIZE / 3];
     for (int i = 0; i < b1.Length; i++)
     {
         b1[i] = (byte)(sbyte)(i & 0x0007F);
     }
     for (int i = 0; i < b2.Length; i++)
     {
         b2[i] = (byte)(sbyte)(i & 0x0003F);
     }
     long n = 0;
     Assert.AreEqual(n, @out.Length, "output length must match");
     while (n <= MAX_VALUE - b1.Length)
     {
         @out.WriteBytes(b1, 0, b1.Length);
         @out.Flush();
         n += b1.Length;
         Assert.AreEqual(n, @out.Length, "output length must match");
     }
     //System.out.println("after writing b1's, length = "+out.Length()+" (MAX_VALUE="+MAX_VALUE+")");
     int m = b2.Length;
     long L = 12;
     for (int j = 0; j < L; j++)
     {
         for (int i = 0; i < b2.Length; i++)
         {
             b2[i]++;
         }
         @out.WriteBytes(b2, 0, m);
         @out.Flush();
         n += m;
         Assert.AreEqual(n, @out.Length, "output length must match");
     }
     @out.Dispose();
     // input part
     var @in = new RAMInputStream("testcase", f);
     Assert.AreEqual(n, @in.Length(), "input length must match");
     //System.out.println("input length = "+in.Length()+" % 1024 = "+in.Length()%1024);
     for (int j = 0; j < L; j++)
     {
         long loc = n - (L - j) * m;
         @in.Seek(loc / 3);
         @in.Seek(loc);
         for (int i = 0; i < m; i++)
         {
             var bt = (sbyte)@in.ReadByte();
             var expected = (sbyte)(1 + j + (i & 0x0003F));
             Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
         }
     }
 }
示例#5
0
 // Writes the contents of buffer into the fields stream
 // and adds a new entry for this document into the index
 // stream.  This assumes the buffer was already written
 // in the correct fields format.
 internal void  FlushDocument(int numStoredFields, RAMOutputStream buffer)
 {
     indexStream.WriteLong(fieldsStream.FilePointer);
     fieldsStream.WriteVInt(numStoredFields);
     buffer.WriteTo(fieldsStream);
 }
示例#6
0
 private void  InitBlock(StoredFieldsWriter enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
     buffer = enclosingInstance.docWriter.NewPerDocBuffer();
     fdt    = new RAMOutputStream(buffer);
 }
示例#7
0
 private void  InitBlock(TermVectorsTermsWriter enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
     buffer    = enclosingInstance.docWriter.NewPerDocBuffer();
     perDocTvf = new RAMOutputStream(buffer);
 }
 internal SortingDocsAndPositionsEnum(int maxDoc, SortingDocsAndPositionsEnum reuse, DocsAndPositionsEnum @in, Sorter.DocMap docMap, bool storeOffsets)
     : base(@in)
 {
     this.maxDoc = maxDoc;
     this.storeOffsets = storeOffsets;
     if (reuse != null)
     {
         docs = reuse.docs;
         offsets = reuse.offsets;
         payload = reuse.payload;
         file = reuse.file;
         if (reuse.maxDoc == maxDoc)
         {
             sorter = reuse.sorter;
         }
         else
         {
             sorter = new DocOffsetSorter(maxDoc);
         }
     }
     else
     {
         docs = new int[32];
         offsets = new long[32];
         payload = new BytesRef(32);
         file = new RAMFile();
         sorter = new DocOffsetSorter(maxDoc);
     }
     using (IndexOutput @out = new RAMOutputStream(file))
     {
         int doc;
         int i = 0;
         while ((doc = @in.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
         {
             if (i == docs.Length)
             {
                 int newLength = ArrayUtil.Oversize(i + 1, 4);
                 docs = Arrays.CopyOf(docs, newLength);
                 offsets = Arrays.CopyOf(offsets, newLength);
             }
             docs[i] = docMap.OldToNew(doc);
             offsets[i] = @out.FilePointer;
             AddPositions(@in, @out);
             i++;
         }
         upto = i;
         sorter.Reset(docs, offsets);
         sorter.Sort(0, upto);
     }
     this.postingInput = new RAMInputStream("", file);
 }