1010using System . Linq ;
1111using System . Text ;
1212using System . Threading ;
13+ using System . Threading . Tasks ;
1314using Assert = Lucene . Net . TestFramework . Assert ;
1415
1516namespace Lucene . Net . Store
@@ -31,19 +32,19 @@ namespace Lucene.Net.Store
3132 * limitations under the License.
3233 */
3334
34- using BytesRef = Lucene . Net . Util . BytesRef ;
35- using Document = Documents . Document ;
35+ using BytesRef = Util . BytesRef ;
36+ using Document = Document ;
3637 using Field = Field ;
37- using IndexInputSlicer = Lucene . Net . Store . Directory . IndexInputSlicer ;
38- using IndexReader = Lucene . Net . Index . IndexReader ;
39- using LuceneTestCase = Lucene . Net . Util . LuceneTestCase ;
40- using MockAnalyzer = Lucene . Net . Analysis . MockAnalyzer ;
41- using RandomIndexWriter = Lucene . Net . Index . RandomIndexWriter ;
42- using TestUtil = Lucene . Net . Util . TestUtil ;
38+ using IndexInputSlicer = Directory . IndexInputSlicer ;
39+ using IndexReader = Index . IndexReader ;
40+ using LuceneTestCase = Util . LuceneTestCase ;
41+ using MockAnalyzer = Analysis . MockAnalyzer ;
42+ using RandomIndexWriter = Index . RandomIndexWriter ;
43+ using TestUtil = Util . TestUtil ;
4344
4445 /// <summary>
4546 /// Tests MMapDirectory's MultiMMapIndexInput
46- /// <p >
47+ /// <para/ >
4748 /// Because Java's ByteBuffer uses an int to address the
4849 /// values, it's necessary to access a file >
4950 /// Integer.MAX_VALUE in size using multiple byte buffers.
@@ -558,10 +559,12 @@ public void TestConcurrentCloneReadVsDispose_Issue1013()
558559
559560 const string name = "bytes" ;
560561 const int fileSize = 1 << 20 ; // 1 MiB
561- using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( Random ) ) )
562+ var random = Random ;
563+
564+ using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( random ) ) )
562565 {
563566 var buf = new byte [ 4096 ] ;
564- new Random ( 42 ) . NextBytes ( buf ) ;
567+ random . NextBytes ( buf ) ;
565568 for ( int written = 0 ; written < fileSize ; written += buf . Length )
566569 {
567570 io . WriteBytes ( buf , 0 , buf . Length ) ;
@@ -580,7 +583,7 @@ public void TestConcurrentCloneReadVsDispose_Issue1013()
580583 {
581584 iteration ++ ;
582585
583- var master = mmapDir . OpenInput ( name , NewIOContext ( Random ) ) ;
586+ var master = mmapDir . OpenInput ( name , NewIOContext ( random ) ) ;
584587 var start = new ManualResetEventSlim ( false ) ;
585588 var threads = new Thread [ readerThreads ] ;
586589 long totalReads = 0 ;
@@ -630,7 +633,7 @@ public void TestConcurrentCloneReadVsDispose_Issue1013()
630633
631634 start . Set ( ) ;
632635
633- Thread . Sleep ( Random . Next ( 1 , 5 ) ) ;
636+ Thread . Sleep ( random . Next ( 1 , 5 ) ) ;
634637 master . Dispose ( ) ;
635638
636639 // Join every reader. The View's drain barrier ensures Dispose
@@ -699,10 +702,11 @@ public void TestConcurrentCloneVsDispose_RaceScenario()
699702 using var mmapDir = new MMapDirectory ( dirPath ) ;
700703 const string name = "bytes" ;
701704 const int fileSize = 64 * 1024 ;
702- using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( Random ) ) )
705+ var random = Random ;
706+ using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( random ) ) )
703707 {
704708 var buf = new byte [ 4096 ] ;
705- new Random ( 7 ) . NextBytes ( buf ) ;
709+ random . NextBytes ( buf ) ;
706710 for ( int w = 0 ; w < fileSize ; w += buf . Length )
707711 io . WriteBytes ( buf , 0 , buf . Length ) ;
708712 }
@@ -713,7 +717,7 @@ public void TestConcurrentCloneVsDispose_RaceScenario()
713717 while ( sw . Elapsed < TimeSpan . FromSeconds ( 15 ) )
714718 {
715719 iterations ++ ;
716- var master = mmapDir . OpenInput ( name , NewIOContext ( Random ) ) ;
720+ var master = mmapDir . OpenInput ( name , NewIOContext ( random ) ) ;
717721 var start = new ManualResetEventSlim ( false ) ;
718722 var cloners = new Thread [ 6 ] ;
719723 for ( int i = 0 ; i < cloners . Length ; i ++ )
@@ -738,7 +742,7 @@ public void TestConcurrentCloneVsDispose_RaceScenario()
738742 cloners [ i ] . Start ( ) ;
739743 }
740744 start . Set ( ) ;
741- Thread . Sleep ( Random . Next ( 0 , 3 ) ) ;
745+ Thread . Sleep ( random . Next ( 0 , 3 ) ) ;
742746 master . Dispose ( ) ;
743747 foreach ( var t in cloners )
744748 {
@@ -792,10 +796,11 @@ public void TestConcurrentReadVsSelfDispose_RaceScenario()
792796 using var mmapDir = new MMapDirectory ( dirPath ) ;
793797 const string name = "bytes" ;
794798 const int fileSize = 1 << 18 ; // 256 KiB — enough for several buffer refills
795- using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( Random ) ) )
799+ var random = Random ;
800+ using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( random ) ) )
796801 {
797802 var buf = new byte [ 4096 ] ;
798- new Random ( 11 ) . NextBytes ( buf ) ;
803+ random . NextBytes ( buf ) ;
799804 for ( int w = 0 ; w < fileSize ; w += buf . Length )
800805 io . WriteBytes ( buf , 0 , buf . Length ) ;
801806 }
@@ -806,7 +811,7 @@ public void TestConcurrentReadVsSelfDispose_RaceScenario()
806811 while ( sw . Elapsed < TimeSpan . FromSeconds ( 15 ) && unexpected . IsEmpty )
807812 {
808813 iterations ++ ;
809- var input = mmapDir . OpenInput ( name , NewIOContext ( Random ) ) ;
814+ var input = mmapDir . OpenInput ( name , NewIOContext ( random ) ) ;
810815 var start = new ManualResetEventSlim ( false ) ;
811816 var readers = new Thread [ 4 ] ;
812817 for ( int i = 0 ; i < readers . Length ; i ++ )
@@ -839,7 +844,7 @@ public void TestConcurrentReadVsSelfDispose_RaceScenario()
839844 readers [ i ] . Start ( ) ;
840845 }
841846 start . Set ( ) ;
842- Thread . Sleep ( Random . Next ( 1 , 5 ) ) ;
847+ Thread . Sleep ( random . Next ( 1 , 5 ) ) ;
843848 input . Dispose ( ) ;
844849 foreach ( var t in readers ) t . Join ( TimeSpan . FromSeconds ( 5 ) ) ;
845850 }
@@ -863,10 +868,11 @@ public void TestConcurrentSliceReadVsSlicerDispose_RaceScenario()
863868 using var mmapDir = new MMapDirectory ( dirPath ) ;
864869 const string name = "bytes" ;
865870 const int fileSize = 1 << 18 ;
866- using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( Random ) ) )
871+ var random = Random ;
872+ using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( random ) ) )
867873 {
868874 var buf = new byte [ 4096 ] ;
869- new Random ( 13 ) . NextBytes ( buf ) ;
875+ random . NextBytes ( buf ) ;
870876 for ( int w = 0 ; w < fileSize ; w += buf . Length )
871877 io . WriteBytes ( buf , 0 , buf . Length ) ;
872878 }
@@ -877,7 +883,7 @@ public void TestConcurrentSliceReadVsSlicerDispose_RaceScenario()
877883 while ( sw . Elapsed < TimeSpan . FromSeconds ( 15 ) && unexpected . IsEmpty )
878884 {
879885 iterations ++ ;
880- var slicer = mmapDir . CreateSlicer ( name , NewIOContext ( Random ) ) ;
886+ var slicer = mmapDir . CreateSlicer ( name , NewIOContext ( random ) ) ;
881887 var start = new ManualResetEventSlim ( false ) ;
882888 var readers = new Thread [ 4 ] ;
883889 for ( int i = 0 ; i < readers . Length ; i ++ )
@@ -908,7 +914,7 @@ public void TestConcurrentSliceReadVsSlicerDispose_RaceScenario()
908914 readers [ i ] . Start ( ) ;
909915 }
910916 start . Set ( ) ;
911- Thread . Sleep ( Random . Next ( 1 , 5 ) ) ;
917+ Thread . Sleep ( random . Next ( 1 , 5 ) ) ;
912918 slicer . Dispose ( ) ;
913919 foreach ( var t in readers ) t . Join ( TimeSpan . FromSeconds ( 5 ) ) ;
914920 }
@@ -1142,14 +1148,14 @@ public void TestMultipleSlicesReadDistinctData()
11421148 // its own slice fully and asserts the pattern. If the slices
11431149 // were accidentally aliased to the same underlying view,
11441150 // racing Seek() calls would cross-contaminate.
1145- var errors = new System . Collections . Concurrent . ConcurrentBag < string > ( ) ;
1146- var tasks = new System . Threading . Tasks . Task [ regions ] ;
1151+ var errors = new ConcurrentBag < string > ( ) ;
1152+ var tasks = new Task [ regions ] ;
11471153 for ( int r = 0 ; r < regions ; r ++ )
11481154 {
11491155 int idx = r ;
11501156 byte expected = ( byte ) ( 0x11 * ( idx + 1 ) ) ;
11511157 var clone = ( IndexInput ) slices [ idx ] . Clone ( ) ;
1152- tasks [ idx ] = System . Threading . Tasks . Task . Run ( ( ) =>
1158+ tasks [ idx ] = Task . Run ( ( ) =>
11531159 {
11541160 for ( int pass = 0 ; pass < 50 ; pass ++ )
11551161 {
@@ -1166,7 +1172,7 @@ public void TestMultipleSlicesReadDistinctData()
11661172 }
11671173 } ) ;
11681174 }
1169- System . Threading . Tasks . Task . WaitAll ( tasks ) ;
1175+ Task . WaitAll ( tasks ) ;
11701176 if ( ! errors . IsEmpty )
11711177 {
11721178 Assert . Fail ( "Cross-slice contamination detected:\n " + string . Join ( "\n " , errors ) ) ;
@@ -1233,15 +1239,16 @@ public void TestConcurrentClonesReadIdenticalBytes()
12331239 // enough that the test finishes in well under a second per
12341240 // iteration.
12351241 const int fileSize = 2 * 1024 * 1024 ;
1242+ var random = Random ;
12361243 var expected = new byte [ fileSize ] ;
1237- new Random ( 0xC0FFEE ) . NextBytes ( expected ) ;
1244+ random . NextBytes ( expected ) ;
12381245
1239- using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( Random ) ) )
1246+ using ( var io = mmapDir . CreateOutput ( name , NewIOContext ( random ) ) )
12401247 {
12411248 io . WriteBytes ( expected , 0 , expected . Length ) ;
12421249 }
12431250
1244- using var root = mmapDir . OpenInput ( name , NewIOContext ( Random ) ) ;
1251+ using var root = mmapDir . OpenInput ( name , NewIOContext ( random ) ) ;
12451252
12461253 const int numWorkers = 8 ;
12471254 const int passesPerWorker = 20 ;
0 commit comments