Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateTheFileIfOverwriting() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncateTheFileIfOverwriting()
        {
            // GIVEN
            IdContainer.CreateEmptyIdFile(_fs, _file, 30, false);
            IdContainer idContainer = new IdContainer(_fs, _file, 5, false);

            idContainer.Init();
            for (int i = 0; i < 17; i++)
            {
                idContainer.FreeId(i);
            }
            idContainer.Close(30);
            assertThat(( int )_fs.getFileSize(_file), greaterThan(IdContainer.HeaderSize));

            // WHEN
            IdContainer.CreateEmptyIdFile(_fs, _file, 30, false);

            // THEN
            assertEquals(IdContainer.HeaderSize, ( int )_fs.getFileSize(_file));
            assertEquals(30, IdContainer.ReadHighId(_fs, _file));
            idContainer = new IdContainer(_fs, _file, 5, false);
            idContainer.Init();
            assertEquals(30, idContainer.InitialHighId);

            idContainer.Close(30);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldForceStickyMark() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForceStickyMark()
        {
            // GIVEN
            CreateEmptyFile();

            // WHEN opening the id generator, where the jvm crashes right after
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();

            // THEN
            try
            {
                IdContainer.ReadHighId(_fs, _file);
                fail("Should have thrown, saying something with sticky generator");
            }
            catch (InvalidIdGeneratorException)
            {
                // THEN Good
            }
            finally
            {
                idContainer.Close(0);
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnInitIfTheFileWasCreated()
        public virtual void ShouldReturnFalseOnInitIfTheFileWasCreated()
        {
            // When
            // An IdContainer is created with no underlying file
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            // Then
            // Init should return false
            assertFalse(idContainer.Init());
            idContainer.Close(100);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void idContainerReadWriteBySingleByte() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IdContainerReadWriteBySingleByte()
        {
            SingleByteFileSystemAbstraction fileSystem = new SingleByteFileSystemAbstraction();
            IdContainer idContainer = new IdContainer(fileSystem, _file, 100, false);

            idContainer.Init();
            idContainer.Close(100);

            idContainer = new IdContainer(fileSystem, _file, 100, false);
            idContainer.Init();
            assertEquals(100, idContainer.InitialHighId);
            fileSystem.Dispose();
            idContainer.Close(100);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void includeFileNameIntoReadHeaderException() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IncludeFileNameIntoReadHeaderException()
        {
            CreateEmptyFile();
            _fs.truncate(_file, 0);

            try
            {
                IdContainer idContainer = new IdContainer(_fs, _file, 100, false);
                idContainer.Init();
            }
            catch (InvalidIdGeneratorException e)
            {
                assertThat(e.Message, Matchers.containsString(_file.AbsolutePath));
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeleteIfClosed()
        public virtual void ShouldDeleteIfClosed()
        {
            // GIVEN
            CreateEmptyFile();
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();
            idContainer.Close(0);

            // WHEN
            idContainer.Delete();

            // THEN
            assertFalse(_fs.fileExists(_file));
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnTrueOnInitIfAProperFileWasThere()
        public virtual void ShouldReturnTrueOnInitIfAProperFileWasThere()
        {
            // Given
            // A properly created and closed id file
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();
            idContainer.Close(100);

            // When
            // An IdContainer is created over it
            idContainer = new IdContainer(_fs, _file, 100, false);

            // Then
            // init() should return true
            assertTrue(idContainer.Init());
            idContainer.Close(100);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void constructorShouldNotCallHighIdSupplierOnCleanIdFile()
        public virtual void ConstructorShouldNotCallHighIdSupplierOnCleanIdFile()
        {
            // Given
            // A non empty, clean id file
            IdContainer.CreateEmptyIdFile(Fsr.get(), _file, 42, true);
            // and a mock supplier to test against
            System.Func <long> highId = mock(typeof(System.Func <long>));

            // When
            // An IdGenerator is created over the previous properly closed file
            IdGenerator idGenerator = new IdGeneratorImpl(Fsr.get(), _file, 100, 100, false, IdType.Node, highId);

            idGenerator.Dispose();

            // Then
            // The supplier must have remained untouched
            verifyZeroInteractions(highId);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Opens the id generator represented by <CODE>fileName</CODE>. The
        /// <CODE>grabSize</CODE> means how many defragged ids we should keep in
        /// memory and is also the size (x4) of the two buffers used for reading and
        /// writing to the id generator file. The highest returned id will be read
        /// from file and if <CODE>grabSize</CODE> number of ids exist they will be
        /// read into memory (if less exist all defragged ids will be in memory).
        /// <para>
        /// If this id generator hasn't been closed properly since the previous
        /// session (sticky) an <CODE>IOException</CODE> will be thrown. When this
        /// happens one has to rebuild the id generator from the (node/rel/prop)
        /// store file.
        ///
        /// </para>
        /// </summary>
        /// <param name="file">
        ///            The file name (and path if needed) for the id generator to be
        ///            opened </param>
        /// <param name="grabSize">
        ///            The number of defragged ids to keep in memory </param>
        /// <param name="max"> is the highest possible id to be returned by this id generator from
        /// <seealso cref="nextId()"/>. </param>
        /// <param name="aggressiveReuse"> will reuse ids during the same session, not requiring
        /// a restart to be able reuse ids freed with <seealso cref="freeId(long)"/>. </param>
        /// <param name="highId"> A supplier for the high id to be used if the id file is found to be empty or not properly shut down </param>
        /// <exception cref="UnderlyingStorageException">
        ///             If no such file exist or if the id generator is sticky </exception>
        public IdGeneratorImpl(FileSystemAbstraction fs, File file, int grabSize, long max, bool aggressiveReuse, IdType idType, System.Func <long> highId)
        {
            this._max         = max;
            this._idType      = idType;
            this._idContainer = new IdContainer(fs, file, grabSize, aggressiveReuse);

            /*
             * The highId supplier will be called only if the id container tells us that the information found in the
             * id file is not reliable (typically the file had to be created). Calling the supplier can be a potentially
             * expensive operation.
             */
            if (this._idContainer.init())
            {
                this._highId = _idContainer.InitialHighId;
            }
            else
            {
                this._highId = highId();
            }
        }
Ejemplo n.º 10
0
 private void CreateEmptyFile()
 {
     IdContainer.CreateEmptyIdFile(_fs, _file, 42, false);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Read the defragmented id count from the given id-file.
        ///
        /// Note that this method should only be used when the file is not currently in use by an IdGenerator, since this
        /// method does not take any in-memory state into account.
        /// </summary>
        /// <param name="fileSystem"> The file system to use for accessing the given file. </param>
        /// <param name="file"> The path to the id-file from which to read the defrag count. </param>
        /// <returns> The number of defragmented ids in the id-file. </returns>
        /// <exception cref="IOException"> If anything goes wrong when accessing the file, for instance if the file does not exist. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static long readDefragCount(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file) throws java.io.IOException
        public static long ReadDefragCount(FileSystemAbstraction fileSystem, File file)
        {
            return(IdContainer.ReadDefragCount(fileSystem, file));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Read the high-id count from the given id-file.
        ///
        /// Note that this method should only be used when the file is not currently in use by an IdGenerator, since this
        /// method does not take any in-memory state into account.
        /// </summary>
        /// <param name="fileSystem"> The file system to use for accessing the given file. </param>
        /// <param name="file"> The path to the id-file from which to read the high-id. </param>
        /// <returns> The high-id from the given file. </returns>
        /// <exception cref="IOException"> If anything goes wrong when accessing the file, for instance if the file does not exist. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static long readHighId(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file) throws java.io.IOException
        public static long ReadHighId(FileSystemAbstraction fileSystem, File file)
        {
            return(IdContainer.ReadHighId(fileSystem, file));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new id generator.
 /// </summary>
 /// <param name="fileName"> The name of the id generator </param>
 /// <param name="throwIfFileExists"> if {@code true} will cause an <seealso cref="UnderlyingStorageException"/> to be thrown if
 /// the file already exists. if {@code false} will truncate the file writing the header in it. </param>
 public static void CreateGenerator(FileSystemAbstraction fs, File fileName, long highId, bool throwIfFileExists)
 {
     IdContainer.CreateEmptyIdFile(fs, fileName, highId, throwIfFileExists);
 }