Beispiel #1
0
//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();
            }
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotLoseDataForcedBeforeFileSystemCrashes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotLoseDataForcedBeforeFileSystemCrashes()
        {
            using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction())
            {
                // given
                int numberOfBytesForced = 8;

                File aFile = new File("yo");

                StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE);
                WriteLong(channel, 1111);

                // when
                channel.Force(true);
                WriteLong(channel, 2222);
                fs.Crash();

                // then
                StoreChannel readChannel = fs.Open(aFile, OpenMode.READ);
                assertEquals(numberOfBytesForced, readChannel.size());

                assertEquals(1111, ReadLong(readChannel).Long);
            }
        }