Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failToLockSameFolderAcrossIndependentLockers() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailToLockSameFolderAcrossIndependentLockers()
        {
            StoreLayout storeLayout = TestDirectory.storeLayout();

            using (GlobalStoreLocker storeLocker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
            {
                storeLocker.CheckLock();

                try
                {
                    using (GlobalStoreLocker locker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
                    {
                        locker.CheckLock();
                        fail("directory should be locked");
                    }
                }
                catch (StoreLockException)
                {
                    // expected
                }

                try
                {
                    using (GlobalStoreLocker locker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
                    {
                        locker.CheckLock();
                        fail("directory should be locked");
                    }
                }
                catch (StoreLockException)
                {
                    // expected
                }
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allowToLockSameDirectoryIfItWasUnlocked() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AllowToLockSameDirectoryIfItWasUnlocked()
        {
            StoreLayout storeLayout = TestDirectory.storeLayout();

            using (GlobalStoreLocker storeLocker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
            {
                storeLocker.CheckLock();
            }
            using (GlobalStoreLocker storeLocker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
            {
                storeLocker.CheckLock();
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allowMultipleCallstoActuallyStoreLocker() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AllowMultipleCallstoActuallyStoreLocker()
        {
            StoreLayout storeLayout = TestDirectory.storeLayout();

            using (GlobalStoreLocker storeLocker = new GlobalStoreLocker(FileSystemRule.get(), storeLayout))
            {
                storeLocker.CheckLock();
                storeLocker.CheckLock();
                storeLocker.CheckLock();
                storeLocker.CheckLock();
                storeLocker.CheckLock();
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRespectTheStoreLock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRespectTheStoreLock()
        {
            Path databaseDirectory = _homeDir.resolve("data/databases/foo.db");

            Files.createDirectories(databaseDirectory);
            StoreLayout storeLayout = DatabaseLayout.of(databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker locker = new StoreLocker(fileSystem, storeLayout))
            {
                locker.CheckLock();
                CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db", "--force"));
                assertEquals("the database is in use -- stop Neo4j and try again", commandFailed.Message);
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testFailsOnExistingStoreLockFile() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestFailsOnExistingStoreLockFile()
        {
            // Given
            StoreLayout storeLayout = _testDirectory.storeLayout();

            using (FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction(), StoreLocker @lock = new StoreLocker(fileSystemAbstraction, storeLayout))
            {
                @lock.CheckLock();

                // Then
                _expected.expect(typeof(StoreLockException));
                _expected.expectMessage("Unable to obtain lock on store lock file");
                // When
                BatchInserters.inserter(storeLayout.DatabaseLayout("any").databaseDirectory(), fileSystemAbstraction);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create store lock checker with lock on a provided store layout if it exists and writable </summary>
        /// <param name="storeLayout"> store layout to check </param>
        /// <returns> lock checker or empty closeable in case if path does not exists or is not writable </returns>
        /// <exception cref="CannotWriteException">
        /// </exception>
        /// <seealso cref= StoreLocker </seealso>
        /// <seealso cref= Files </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static java.io.Closeable check(org.neo4j.io.layout.StoreLayout storeLayout) throws CannotWriteException
        internal static System.IDisposable Check(StoreLayout storeLayout)
        {
            Path lockFile = storeLayout.StoreLockFile().toPath();

            if (Files.exists(lockFile))
            {
                if (Files.isWritable(lockFile))
                {
                    StoreLockChecker storeLocker = new StoreLockChecker(new DefaultFileSystemAbstraction(), storeLayout);
                    try
                    {
                        storeLocker.CheckLock();
                        return(storeLocker);
                    }
                    catch (StoreLockException le)
                    {
                        try
                        {
                            storeLocker.Dispose();
                        }
                        catch (IOException e)
                        {
                            le.addSuppressed(e);
                        }
                        throw le;
                    }
                }
                else
                {
                    throw new CannotWriteException(lockFile);
                }
            }
            return(() =>
            {
            });
        }
Esempio n. 7
0
 private StoreLockChecker(FileSystemAbstraction fileSystem, StoreLayout storeLayout)
 {
     this._fileSystem  = fileSystem;
     this._storeLocker = new GlobalStoreLocker(fileSystem, storeLayout);
 }