protected void Wait(bool _throw) { if (WriterThread != null) { WriterThread.Join(); if (WriterException != null) { Exception ex = WriterException; WriterException = null; if (_throw) { throw new AggregateException(ex); } } } }
public virtual void TestIsCurrentWithThreads() { Directory dir = NewDirectory(); IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)); IndexWriter writer = new IndexWriter(dir, conf); ReaderHolder holder = new ReaderHolder(); ReaderThread[] threads = new ReaderThread[AtLeast(3)]; CountdownEvent latch = new CountdownEvent(1); WriterThread writerThread = new WriterThread(holder, writer, AtLeast(500), Random, latch); for (int i = 0; i < threads.Length; i++) { threads[i] = new ReaderThread(holder, latch); threads[i].Start(); } writerThread.Start(); writerThread.Join(); bool failed = writerThread.failed != null; if (failed) { Console.WriteLine(writerThread.failed.ToString()); Console.Write(writerThread.failed.StackTrace); } for (int i = 0; i < threads.Length; i++) { threads[i].Join(); if (threads[i].failed != null) { Console.WriteLine(threads[i].failed.ToString()); Console.Write(threads[i].failed.StackTrace); failed = true; } } Assert.IsFalse(failed); writer.Dispose(); dir.Dispose(); }
public virtual void TestIsCurrentWithThreads() { Directory dir = NewDirectory(); IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())); IndexWriter writer = new IndexWriter(dir, conf); ReaderHolder holder = new ReaderHolder(); ReaderThread[] threads = new ReaderThread[AtLeast(3)]; CountdownEvent latch = new CountdownEvent(1); WriterThread writerThread = new WriterThread(holder, writer, AtLeast(500), Random(), latch); for (int i = 0; i < threads.Length; i++) { threads[i] = new ReaderThread(holder, latch); threads[i].Start(); } writerThread.Start(); writerThread.Join(); bool failed = writerThread.Failed != null; if (failed) { Console.WriteLine(writerThread.Failed.ToString()); Console.Write(writerThread.Failed.StackTrace); } for (int i = 0; i < threads.Length; i++) { threads[i].Join(); if (threads[i].Failed != null) { Console.WriteLine(threads[i].Failed.ToString()); Console.Write(threads[i].Failed.StackTrace); failed = true; } } Assert.IsFalse(failed); writer.Dispose(); dir.Dispose(); }
protected override void ExecuteConcrete() { #region Extension of the compressed file try { var extension = Path.GetExtension(destination); if (!extension.Equals(".gz", StringComparison.CurrentCultureIgnoreCase)) { destination += ".gz"; } } catch { Console.WriteLine("Resulting file name contrains invalid characters."); return; } #endregion #region Checking and re-writing existing file try { if (File.Exists(destination)) { Console.WriteLine($"The file {destination} already exists. Rewrite it? y/n"); var answer = Console.ReadLine(); if (!answer.Equals("y", StringComparison.CurrentCultureIgnoreCase)) { return; } else { try { File.Delete(destination); } catch (UnauthorizedAccessException) { Console.WriteLine("You have no rights to overwrite the file, or this file is in use by another app."); return; } catch (IOException) { Console.WriteLine("The file is in use by another app, so it is unable to overwrite it."); return; } catch { Console.WriteLine("Unable to overwrite this file. Probably you've set an invalid file name."); return; } } } } catch { Console.WriteLine("Unknown error. Please try set another resulting file name."); } #endregion var numberOfCompressorThreads = Environment.ProcessorCount; var sharedStateAfterReadFile = ReaderCompressorSharedState.Create(numberOfCompressorThreads, c_readFileChunkSize); var sharedStateAfterCompression = CompressorWriterSharedState.Create(numberOfCompressorThreads, numberOfCompressorThreads * 2); var reader = new ReaderThread(source, c_readFileChunkSize, (IForReaderThread)sharedStateAfterReadFile); var compressors = Enumerable .Range(0, numberOfCompressorThreads) .Select(x => new CompressorThread(c_readFileChunkSize, (IForCompressorThreadInput)sharedStateAfterReadFile, (IForCompressorThreadOutput)sharedStateAfterCompression)) .ToList(); var writer = new WriterThread(destination, c_readFileChunkSize, (IForWriterThread)sharedStateAfterCompression); //Console.WriteLine("Press 'c' to cancel."); //if (Console.ReadKey(true).KeyChar == 'c') //{ // sharedStateAfterReadFile.Cancel(); //} reader.Join(); compressors.ForEach(x => x.Join()); writer.Join(); Console.WriteLine("Finished. Press enter to exit."); Console.ReadLine(); }