//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBeConsistentAfterConcurrentWritesAndForces() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldBeConsistentAfterConcurrentWritesAndForces() { ExecutorService executorService = Executors.newCachedThreadPool(); try { for (int attempt = 0; attempt < 100; attempt++) { using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) { File aFile = new File("contendedFile"); ICollection <Callable <Void> > workers = new List <Callable <Void> >(); for (int i = 0; i < 100; i++) { workers.Add(() => { try { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.position(channel.size()); WriteLong(channel, 1); } catch (IOException e) { throw new Exception(e); } return(null); }); workers.Add(() => { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.force(true); return(null); }); } IList <Future <Void> > futures = executorService.invokeAll(workers); foreach (Future <Void> future in futures) { future.get(); } fs.Crash(); VerifyFileIsFullOfLongIntegerOnes(fs.Open(aFile, OpenMode.READ_WRITE)); } } } finally { executorService.shutdown(); } }
/* * Writes both freeIds and readFromDisk lists to disk and truncates the channel to size. * It forces but does not close the channel. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void close() throws java.io.IOException public override void Close() { ByteBuffer writeBuffer = ByteBuffer.allocate(_batchSize * _idEntrySize); FlushFreeIds(writeBuffer); _freeIds.addAll(_readFromDisk); FlushFreeIds(writeBuffer); if (!_aggressiveMode) { Compact(writeBuffer); } _channel.force(false); }