//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void dropShouldDeleteEntireIndexFolder()
        public virtual void DropShouldDeleteEntireIndexFolder()
        {
            // given
            File root = Storage.directory().directory("root");
            IndexDirectoryStructure directoryStructure = IndexDirectoryStructure.directoriesByProvider(root).forProvider(GenericNativeIndexProvider.Descriptor);
            long indexId                    = 8;
            File indexDirectory             = directoryStructure.DirectoryForIndex(indexId);
            StoreIndexDescriptor descriptor = IndexDescriptorFactory.forSchema(SchemaDescriptorFactory.forLabel(1, 1)).withId(indexId);
            IndexSpecificSpaceFillingCurveSettingsCache spatialSettings = mock(typeof(IndexSpecificSpaceFillingCurveSettingsCache));
            PageCache             pageCache        = Storage.pageCache();
            FileSystemAbstraction fs               = Storage.fileSystem();
            File          indexFile                = new File(indexDirectory, "my-index");
            GenericLayout layout                   = new GenericLayout(1, spatialSettings);
            RecoveryCleanupWorkCollector immediate = immediate();
            IndexDropAction             dropAction = new FileSystemIndexDropAction(fs, directoryStructure);
            GenericNativeIndexPopulator populator  = new GenericNativeIndexPopulator(pageCache, fs, indexFile, layout, EMPTY, descriptor, spatialSettings, directoryStructure, mock(typeof(SpaceFillingCurveConfiguration)), dropAction, false);

            populator.Create();

            // when
            assertTrue(fs.ListFiles(indexDirectory).Length > 0);
            populator.Drop();

            // then
            assertFalse(fs.FileExists(indexDirectory));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new id file.
 /// </summary>
 /// <param name="file"> The name of the id generator </param>
 /// <param name="throwIfFileExists"> if {@code true} will cause an <seealso cref="System.InvalidOperationException"/> to be thrown if
 /// the file already exists. if {@code false} will truncate the file writing the header in it. </param>
 public static void CreateEmptyIdFile(FileSystemAbstraction fs, File file, long highId, bool throwIfFileExists)
 {
     // sanity checks
     if (fs == null)
     {
         throw new System.ArgumentException("Null filesystem");
     }
     if (file == null)
     {
         throw new System.ArgumentException("Null filename");
     }
     if (throwIfFileExists && fs.FileExists(file))
     {
         throw new System.InvalidOperationException("Can't create id file [" + file + "], file already exists");
     }
     try
     {
         using (StoreChannel channel = fs.Create(file))
         {
             // write the header
             channel.Truncate(0);
             ByteBuffer buffer = ByteBuffer.allocate(HeaderSize);
             buffer.put(_cleanGenerator).putLong(highId).flip();
             channel.WriteAll(buffer);
             channel.Force(false);
         }
     }
     catch (IOException e)
     {
         throw new UnderlyingStorageException("Unable to create id file " + file, e);
     }
 }
Ejemplo n.º 3
0
        public void SetMigrationStatus(Org.Neo4j.Io.fs.FileSystemAbstraction fs, java.io.File stateFile, string info)
        {
            if (fs.FileExists(stateFile))
            {
                try
                {
                    fs.Truncate(stateFile, 0);
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }

            try
            {
                using (Writer writer = fs.OpenAsWriter(stateFile, StandardCharsets.UTF_8, false))
                {
                    writer.write(name());
                    writer.write('\n');
                    writer.write(info);
                    writer.flush();
                }
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
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 shouldSuppressFailureToCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSuppressFailureToCloseChannelInFailedAttemptToReadHeaderAfterOpen()
        {
            // GIVEN a file which returns 1/2 log header size worth of bytes
            FileSystemAbstraction fs = mock(typeof(FileSystemAbstraction));
            LogFiles     logFiles    = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build();
            int          logVersion  = 0;
            File         logFile     = logFiles.GetLogFileForVersion(logVersion);
            StoreChannel channel     = mock(typeof(StoreChannel));

            when(channel.read(any(typeof(ByteBuffer)))).thenReturn(LogHeader.LOG_HEADER_SIZE / 2);
            when(fs.FileExists(logFile)).thenReturn(true);
            when(fs.Open(eq(logFile), any(typeof(OpenMode)))).thenReturn(channel);
            doThrow(typeof(IOException)).when(channel).close();

            // WHEN
            try
            {
                logFiles.OpenForVersion(logVersion);
                fail("Should have failed");
            }
            catch (IncompleteLogHeaderException e)
            {
                // THEN good
                verify(channel).close();
                assertEquals(1, e.Suppressed.length);
                assertTrue(e.Suppressed[0] is IOException);
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void shouldThrowWhenTryingToCreateFileThatAlreadyExists()
        public virtual void ShouldThrowWhenTryingToCreateFileThatAlreadyExists()
        {
            // Given
            FileSystemAbstraction fs = mock(typeof(FileSystemAbstraction));

            when(fs.FileExists(_file)).thenReturn(false).thenReturn(true);
            when(fs.GetFileSize(_file)).thenReturn(42L);

            // When
            new IndexProviderStore(_file, fs, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            // exception is thrown
        }
 public override bool FileExists(File file)
 {
     return(@delegate.FileExists(file));
 }