//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotUpdateOutputStreamWhenClosedDuringRotation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotUpdateOutputStreamWhenClosedDuringRotation() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch allowRotationComplete = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent allowRotationComplete = new System.Threading.CountdownEvent(1); RotationListener rotationListener = spy(new RotationListenerAnonymousInnerClass2(this, allowRotationComplete)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<java.io.OutputStream> mockStreams = new java.util.ArrayList<>(); IList <Stream> mockStreams = new List <Stream>(); FileSystemAbstraction fs = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fileSystem, mockStreams); ExecutorService rotationExecutor = Executors.newSingleThreadExecutor(); try { RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, _logFile, 10, 0, 10, rotationExecutor, rotationListener); Stream outputStream = supplier.Get(); Write(supplier, "A string longer than 10 bytes"); assertThat(supplier.Get(), @is(outputStream)); allowRotationComplete.Signal(); supplier.Dispose(); } finally { ShutDownExecutor(rotationExecutor); } AssertStreamClosed(mockStreams[0]); }
private void Write(RotatingFileOutputStreamSupplier supplier, string line) { PrintWriter writer = new PrintWriter(supplier.Get()); writer.println(line); writer.flush(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotifyListenerOnRotationErrorDuringJobExecution() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotifyListenerOnRotationErrorDuringJobExecution() { RotationListener rotationListener = mock(typeof(RotationListener)); Executor executor = mock(typeof(Executor)); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(_fileSystem, _logFile, 10, 0, 10, executor, rotationListener); Stream outputStream = supplier.Get(); RejectedExecutionException exception = new RejectedExecutionException("text exception"); doThrow(exception).when(executor).execute(any(typeof(ThreadStart))); Write(supplier, "A string longer than 10 bytes"); assertThat(supplier.Get(), @is(outputStream)); verify(rotationListener).rotationError(exception, outputStream); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotifyListenerOnRotationErrorDuringRotationIO() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotifyListenerOnRotationErrorDuringRotationIO() { RotationListener rotationListener = mock(typeof(RotationListener)); FileSystemAbstraction fs = spy(_fileSystem); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, _logFile, 10, 0, 10, _directExecutor, rotationListener); Stream outputStream = supplier.Get(); IOException exception = new IOException("text exception"); doThrow(exception).when(fs).renameFile(any(typeof(File)), any(typeof(File))); Write(supplier, "A string longer than 10 bytes"); assertThat(supplier.Get(), @is(outputStream)); verify(rotationListener).rotationError(eq(exception), any(typeof(Stream))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void rotationShouldNotDeadlockOnListener() internal virtual void RotationShouldNotDeadlockOnListener() { assertTimeout(ofMillis(TEST_TIMEOUT_MILLIS), () => { string logContent = "Output file created"; AtomicReference <Exception> listenerException = new AtomicReference <Exception>(null); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); RotationListener listener = new RotationListenerAnonymousInnerClass(this, listenerException, latch); ExecutorService executor = Executors.newSingleThreadExecutor(); DefaultFileSystemAbstraction defaultFileSystemAbstraction = new DefaultFileSystemAbstraction(); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(defaultFileSystemAbstraction, _logFile, 0, 0, 10, executor, listener); Stream outputStream = supplier.Get(); LockingPrintWriter lockingPrintWriter = new LockingPrintWriter(this, outputStream); lockingPrintWriter.WithLock(() => { supplier.Rotate(); latch.await(); return(Void.TYPE); }); ShutDownExecutor(executor); IList <string> strings = Files.readAllLines(_logFile.toPath()); string actual = string.join("", strings); assertEquals(logContent, actual); assertNull(listenerException.get()); }); }