Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverIfCrashedDuringMove() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverIfCrashedDuringMove()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.IOException exception = new java.io.IOException("simulated IO Exception on create");
            IOException           exception          = new IOException("simulated IO Exception on create");
            FileSystemAbstraction crashingFileSystem = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fs, exception);

            FileUserRepository users = new FileUserRepository(crashingFileSystem, _authFile, _logProvider);

            users.Start();
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            // When
            try
            {
                users.Create(user);
                fail("Expected an IOException");
            }
            catch (IOException e)
            {
                assertSame(exception, e);
            }

            // Then
            assertFalse(crashingFileSystem.FileExists(_authFile));
            assertThat(crashingFileSystem.ListFiles(_authFile.ParentFile).Length, equalTo(0));
        }
Пример #2
0
//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]);
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverIfCrashedDuringMove() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverIfCrashedDuringMove()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.IOException exception = new java.io.IOException("simulated IO Exception on create");
            IOException           exception          = new IOException("simulated IO Exception on create");
            FileSystemAbstraction crashingFileSystem = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fs, exception);

            _roleRepository = new FileRoleRepository(crashingFileSystem, _roleFile, _logProvider);
            _roleRepository.start();
            RoleRecord role = new RoleRecord("admin", "jake");

            // When
            try
            {
                _roleRepository.create(role);
                fail("Expected an IOException");
            }
            catch (IOException e)
            {
                assertSame(exception, e);
            }

            // Then
            assertFalse(crashingFileSystem.FileExists(_roleFile));
            assertThat(crashingFileSystem.ListFiles(_roleFile.ParentFile).Length, equalTo(0));
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustUnblockPageFaultersWhenEvictionGetsException()
        internal virtual void MustUnblockPageFaultersWhenEvictionGetsException()
        {
            assertTimeout(ofMillis(SEMI_LONG_TIMEOUT_MILLIS), () =>
            {
                WriteInitialDataTo(file("a"));

                MutableBoolean throwException = new MutableBoolean(true);
                FileSystemAbstraction fs      = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, this.fs, throwException);

                using (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL), PagedFile pagedFile = map(pageCache, file("a"), 8))
                {
                    // The basic idea is that this loop, which will encounter a lot of page faults, must not block forever even
                    // though the eviction thread is unable to flush any dirty pages because the file system throws
                    // exceptions on all writes.
                    try
                    {
                        using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                        {
                            for (int i = 0; i < 1000; i++)
                            {
                                assertTrue(cursor.Next());
                            }
                            fail("Expected an exception at this point");
                        }
                    }
                    catch (IOException)
                    {
                        // Good.
                    }

                    throwException.setFalse();
                }
            });
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldObtainLockWhenStoreFileNotLocked() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldObtainLockWhenStoreFileNotLocked()
        {
            FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, FileSystemRule.get());

            try
            {
                using (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction, Target.storeLayout()))
                {
                    storeLocker.CheckLock();

                    // Ok
                }
            }
            catch (StoreLockException)
            {
                fail();
            }
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseStoreFileOnFailureToOpen()
        public virtual void ShouldCloseStoreFileOnFailureToOpen()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableBoolean fired = new org.apache.commons.lang3.mutable.MutableBoolean();
            MutableBoolean        fired = new MutableBoolean();
            FileSystemAbstraction fs    = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _efs.get(), fired);

            // WHEN
            try
            {
                using (PageCache pageCache = PageCacheRule.getPageCache(fs))
                {
                    NewNodeStore(fs);
                    fail("Should fail");
                }
            }               // Close the page cache here so that we can see failure to close (due to still mapped files)
            catch (Exception e)
            {
                // THEN
                assertTrue(contains(e, typeof(IOException)));
                assertTrue(fired.booleanValue());
            }
        }
Пример #7
0
 public DelegatingStoreChannelAnonymousInnerClass(DelegatingFileSystemAbstractionAnonymousInnerClass outerInstance, UnknownType open) : base(open)
 {
     this.outerInstance = outerInstance;
 }