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 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]); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldSurviveFilesystemErrors() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldSurviveFilesystemErrors() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.adversaries.RandomAdversary adversary = new org.neo4j.adversaries.RandomAdversary(0.1, 0.1, 0); RandomAdversary adversary = new RandomAdversary(0.1, 0.1, 0); adversary.ProbabilityFactor = 0; AdversarialFileSystemAbstraction adversarialFileSystem = new SensibleAdversarialFileSystemAbstraction(adversary, _fileSystem); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(adversarialFileSystem, _logFile, 1000, 0, 9, _directExecutor); adversary.ProbabilityFactor = 1; WriteLines(supplier, 10000); // run cleanly for a while, to allow it to fill any gaps left in log archive numbers adversary.ProbabilityFactor = 0; WriteLines(supplier, 10000); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile3), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile4), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile5), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile6), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile7), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile8), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile9), @is(true)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotRotateLogWhenSizeExceededButNotDelay() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotRotateLogWhenSizeExceededButNotDelay() { UpdatableLongSupplier clock = new UpdatableLongSupplier(DateTimeHelper.CurrentUnixTimeMillis()); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(clock, _fileSystem, _logFile, 10, SECONDS.toMillis(60), 10, _directExecutor, new RotationListener()); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(false)); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(false)); Write(supplier, "A string longer than 10 bytes"); clock.Value = clock.AsLong + SECONDS.toMillis(59); Write(supplier, "A string longer than 10 bytes"); clock.Value = clock.AsLong + SECONDS.toMillis(1); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile3), @is(false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotifyListenerWhenNewLogIsCreated() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotifyListenerWhenNewLogIsCreated() { //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); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch rotationComplete = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent rotationComplete = new System.Threading.CountdownEvent(1); string outputFileCreatedMessage = "Output file created"; string rotationCompleteMessage = "Rotation complete"; RotationListener rotationListener = spy(new RotationListenerAnonymousInnerClass(this, allowRotationComplete, rotationComplete, outputFileCreatedMessage, rotationCompleteMessage)); ExecutorService rotationExecutor = Executors.newSingleThreadExecutor(); try { RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(_fileSystem, _logFile, 10, 0, 10, rotationExecutor, rotationListener); Write(supplier, "A string longer than 10 bytes"); Write(supplier, "A string longer than 10 bytes"); allowRotationComplete.Signal(); rotationComplete.await(1L, TimeUnit.SECONDS); verify(rotationListener).outputFileCreated(any(typeof(Stream))); verify(rotationListener).rotationCompleted(any(typeof(Stream))); } finally { ShutDownExecutor(rotationExecutor); } }
//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()); }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void limitsNumberOfArchivedLogs() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void LimitsNumberOfArchivedLogs() { RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(_fileSystem, _logFile, 10, 0, 2, _directExecutor); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(false)); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(false)); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile3), @is(false)); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile3), @is(false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCloseAllOutputStreams() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldCloseAllOutputStreams() { //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 DelegatingFileSystemAbstractionAnonymousInnerClass2(this, _fileSystem, mockStreams); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, _logFile, 10, 0, 10, _directExecutor); Write(supplier, "A string longer than 10 bytes"); supplier.Dispose(); AssertStreamClosed(mockStreams[0]); }
//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 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 shouldFindAllArchives() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldFindAllArchives() { RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(_fileSystem, _logFile, 10, 0, 2, _directExecutor); Write(supplier, "A string longer than 10 bytes"); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(false)); IList <File> allArchives = getAllArchives(_fileSystem, _logFile); assertThat(allArchives.Count, @is(1)); assertThat(allArchives, hasItem(_archiveLogFile1)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCloseAllStreamsDespiteError() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldCloseAllStreamsDespiteError() { //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 DelegatingFileSystemAbstractionAnonymousInnerClass3(this, _fileSystem, mockStreams); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, _logFile, 10, 0, 10, _directExecutor); Write(supplier, "A string longer than 10 bytes"); Write(supplier, "A string longer than 10 bytes"); IOException exception = new IOException("test exception"); Stream mockStream = mockStreams[1]; doThrow(exception).when(mockStream).close(); IOException ioException = assertThrows(typeof(IOException), supplier.close); assertThat(ioException, sameInstance(exception)); verify(mockStream).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void rotatesLogWhenSizeExceeded() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void RotatesLogWhenSizeExceeded() { RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(_fileSystem, _logFile, 10, 0, 10, _directExecutor); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(false)); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(false)); Write(supplier, "Short"); Write(supplier, "A string longer than 10 bytes"); assertThat(_fileSystem.fileExists(_logFile), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile1), @is(true)); assertThat(_fileSystem.fileExists(_archiveLogFile2), @is(true)); }
public OutputStreamAnonymousInnerClass(RotatingFileOutputStreamSupplier outerInstance) { this.outerInstance = outerInstance; }