예제 #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);
        }
예제 #2
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);
        }
예제 #3
0
 private void CreateEmptyFile()
 {
     IdContainer.CreateEmptyIdFile(_fs, _file, 42, false);
 }
예제 #4
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);
 }